]> git.scottworley.com Git - pinch/commitdiff
Factor out test setup
authorScott Worley <scottworley@scottworley.com>
Sat, 23 May 2020 00:55:41 +0000 (17:55 -0700)
committerScott Worley <scottworley@scottworley.com>
Sat, 23 May 2020 00:55:41 +0000 (17:55 -0700)
test.sh
tests/alias.sh
tests/core.sh
tests/lib/test-setup.sh [new file with mode: 0644]
tests/multi-update.sh
tests/pin-twice.sh
tests/reject-duplicates.sh
tests/reject-nonancestor.sh

diff --git a/test.sh b/test.sh
index 9823458496987f3695c5015936c54aaa558b92d4..9485418e5e9ecd33d4a7174deb255770113cf7d3 100755 (executable)
--- 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
index c7213403995d2d1093f1e1b57325aa67cf9f1cca..50839993f5a99ab404a4a996df313e12c18f0169 100755 (executable)
@@ -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" <<EOF
-[foo]
-git_repo = file://$repo
-git_ref = master
+. ./tests/lib/test-setup.sh
 
+foo_setup
+
+cat >> "$conf" <<EOF
 [bar]
 alias_of = foo
 EOF
@@ -26,7 +13,7 @@ python3 ./pinch.py pin "$conf"
 
 actual_env_command=`python3 ./pinch.py update --dry-run "$conf"`
 
-rm -rf "$repo_dir" "$conf"
+foo_cleanup
 
 expected_env_command_RE='^nix-env --profile /nix/var/nix/profiles/per-user/[^/]+/channels --show-trace --file '\''<nix/unpack-channel.nix>'\'' --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"; \}'\''$'
 
index 385ae2ba2bce33ead838020be80d62b38775d2de..da0d991089fd915a8ba308776537be21657d4588 100755 (executable)
@@ -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" <<EOF
-[foo]
-git_repo = file://$repo
-git_ref = master
-EOF
+foo_setup
 
 python3 ./pinch.py pin "$conf"
 
 actual_env_command=`python3 ./pinch.py update --dry-run "$conf"`
 
-rm -rf "$repo_dir" "$conf"
+foo_cleanup
 
 expected_env_command_RE='^nix-env --profile /nix/var/nix/profiles/per-user/[^/]+/channels --show-trace --file '\''<nix/unpack-channel.nix>'\'' --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 (file)
index 0000000..12cf525
--- /dev/null
@@ -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" <<EOF
+[foo]
+git_repo = file://$repo
+git_ref = master
+EOF
+
+}
+
+foo_cleanup() {
+  rm -rf "$repo_dir" "$conf"
+}
index 24c22bc18eaa1dee6a54904e653309d0efb8d0a1..d6a6d54c704a5b086582bb5f3ff1fb1c66559ac8 100755 (executable)
@@ -1,23 +1,8 @@
 #!/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'
-)
-
-conf1="`mktemp`"
-cat > "$conf1" <<EOF
-[foo]
-git_repo = file://$repo
-git_ref = master
-EOF
+. ./tests/lib/test-setup.sh
+
+foo_setup
 
 conf2="`mktemp`"
 cat > "$conf2" <<EOF
@@ -25,12 +10,13 @@ cat > "$conf2" <<EOF
 alias_of = foo
 EOF
 
-python3 ./pinch.py pin "$conf1"
+python3 ./pinch.py pin "$conf"
 python3 ./pinch.py pin "$conf2"
 
-actual_env_command=`python3 ./pinch.py update --dry-run "$conf1" "$conf2"`
+actual_env_command=`python3 ./pinch.py update --dry-run "$conf" "$conf2"`
 
-rm -rf "$repo_dir" "$conf1" "$conf2"
+foo_cleanup
+rm -rf "$conf2"
 
 expected_env_command_RE='^nix-env --profile /nix/var/nix/profiles/per-user/[^/]+/channels --show-trace --file '\''<nix/unpack-channel.nix>'\'' --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"; \}'\''$'
 
index b17af2c92d19b94754fd3eaced83a6703eba300c..5f51cc0bcd5191c9693f0ec4decbc72201711c20 100755 (executable)
@@ -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" <<EOF
-[foo]
-git_repo = file://$repo
-git_ref = master
-EOF
+foo_setup
 
 python3 ./pinch.py pin "$conf"
 
@@ -32,7 +17,7 @@ python3 ./pinch.py pin "$conf"
 
 actual_env_command=`python3 ./pinch.py update --dry-run "$conf"`
 
-rm -rf "$repo_dir" "$conf"
+foo_cleanup
 
 expected_env_command_RE='^nix-env --profile /nix/var/nix/profiles/per-user/[^/]+/channels --show-trace --file '\''<nix/unpack-channel.nix>'\'' --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"; \}'\''$'
 
index d30bc40e32ab37217f21279930d452f9fb44fc2f..8a630b049b10fdbfe47522d6865423358ca0c3c1 100755 (executable)
@@ -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" <<EOF
-[same]
-git_repo = file://$repo1
-git_ref = master
-EOF
-
-conf2="`mktemp`"
-cat > "$conf2" <<EOF
-[same]
-git_repo = file://$repo2
-git_ref = master
-EOF
+. ./tests/lib/test-setup.sh
+
+foo_setup
+
+repo_dir1=$repo_dir
+repo1=$repo
+conf1=$conf
+
+foo_setup
 
 python3 ./pinch.py pin "$conf1"
-python3 ./pinch.py pin "$conf2"
+python3 ./pinch.py pin "$conf"
 
-if python3 ./pinch.py update --dry-run "$conf1" "$conf2";then
+if python3 ./pinch.py update --dry-run "$conf1" "$conf";then
   echo "FAIL: Duplicate names should be rejected"
   exit 1
 else
   echo PASS
 fi
 
-rm -rf "$repo_dir1" "$repo_dir2" "$conf1" "$conf2"
+foo_cleanup
+
+repo_dir=$repo_dir1
+repo=$repo1
+conf=$conf1
 
+foo_cleanup
index b8e944ac52ced7713d562a08d2890f55e584e47d..5608761b23e54d9909d78bfe99d7ec41cd22459e 100755 (executable)
@@ -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" <<EOF
-[foo]
-git_repo = file://$repo
-git_ref = master
-EOF
+foo_setup
 
 python3 ./pinch.py pin "$conf"
 
@@ -35,4 +20,4 @@ else
   echo PASS
 fi
 
-rm -rf "$repo_dir" "$conf"
+foo_cleanup