|
| 1 | +{ |
| 2 | + pkgs, |
| 3 | + self, |
| 4 | + tlib, |
| 5 | + writeText, |
| 6 | + ... |
| 7 | +}: |
| 8 | + |
| 9 | +let |
| 10 | + inherit (tlib) |
| 11 | + fileContains |
| 12 | + isFile |
| 13 | + isDirectory |
| 14 | + notIsFile |
| 15 | + notIsDirectory |
| 16 | + test |
| 17 | + ; |
| 18 | + wm = self.wrappers.oh-my-posh; |
| 19 | +in |
| 20 | +test { wrapper = "oh-my-posh"; } { |
| 21 | + |
| 22 | + "wrapper should output correct version" = |
| 23 | + let |
| 24 | + wrapper = wm.wrap { |
| 25 | + inherit pkgs; |
| 26 | + }; |
| 27 | + in |
| 28 | + '' |
| 29 | + "${wrapper}/bin/oh-my-posh" --version | |
| 30 | + grep -q "${wrapper.version}" |
| 31 | + ''; |
| 32 | + |
| 33 | + "If config is provided then config.json is properly set up" = |
| 34 | + let |
| 35 | + wrapper = wm.wrap { |
| 36 | + inherit pkgs; |
| 37 | + theme = "jandedobbeleer"; |
| 38 | + }; |
| 39 | + configFile = "${wrapper}/config.json"; |
| 40 | + in |
| 41 | + [ |
| 42 | + (isFile configFile) |
| 43 | + (fileContains "${wrapper}/bin/oh-my-posh" "--config.*${configFile}") |
| 44 | + ]; |
| 45 | + |
| 46 | + "If no config is provided then no config.json is set up" = |
| 47 | + let |
| 48 | + wrapper = wm.wrap { |
| 49 | + inherit pkgs; |
| 50 | + }; |
| 51 | + configFile = "${wrapper}/config.json"; |
| 52 | + in |
| 53 | + notIsFile configFile; |
| 54 | + |
| 55 | + "config chains" = |
| 56 | + let |
| 57 | + baseWrapper = wm.wrap { |
| 58 | + inherit pkgs; |
| 59 | + theme = [ |
| 60 | + "aliens" |
| 61 | + "agnoster" |
| 62 | + ]; |
| 63 | + settings.foo = "foo"; |
| 64 | + configFile = writeText "file-config.yaml" "bar: bar"; |
| 65 | + }; |
| 66 | + nixStoreFile = name: "/nix/store/[[:alnum:]]{32}-.*${name}"; |
| 67 | + extendsPattern = path: ''"extends": "${path}"''; |
| 68 | + in |
| 69 | + { |
| 70 | + "theme > file > settings (default order)" = |
| 71 | + let |
| 72 | + wrapper = baseWrapper; |
| 73 | + configChainDir = "${wrapper}/config-chain"; |
| 74 | + |
| 75 | + nixSettingsFile = "${configChainDir}/settings.json"; |
| 76 | + fileSettingsFile = "${configChainDir}/file-config.json"; |
| 77 | + agnosterFile = "${configChainDir}/agnoster.omp.json"; |
| 78 | + in |
| 79 | + [ |
| 80 | + "[[ -h ${wrapper}/config.json ]]" |
| 81 | + "[[ $(readlink -f ${wrapper}/config.json) == ${nixSettingsFile} ]]" |
| 82 | + (fileContains nixSettingsFile (extendsPattern fileSettingsFile)) |
| 83 | + (fileContains fileSettingsFile (extendsPattern agnosterFile)) |
| 84 | + (fileContains agnosterFile (extendsPattern (nixStoreFile "aliens.omp.json"))) |
| 85 | + ]; |
| 86 | + |
| 87 | + "file > theme > settings" = |
| 88 | + let |
| 89 | + wrapper = baseWrapper.wrap { |
| 90 | + order = [ |
| 91 | + "file" |
| 92 | + "theme" |
| 93 | + "settings" |
| 94 | + ]; |
| 95 | + }; |
| 96 | + configChainDir = "${wrapper}/config-chain"; |
| 97 | + |
| 98 | + nixSettingsFile = "${configChainDir}/settings.json"; |
| 99 | + agnosterFile = "${configChainDir}/agnoster.omp.json"; |
| 100 | + aliensFile = "${configChainDir}/aliens.omp.json"; |
| 101 | + in |
| 102 | + [ |
| 103 | + "[[ -h ${wrapper}/config.json ]]" |
| 104 | + "[[ $(readlink -f ${wrapper}/config.json) == ${nixSettingsFile} ]]" |
| 105 | + (fileContains nixSettingsFile (extendsPattern agnosterFile)) |
| 106 | + (fileContains agnosterFile (extendsPattern aliensFile)) |
| 107 | + (fileContains aliensFile (extendsPattern (nixStoreFile "file-config.json"))) |
| 108 | + ]; |
| 109 | + |
| 110 | + "file > settings > theme" = |
| 111 | + let |
| 112 | + wrapper = baseWrapper.wrap { |
| 113 | + order = [ |
| 114 | + "file" |
| 115 | + "settings" |
| 116 | + "theme" |
| 117 | + ]; |
| 118 | + }; |
| 119 | + configChainDir = "${wrapper}/config-chain"; |
| 120 | + |
| 121 | + agnosterFile = "${configChainDir}/agnoster.omp.json"; |
| 122 | + aliensFile = "${configChainDir}/aliens.omp.json"; |
| 123 | + nixSettingsFile = "${configChainDir}/settings.json"; |
| 124 | + in |
| 125 | + [ |
| 126 | + "[[ -h ${wrapper}/config.json ]]" |
| 127 | + "[[ $(readlink -f ${wrapper}/config.json) == ${agnosterFile} ]]" |
| 128 | + (fileContains agnosterFile (extendsPattern aliensFile)) |
| 129 | + (fileContains aliensFile (extendsPattern nixSettingsFile)) |
| 130 | + (fileContains nixSettingsFile (extendsPattern (nixStoreFile "file-config.json"))) |
| 131 | + ]; |
| 132 | + |
| 133 | + "settings > theme > file" = |
| 134 | + let |
| 135 | + wrapper = baseWrapper.wrap { |
| 136 | + order = [ |
| 137 | + "settings" |
| 138 | + "theme" |
| 139 | + "file" |
| 140 | + ]; |
| 141 | + }; |
| 142 | + configChainDir = "${wrapper}/config-chain"; |
| 143 | + |
| 144 | + fileSettingsFile = "${configChainDir}/file-config.json"; |
| 145 | + agnosterFile = "${configChainDir}/agnoster.omp.json"; |
| 146 | + aliensFile = "${configChainDir}/aliens.omp.json"; |
| 147 | + in |
| 148 | + [ |
| 149 | + "[[ -h ${wrapper}/config.json ]]" |
| 150 | + "[[ $(readlink -f ${wrapper}/config.json) == ${fileSettingsFile} ]]" |
| 151 | + (fileContains fileSettingsFile (extendsPattern agnosterFile)) |
| 152 | + (fileContains agnosterFile (extendsPattern aliensFile)) |
| 153 | + (fileContains aliensFile (extendsPattern (nixStoreFile "settings.json"))) |
| 154 | + ]; |
| 155 | + |
| 156 | + "theme > settings > file" = |
| 157 | + let |
| 158 | + wrapper = baseWrapper.wrap { |
| 159 | + order = [ |
| 160 | + "theme" |
| 161 | + "settings" |
| 162 | + "file" |
| 163 | + ]; |
| 164 | + }; |
| 165 | + configChainDir = "${wrapper}/config-chain"; |
| 166 | + |
| 167 | + fileSettingsFile = "${configChainDir}/file-config.json"; |
| 168 | + nixSettingsFile = "${configChainDir}/settings.json"; |
| 169 | + agnosterFile = "${configChainDir}/agnoster.omp.json"; |
| 170 | + in |
| 171 | + [ |
| 172 | + "[[ -h ${wrapper}/config.json ]]" |
| 173 | + "[[ $(readlink -f ${wrapper}/config.json) == ${fileSettingsFile} ]]" |
| 174 | + (fileContains fileSettingsFile (extendsPattern nixSettingsFile)) |
| 175 | + (fileContains nixSettingsFile (extendsPattern agnosterFile)) |
| 176 | + (fileContains agnosterFile (extendsPattern (nixStoreFile "aliens.omp.json"))) |
| 177 | + ]; |
| 178 | + |
| 179 | + "settings > file > theme" = |
| 180 | + let |
| 181 | + wrapper = baseWrapper.wrap { |
| 182 | + order = [ |
| 183 | + "settings" |
| 184 | + "file" |
| 185 | + "theme" |
| 186 | + ]; |
| 187 | + }; |
| 188 | + configChainDir = "${wrapper}/config-chain"; |
| 189 | + |
| 190 | + agnosterFile = "${configChainDir}/agnoster.omp.json"; |
| 191 | + aliensFile = "${configChainDir}/aliens.omp.json"; |
| 192 | + fileSettingsFile = "${configChainDir}/file-config.json"; |
| 193 | + in |
| 194 | + [ |
| 195 | + "[[ -h ${wrapper}/config.json ]]" |
| 196 | + "[[ $(readlink -f ${wrapper}/config.json) == ${agnosterFile} ]]" |
| 197 | + (fileContains agnosterFile (extendsPattern aliensFile)) |
| 198 | + (fileContains aliensFile (extendsPattern fileSettingsFile)) |
| 199 | + (fileContains fileSettingsFile (extendsPattern (nixStoreFile "settings.json"))) |
| 200 | + ]; |
| 201 | + }; |
| 202 | + |
| 203 | + "config file formats" = |
| 204 | + let |
| 205 | + key = "dummy_key"; |
| 206 | + value = "dummy_value"; |
| 207 | + in |
| 208 | + { |
| 209 | + "json configFile is loaded" = |
| 210 | + let |
| 211 | + wrapper = wm.wrap { |
| 212 | + inherit pkgs; |
| 213 | + configFile = writeText "config.json" ''{"${key}": "${value}"}''; |
| 214 | + }; |
| 215 | + generatedConfig = "${wrapper}/config.json"; |
| 216 | + in |
| 217 | + [ |
| 218 | + (isFile generatedConfig) |
| 219 | + (fileContains generatedConfig key) |
| 220 | + (fileContains generatedConfig value) |
| 221 | + ]; |
| 222 | + |
| 223 | + "yaml configFile is loaded" = |
| 224 | + let |
| 225 | + wrapper = wm.wrap { |
| 226 | + inherit pkgs; |
| 227 | + configFile = writeText "config.yaml" "${key}: ${value}"; |
| 228 | + }; |
| 229 | + generatedConfig = "${wrapper}/config.json"; |
| 230 | + in |
| 231 | + [ |
| 232 | + (isFile generatedConfig) |
| 233 | + (fileContains generatedConfig key) |
| 234 | + (fileContains generatedConfig value) |
| 235 | + ]; |
| 236 | + |
| 237 | + "toml configFile is loaded" = |
| 238 | + let |
| 239 | + wrapper = wm.wrap { |
| 240 | + inherit pkgs; |
| 241 | + configFile = writeText "config.toml" ''${key} = "${value}"''; |
| 242 | + }; |
| 243 | + generatedConfig = "${wrapper}/config.json"; |
| 244 | + in |
| 245 | + [ |
| 246 | + (isFile generatedConfig) |
| 247 | + (fileContains generatedConfig key) |
| 248 | + (fileContains generatedConfig value) |
| 249 | + ]; |
| 250 | + }; |
| 251 | + |
| 252 | + "explicit `extends` in settings breaks the config chain" = |
| 253 | + let |
| 254 | + wrapper = wm.wrap { |
| 255 | + inherit pkgs; |
| 256 | + theme = [ |
| 257 | + "aliens" |
| 258 | + "agnoster" |
| 259 | + ]; |
| 260 | + settings.extends = "foo"; |
| 261 | + }; |
| 262 | + configChainDir = "${wrapper}/config-chain"; |
| 263 | + in |
| 264 | + [ |
| 265 | + (isFile "${configChainDir}/settings.json") |
| 266 | + (notIsFile "${configChainDir}/agnoster.omp.json") |
| 267 | + (notIsFile "${configChainDir}/aliens.omp.json") |
| 268 | + ]; |
| 269 | + |
| 270 | + "If a single config is provided then no config-chain dir is created" = |
| 271 | + let |
| 272 | + wrapper = wm.wrap { |
| 273 | + inherit pkgs; |
| 274 | + settings.extends = "foo"; |
| 275 | + }; |
| 276 | + in |
| 277 | + [ |
| 278 | + (isFile "${wrapper}/config.json") |
| 279 | + (notIsDirectory "${wrapper}/config-chain") |
| 280 | + ]; |
| 281 | + |
| 282 | + "extending segments works as expected" = |
| 283 | + let |
| 284 | + wrapper = wm.wrap { |
| 285 | + inherit pkgs; |
| 286 | + configFile = writeText "config.yaml" '' |
| 287 | + blocks: |
| 288 | + - type: prompt |
| 289 | + alignment: left |
| 290 | + segments: |
| 291 | + - type: text |
| 292 | + style: plain |
| 293 | + template: "[b1s1]" |
| 294 | + - type: text |
| 295 | + style: plain |
| 296 | + template: "[b1s2]" |
| 297 | + - type: prompt |
| 298 | + alignment: right |
| 299 | + segments: |
| 300 | + - type: text |
| 301 | + style: plain |
| 302 | + template: "[b2s1]" |
| 303 | + - type: text |
| 304 | + style: plain |
| 305 | + template: "[b2s2]" |
| 306 | + alias: foo |
| 307 | + ''; |
| 308 | + settings.blocks = [ |
| 309 | + { |
| 310 | + type = "prompt"; |
| 311 | + alignment = "right"; |
| 312 | + segments = [ |
| 313 | + { |
| 314 | + type = "text"; |
| 315 | + style = "plain"; |
| 316 | + alias = "foo"; |
| 317 | + template = "foo"; |
| 318 | + } |
| 319 | + ]; |
| 320 | + } |
| 321 | + ]; |
| 322 | + }; |
| 323 | + in |
| 324 | + # '[b2s2]' should be overridden with 'foo' |
| 325 | + [ |
| 326 | + "${wrapper}/bin/oh-my-posh print primary | grep -Fq '[b1s1]'" |
| 327 | + "${wrapper}/bin/oh-my-posh print primary | grep -Fq '[b1s2]'" |
| 328 | + "${wrapper}/bin/oh-my-posh print primary | grep -Fq '[b2s1]'" |
| 329 | + "${wrapper}/bin/oh-my-posh print primary | grep -Fqv '[b2s2]'" |
| 330 | + "${wrapper}/bin/oh-my-posh print primary | grep -Fq 'foo'" |
| 331 | + ]; |
| 332 | +} |
0 commit comments