From 7b7892de863545a90e2110eadcff3843d7941211 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sun, 18 Apr 2021 23:00:56 +0300 Subject: [PATCH] test: helpers: Add profile command tests --- .../profiles/test-bad-component.bash_it | 12 ++ .../bash_it/profiles/test-bad-type.bash_it | 12 ++ test/lib/helpers.bats | 108 ++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 test/fixtures/bash_it/profiles/test-bad-component.bash_it create mode 100644 test/fixtures/bash_it/profiles/test-bad-type.bash_it diff --git a/test/fixtures/bash_it/profiles/test-bad-component.bash_it b/test/fixtures/bash_it/profiles/test-bad-component.bash_it new file mode 100644 index 0000000000..8640265cf2 --- /dev/null +++ b/test/fixtures/bash_it/profiles/test-bad-component.bash_it @@ -0,0 +1,12 @@ +# plugins +plugins alias-completion +plugins base + +# completion +completion bash-it +completion system + +# aliases +aliases general +# Bad component +aliases bla diff --git a/test/fixtures/bash_it/profiles/test-bad-type.bash_it b/test/fixtures/bash_it/profiles/test-bad-type.bash_it new file mode 100644 index 0000000000..ed2d23732f --- /dev/null +++ b/test/fixtures/bash_it/profiles/test-bad-type.bash_it @@ -0,0 +1,12 @@ +# plugins +plugins alias-completion +plugins base +# Bad type +pluugins alias-completion + +# completion +completion bash-it +completion system + +# aliases +aliases general diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index e60d5542ab..8b6139eff0 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -13,11 +13,24 @@ load ../../lib/helpers function local_setup { setup_test_fixture + + # Copy the test fixture to the Bash-it folder + if command -v rsync &> /dev/null; then + rsync -a "$BASH_IT/test/fixtures/bash_it/" "$BASH_IT/" + else + find "$BASH_IT/test/fixtures/bash_it" \ + -mindepth 1 -maxdepth 1 \ + -exec cp -r {} "$BASH_IT/" \; + fi } # TODO Create global __is_enabled function # TODO Create global __get_base_name function # TODO Create global __get_enabled_name function +@test "bash-it: verify that the test fixture is available" { + assert_file_exist "$BASH_IT/profiles/test-bad-component.bash_it" + assert_file_exist "$BASH_IT/profiles/test-bad-type.bash_it" +} @test "helpers: _command_exists function exists" { run type -a _command_exists &> /dev/null @@ -283,6 +296,101 @@ function local_setup { assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" } +@test "helper: profile load command sanity" { + run _bash-it-profile-load "default" + + assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" + assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash" + assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash" + assert_link_exist "$BASH_IT/enabled/350---system.completion.bash" +} + +@test "helper: profile save command sanity" { + run _enable-plugin "nvm" + + run _bash-it-profile-save "test" + assert_line -n 0 "Saving plugins configuration..." + assert_line -n 1 "Saving completion configuration..." + assert_line -n 2 "Saving aliases configuration..." + assert_line -n 3 "All done!" +} + +@test "helper: profile save creates valid file with only plugin enabled" { + run _enable-plugin "nvm" + + run _bash-it-profile-save "test" + run cat "$BASH_IT/profiles/test.bash_it" + assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" + assert_line -n 1 "# plugins" + assert_line -n 2 "plugins nvm" +} + +@test "helper: profile save creates valid file with only completion enabled" { + run _enable-completion "bash-it" + + run _bash-it-profile-save "test" + run cat "$BASH_IT/profiles/test.bash_it" + assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" + assert_line -n 1 "# completion" + assert_line -n 2 "completion bash-it" +} + +@test "helper: profile save creates valid file with only aliases enabled" { + run _enable-alias "general" + + run _bash-it-profile-save "test" + run cat "$BASH_IT/profiles/test.bash_it" + assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" + assert_line -n 1 "# aliases" + assert_line -n 2 "aliases general" +} + +@test "helper: profile edge case, empty configuration" { + run _bash-it-profile-save "test" + assert_line -n 3 "It seems like no configuration was enabled.." + assert_line -n 4 "Make sure to double check that this is the wanted behavior." + + run _enable-alias "general" + run _enable-plugin "base" + run _enable-plugin "alias-completion" + run _enable-completion "bash-it" + run _enable-completion "system" + + run _bash-it-profile-load "test" + assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash" + assert_link_not_exist "$BASH_IT/enabled/250---base.plugin.bash" + assert_link_not_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash" + assert_link_not_exist "$BASH_IT/enabled/350---bash-it.completion.bash" + assert_link_not_exist "$BASH_IT/enabled/350---system.completion.bash" +} + +@test "helper: profile save and load" { + run _enable-alias "general" + run _enable-plugin "base" + run _enable-plugin "alias-completion" + run _enable-completion "bash-it" + run _enable-completion "system" + + run _bash-it-profile-save "test" + assert_success + + run _disable-alias "general" + assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash" + run _bash-it-profile-load "test" + assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" +} + +@test "helper: profile load corrupted profile file: bad component" { + run _bash-it-profile-load "test-bad-component" + assert_line -n 1 -p "Bad line(#12) in profile, aborting load..." +} + +@test "helper: profile load corrupted profile file: bad subdirectory" { + run _bash-it-profile-load "test-bad-type" + assert_line -n 1 -p "Bad line(#5) in profile, aborting load..." +} + @test "helpers: migrate plugins and completions that share the same name" { ln -s $BASH_IT/completion/available/dirs.completion.bash $BASH_IT/completion/enabled/350---dirs.completion.bash assert_link_exist "$BASH_IT/completion/enabled/350---dirs.completion.bash"