Skip to content

Commit 6ca32ba

Browse files
committed
feat(wrapperModules.oh-my-posh): init
add check.nix implement omp + checks fix fileContains add configFile option clean up tests simplify use optionalString use omp-native "extends" feature to merge configs add config-chain folder preserve original names in config chain add foo.omp.json handle reverse traversal of ordered settings remove config-chain dir if empty ensure that settings get copied to config-chain properly copy settings.json remove nix store hash from config file update tests cleanup test refactor simplify tmp file rename _omp_out --> dst simplify copy case rework json normalization fix tests wip cleanup nix recursion rewrite recurse from the end of the list simplify chainFiles cleanup unreachable configs improve docs linting improve docs cleanup improve errMsgs in testlib add config.json test add test for breaking config-chain add test for extending segments remove dummie configs
1 parent 87fa3a7 commit 6ca32ba

3 files changed

Lines changed: 649 additions & 4 deletions

File tree

ci/test-lib.nix

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
let
1111
wlib = self.lib;
1212

13-
errMsg = msg: "(echo ${renderMsg msg} >&2 && return 1)";
13+
errMsg = msg: "(echo \"${renderMsg msg}\" >&2 && return 1)";
1414

1515
indentBlock =
1616
str: num:
@@ -280,10 +280,27 @@ in
280280
msg = "File ${path} should not exist";
281281
};
282282

283+
/**
284+
Returns an `Assertion` that checks whether `path` does **not** exist as a directory.
285+
286+
# Type
287+
```
288+
notIsFile :: String -> Assertion
289+
```
290+
291+
# Arguments
292+
path
293+
: The filesystem path that should be absent.
294+
*/
295+
notIsDirectory = path: {
296+
cond = ''[ ! -d "${path}" ]'';
297+
msg = "Directory ${path} should not exist";
298+
};
299+
283300
/**
284301
Returns an `Assertion` that checks whether `file` contains a line matching `pattern`.
285302
286-
The check is performed with `grep -q`, so `pattern` is treated as a basic regular expression.
303+
The check is performed with `grep -Eq`, so `pattern` is treated as an extended regular expression.
287304
288305
# Type
289306
```
@@ -295,10 +312,10 @@ in
295312
: Path to the file to search.
296313
297314
pattern
298-
: Basic regular expression to search for.
315+
: Extended regular expression to search for.
299316
*/
300317
fileContains = file: pattern: {
301-
cond = ''grep -q '${pattern}' "${file}"'';
318+
cond = ''grep -Eq -- '${pattern}' "${file}"'';
302319
msg = "Pattern '${pattern}' not found in ${file}";
303320
};
304321

Lines changed: 332 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
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

Comments
 (0)