From 47f668229232ce132e64aa2beec7fa1ca8a63803 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 15 Jun 2020 17:04:05 +0200 Subject: [PATCH 1/5] Added test case for base theme SVN functionality Unit tests for #1612, #1613. --- test/fixtures/svn/broken/svn | 3 ++ test/fixtures/svn/working/svn | 3 ++ test/themes/base.theme.svn.bats | 81 +++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100755 test/fixtures/svn/broken/svn create mode 100755 test/fixtures/svn/working/svn create mode 100644 test/themes/base.theme.svn.bats diff --git a/test/fixtures/svn/broken/svn b/test/fixtures/svn/broken/svn new file mode 100755 index 00000000..3c310539 --- /dev/null +++ b/test/fixtures/svn/broken/svn @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +exit 72 diff --git a/test/fixtures/svn/working/svn b/test/fixtures/svn/working/svn new file mode 100755 index 00000000..0fdcf091 --- /dev/null +++ b/test/fixtures/svn/working/svn @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +exit 0 diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats new file mode 100644 index 00000000..ce199ac1 --- /dev/null +++ b/test/themes/base.theme.svn.bats @@ -0,0 +1,81 @@ +#!/usr/bin/env bats + +load ../test_helper +load ../../lib/composure + +cite _about _param _example _group _author _version + +load ../../lib/helpers +load ../../themes/base.theme + +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 +} + +setup_repo() { + upstream="$(mktemp -d)" + pushd "$upstream" > /dev/null + # Create a dummy SVN folder - this will not work with an actual `svn` command, + # but will be enough to trigger the SVN check in the base theme. + mkdir .svn + + echo "$upstream" +} + +setup_svn_path() { + local svn_path="$1" + + # Make sure that the requested SVN script is available + assert_file_exist "$svn_path/svn" + + export OLD_PATH="$PATH" + # Make sure that the requested SVN script is on the path + export PATH="$svn_path:/usr/bin:/bin:/usr/sbin" +} + +reset_svn_path() { + export PATH="$OLD_PATH" + unset OLD_PATH +} + +@test 'themes base: SVN: detect SVN repo' { + repo="$(setup_repo)" + pushd "$repo" + + setup_svn_path "$BASH_IT/test/fixtures/svn/working" + + # Load the base theme again so that the working SVN script is detected + load ../../themes/base.theme + + scm + # Make sure that the SVN command is used + assert_equal "$SCM" "$SCM_SVN" + + reset_svn_path +} + +@test 'themes base: SVN: ignore SVN repo when using broken SVN command' { + repo="$(setup_repo)" + pushd "$repo" + + setup_svn_path "$BASH_IT/test/fixtures/svn/broken" + + # Load the base theme again so that the broken SVN script is detected + load ../../themes/base.theme + + scm + # Make sure that the SVN command is not used + assert_equal "$SCM" "$SCM_NONE" + + reset_svn_path +} From f933a86ff0bf4893b63ac6c5d6cb1b45aa8dbb0c Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 16 Jun 2020 09:24:24 +0200 Subject: [PATCH 2/5] Added tests for additional SVN scenarios --- test/fixtures/svn/working/svn | 7 +++++ test/themes/base.theme.svn.bats | 56 +++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/test/fixtures/svn/working/svn b/test/fixtures/svn/working/svn index 0fdcf091..5d72d7cd 100755 --- a/test/fixtures/svn/working/svn +++ b/test/fixtures/svn/working/svn @@ -1,3 +1,10 @@ #!/usr/bin/env bash +# If the info command is called +# AND the parent folder contains the .svn folder +# THEN return the current path, similar to what `svn info` does +if [[ "$1" = "info" ]] && [[ -d "../.svn" ]]; then + echo "$PWD" +fi + exit 0 diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index ce199ac1..c358e404 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -64,6 +64,43 @@ reset_svn_path() { reset_svn_path } +@test 'themes base: SVN: detect SVN repo even from a subfolder' { + repo="$(setup_repo)" + pushd "$repo" + + mkdir foo + pushd foo + + setup_svn_path "$BASH_IT/test/fixtures/svn/working" + + # Load the base theme again so that the working SVN script is detected + load ../../themes/base.theme + + scm + # Make sure that the SVN command is used + assert_equal "$SCM" "$SCM_SVN" + + reset_svn_path +} + +@test 'themes base: SVN: no SCM if no .svn folder can be found' { + repo="$(setup_repo)" + pushd "$repo" + + rm -rf .svn + + setup_svn_path "$BASH_IT/test/fixtures/svn/working" + + # Load the base theme again so that the working SVN script is detected + load ../../themes/base.theme + + scm + # Make sure that the SVN command is used + assert_equal "$SCM" "$SCM_NONE" + + reset_svn_path +} + @test 'themes base: SVN: ignore SVN repo when using broken SVN command' { repo="$(setup_repo)" pushd "$repo" @@ -79,3 +116,22 @@ reset_svn_path() { reset_svn_path } + +@test 'themes base: SVN: ignore SVN repo even from a subfolder when using a broken SVN' { + repo="$(setup_repo)" + pushd "$repo" + + mkdir foo + pushd foo + + setup_svn_path "$BASH_IT/test/fixtures/svn/broken" + + # Load the base theme again so that the working SVN script is detected + load ../../themes/base.theme + + scm + # Make sure that the SVN command is used + assert_equal "$SCM" "$SCM_NONE" + + reset_svn_path +} From 5aa525caae7610721b5da7daadf633e0df1bec5b Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 16 Jun 2020 09:25:07 +0200 Subject: [PATCH 3/5] Refactored setup/teardown --- test/themes/base.theme.svn.bats | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index c358e404..0a525c4a 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -20,9 +20,16 @@ function local_setup { -mindepth 1 -maxdepth 1 \ -exec cp -r {} "$BASH_IT/" \; fi + + export OLD_PATH="$PATH" } -setup_repo() { +function local_teardown { + export PATH="$OLD_PATH" + unset OLD_PATH +} + +function setup_repo { upstream="$(mktemp -d)" pushd "$upstream" > /dev/null # Create a dummy SVN folder - this will not work with an actual `svn` command, @@ -32,22 +39,16 @@ setup_repo() { echo "$upstream" } -setup_svn_path() { +function setup_svn_path { local svn_path="$1" # Make sure that the requested SVN script is available assert_file_exist "$svn_path/svn" - export OLD_PATH="$PATH" # Make sure that the requested SVN script is on the path export PATH="$svn_path:/usr/bin:/bin:/usr/sbin" } -reset_svn_path() { - export PATH="$OLD_PATH" - unset OLD_PATH -} - @test 'themes base: SVN: detect SVN repo' { repo="$(setup_repo)" pushd "$repo" @@ -60,8 +61,6 @@ reset_svn_path() { scm # Make sure that the SVN command is used assert_equal "$SCM" "$SCM_SVN" - - reset_svn_path } @test 'themes base: SVN: detect SVN repo even from a subfolder' { @@ -79,8 +78,6 @@ reset_svn_path() { scm # Make sure that the SVN command is used assert_equal "$SCM" "$SCM_SVN" - - reset_svn_path } @test 'themes base: SVN: no SCM if no .svn folder can be found' { @@ -97,8 +94,6 @@ reset_svn_path() { scm # Make sure that the SVN command is used assert_equal "$SCM" "$SCM_NONE" - - reset_svn_path } @test 'themes base: SVN: ignore SVN repo when using broken SVN command' { @@ -113,8 +108,6 @@ reset_svn_path() { scm # Make sure that the SVN command is not used assert_equal "$SCM" "$SCM_NONE" - - reset_svn_path } @test 'themes base: SVN: ignore SVN repo even from a subfolder when using a broken SVN' { @@ -132,6 +125,4 @@ reset_svn_path() { scm # Make sure that the SVN command is used assert_equal "$SCM" "$SCM_NONE" - - reset_svn_path } From c02638e94653d4ba7b1b3020d18b5730f2a4f382 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 16 Jun 2020 16:57:37 +0200 Subject: [PATCH 4/5] Fixed comment --- test/fixtures/svn/broken/svn | 1 + test/themes/base.theme.svn.bats | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/fixtures/svn/broken/svn b/test/fixtures/svn/broken/svn index 3c310539..c9f5235b 100755 --- a/test/fixtures/svn/broken/svn +++ b/test/fixtures/svn/broken/svn @@ -1,3 +1,4 @@ #!/usr/bin/env bash +# Simply return an error code to simulate a broken SVN installation exit 72 diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index 0a525c4a..0b578071 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -119,7 +119,7 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Load the base theme again so that the working SVN script is detected + # Load the base theme again so that the broken SVN script is detected load ../../themes/base.theme scm From 3cffa3509252ae8bd7bc074b58cb9d3f732fec41 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 16 Jun 2020 16:59:29 +0200 Subject: [PATCH 5/5] Fixed some more comments --- test/themes/base.theme.svn.bats | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index 0b578071..89279d1b 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -92,7 +92,7 @@ function setup_svn_path { load ../../themes/base.theme scm - # Make sure that the SVN command is used + # Make sure that no SVN command is used assert_equal "$SCM" "$SCM_NONE" } @@ -106,7 +106,7 @@ function setup_svn_path { load ../../themes/base.theme scm - # Make sure that the SVN command is not used + # Make sure that no SVN command is not used assert_equal "$SCM" "$SCM_NONE" } @@ -123,6 +123,6 @@ function setup_svn_path { load ../../themes/base.theme scm - # Make sure that the SVN command is used + # Make sure that no SVN command is used assert_equal "$SCM" "$SCM_NONE" }