From a2290fb189bee1da5e985d785e044d1681401ff7 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Fri, 22 May 2020 17:55:41 -0700 Subject: [PATCH 1/1] Factor out test setup --- test.sh | 4 ++- tests/alias.sh | 23 ++++------------ tests/core.sh | 21 ++------------ tests/lib/test-setup.sh | 26 ++++++++++++++++++ tests/multi-update.sh | 28 +++++-------------- tests/pin-twice.sh | 21 ++------------ tests/reject-duplicates.sh | 55 ++++++++++++------------------------- tests/reject-nonancestor.sh | 21 ++------------ 8 files changed, 67 insertions(+), 132 deletions(-) create mode 100644 tests/lib/test-setup.sh diff --git a/test.sh b/test.sh index 9823458..9485418 100755 --- a/test.sh +++ b/test.sh @@ -7,7 +7,9 @@ PARALLELISM=4 find . -name '*.py' -print0 | xargs -0 mypy --strict --ignore-missing-imports for test in tests/*;do - "$test" + if [ ! -d "$test" ];then + "$test" + fi done find . -name '*_test.py' -print0 | xargs -0 -r -n1 python3 diff --git a/tests/alias.sh b/tests/alias.sh index c721340..5083999 100755 --- a/tests/alias.sh +++ b/tests/alias.sh @@ -1,23 +1,10 @@ #!/bin/sh -set -e - -repo_dir="`mktemp -d`" -repo="$repo_dir/repo" -git init "$repo" -( - cd "$repo" - echo Contents > test-file - git add test-file - git commit -m 'Commit message' -) - -conf="`mktemp`" -cat > "$conf" <> "$conf" <'\'' --install --from-expression '\''f: f \{ name = "(repo-[0-9]{10}-[0-9a-f]{11})"; channelName = "bar"; src = builtins.storePath "/nix/store/.{32}-\1.tar.xz"; \}'\'' '\''f: f \{ name = "\1"; channelName = "foo"; src = builtins.storePath "/nix/store/.{32}-\1.tar.xz"; \}'\''$' diff --git a/tests/core.sh b/tests/core.sh index 385ae2b..da0d991 100755 --- a/tests/core.sh +++ b/tests/core.sh @@ -1,29 +1,14 @@ #!/bin/sh -set -e +. ./tests/lib/test-setup.sh -repo_dir="`mktemp -d`" -repo="$repo_dir/repo" -git init "$repo" -( - cd "$repo" - echo Contents > test-file - git add test-file - git commit -m 'Commit message' -) - -conf="`mktemp`" -cat > "$conf" <'\'' --install --from-expression '\''f: f \{ name = "(repo-[0-9]{10}-[0-9a-f]{11})"; channelName = "foo"; src = builtins.storePath "/nix/store/.{32}-\1.tar.xz"; \}'\''$' diff --git a/tests/lib/test-setup.sh b/tests/lib/test-setup.sh new file mode 100644 index 0000000..12cf525 --- /dev/null +++ b/tests/lib/test-setup.sh @@ -0,0 +1,26 @@ +set -e + +foo_setup() { + + repo_dir="`mktemp -d`" + repo="$repo_dir/repo" + git init "$repo" + ( + cd "$repo" + echo Contents > test-file + git add test-file + git commit -m 'Commit message' + ) + + conf="`mktemp`" + cat > "$conf" < test-file - git add test-file - git commit -m 'Commit message' -) - -conf1="`mktemp`" -cat > "$conf1" < "$conf2" < "$conf2" <'\'' --install --from-expression '\''f: f \{ name = "(repo-[0-9]{10}-[0-9a-f]{11})"; channelName = "bar"; src = builtins.storePath "/nix/store/.{32}-\1.tar.xz"; \}'\'' '\''f: f \{ name = "\1"; channelName = "foo"; src = builtins.storePath "/nix/store/.{32}-\1.tar.xz"; \}'\''$' diff --git a/tests/pin-twice.sh b/tests/pin-twice.sh index b17af2c..5f51cc0 100755 --- a/tests/pin-twice.sh +++ b/tests/pin-twice.sh @@ -1,23 +1,8 @@ #!/bin/sh -set -e +. ./tests/lib/test-setup.sh -repo_dir="`mktemp -d`" -repo="$repo_dir/repo" -git init "$repo" -( - cd "$repo" - echo Contents > test-file - git add test-file - git commit -m 'Commit message' -) - -conf="`mktemp`" -cat > "$conf" <'\'' --install --from-expression '\''f: f \{ name = "(repo-[0-9]{10}-[0-9a-f]{11})"; channelName = "foo"; src = builtins.storePath "/nix/store/.{32}-\1.tar.xz"; \}'\''$' diff --git a/tests/reject-duplicates.sh b/tests/reject-duplicates.sh index d30bc40..8a630b0 100755 --- a/tests/reject-duplicates.sh +++ b/tests/reject-duplicates.sh @@ -1,50 +1,29 @@ #!/bin/sh -set -e - -repo_dir1="`mktemp -d`" -repo1="$repo_dir1/repo" -git init "$repo1" -( - cd "$repo1" - echo Contents > test-file - git add test-file - git commit -m 'Commit message' -) - -repo_dir2="`mktemp -d`" -repo2="$repo_dir2/repo" -git init "$repo2" -( - cd "$repo2" - echo Contents > test-file - git add test-file - git commit -m 'Commit message' -) - -conf1="`mktemp`" -cat > "$conf1" < "$conf2" < test-file - git add test-file - git commit -m 'Commit message' -) - -conf="`mktemp`" -cat > "$conf" <