Skip to content

Commit cb9bb17

Browse files
author
Noah Gorny
committed
test: helpers: Add profile command tests
1 parent 898e897 commit cb9bb17

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# plugins
2+
plugins alias-completion
3+
plugins base
4+
5+
# completion
6+
completion bash-it
7+
completion system
8+
9+
# aliases
10+
aliases general
11+
# Bad component
12+
aliases bla
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# plugins
2+
plugins alias-completion
3+
plugins base
4+
# Bad type
5+
pluugins alias-completion
6+
7+
# completion
8+
completion bash-it
9+
completion system
10+
11+
# aliases
12+
aliases general
13+

test/lib/helpers.bats

+108
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,24 @@ load ../../lib/helpers
1313

1414
function local_setup {
1515
setup_test_fixture
16+
17+
# Copy the test fixture to the Bash-it folder
18+
if command -v rsync &> /dev/null; then
19+
rsync -a "$BASH_IT/test/fixtures/bash_it/" "$BASH_IT/"
20+
else
21+
find "$BASH_IT/test/fixtures/bash_it" \
22+
-mindepth 1 -maxdepth 1 \
23+
-exec cp -r {} "$BASH_IT/" \;
24+
fi
1625
}
1726

1827
# TODO Create global __is_enabled function
1928
# TODO Create global __get_base_name function
2029
# TODO Create global __get_enabled_name function
30+
@test "bash-it: verify that the test fixture is available" {
31+
assert_file_exist "$BASH_IT/profiles/test-bad-component.bash_it"
32+
assert_file_exist "$BASH_IT/profiles/test-bad-type.bash_it"
33+
}
2134

2235
@test "helpers: _command_exists function exists" {
2336
run type -a _command_exists &> /dev/null
@@ -283,6 +296,101 @@ function local_setup {
283296
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
284297
}
285298

299+
@test "helper: profile load command sanity" {
300+
run _bash-it-profile-load "default"
301+
302+
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
303+
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
304+
assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash"
305+
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
306+
assert_link_exist "$BASH_IT/enabled/350---system.completion.bash"
307+
}
308+
309+
@test "helper: profile save command sanity" {
310+
run _enable-plugin "nvm"
311+
312+
run _bash-it-profile-save "test"
313+
assert_line -n 0 "Saving plugins configuration..."
314+
assert_line -n 1 "Saving completion configuration..."
315+
assert_line -n 2 "Saving aliases configuration..."
316+
assert_line -n 3 "All done!"
317+
}
318+
319+
@test "helper: profile save creates valid file with only plugin enabled" {
320+
run _enable-plugin "nvm"
321+
322+
run _bash-it-profile-save "test"
323+
run cat "$BASH_IT/profiles/test.bash_it"
324+
assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!"
325+
assert_line -n 1 "# plugins"
326+
assert_line -n 2 "plugins nvm"
327+
}
328+
329+
@test "helper: profile save creates valid file with only completion enabled" {
330+
run _enable-completion "bash-it"
331+
332+
run _bash-it-profile-save "test"
333+
run cat "$BASH_IT/profiles/test.bash_it"
334+
assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!"
335+
assert_line -n 1 "# completion"
336+
assert_line -n 2 "completion bash-it"
337+
}
338+
339+
@test "helper: profile save creates valid file with only aliases enabled" {
340+
run _enable-alias "general"
341+
342+
run _bash-it-profile-save "test"
343+
run cat "$BASH_IT/profiles/test.bash_it"
344+
assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!"
345+
assert_line -n 1 "# aliases"
346+
assert_line -n 2 "aliases general"
347+
}
348+
349+
@test "helper: profile edge case, empty configuration" {
350+
run _bash-it-profile-save "test"
351+
assert_line -n 3 "It seems like no configuration was enabled.."
352+
assert_line -n 4 "Make sure to double check that this is the wanted behavior."
353+
354+
run _enable-alias "general"
355+
run _enable-plugin "base"
356+
run _enable-plugin "alias-completion"
357+
run _enable-completion "bash-it"
358+
run _enable-completion "system"
359+
360+
run _bash-it-profile-load "test"
361+
assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash"
362+
assert_link_not_exist "$BASH_IT/enabled/250---base.plugin.bash"
363+
assert_link_not_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash"
364+
assert_link_not_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
365+
assert_link_not_exist "$BASH_IT/enabled/350---system.completion.bash"
366+
}
367+
368+
@test "helper: profile save and load" {
369+
run _enable-alias "general"
370+
run _enable-plugin "base"
371+
run _enable-plugin "alias-completion"
372+
run _enable-completion "bash-it"
373+
run _enable-completion "system"
374+
375+
run _bash-it-profile-save "test"
376+
assert_success
377+
378+
run _disable-alias "general"
379+
assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash"
380+
run _bash-it-profile-load "test"
381+
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
382+
}
383+
384+
@test "helper: profile load corrupted profile file: bad component" {
385+
run _bash-it-profile-load "test-bad-component"
386+
assert_line -n 1 -p "Bad line(#12) in profile, aborting load..."
387+
}
388+
389+
@test "helper: profile load corrupted profile file: bad subdirectory" {
390+
run _bash-it-profile-load "test-bad-type"
391+
assert_line -n 1 -p "Bad line(#5) in profile, aborting load..."
392+
}
393+
286394
@test "helpers: migrate plugins and completions that share the same name" {
287395
ln -s $BASH_IT/completion/available/dirs.completion.bash $BASH_IT/completion/enabled/350---dirs.completion.bash
288396
assert_link_exist "$BASH_IT/completion/enabled/350---dirs.completion.bash"

0 commit comments

Comments
 (0)