From 2bde9104e0285df46d077b8070a33e3853eb9e24 Mon Sep 17 00:00:00 2001 From: Robert Wright Date: Wed, 30 Aug 2023 14:46:49 +0100 Subject: [PATCH] Add filter_test_dir test utility --- tests/chez/chez017/.gitignore | 2 -- .../expected.in => chez/chez017/expected} | 2 +- tests/chez/chez017/gen_expected.sh | 8 ------- tests/chez/chez017/run | 4 ++-- tests/idris2/pkg010/.gitignore | 2 -- tests/idris2/pkg010/expected | 6 +++++ tests/idris2/pkg010/expected.in | 6 ----- tests/idris2/pkg010/gen_expected.sh | 3 --- tests/idris2/pkg010/run | 15 +++---------- tests/idris2/pkg013/.gitignore | 2 -- tests/idris2/pkg013/expected | 1 + tests/idris2/pkg013/expected.in | 1 - tests/idris2/pkg013/gen_expected.sh | 3 --- tests/idris2/pkg013/run | 10 +-------- tests/idris2/pkg014/.gitignore | 2 -- tests/idris2/pkg014/expected | 1 + tests/idris2/pkg014/expected.in | 1 - tests/idris2/pkg014/gen_expected.sh | 3 --- tests/idris2/pkg014/run | 10 +-------- tests/idris2/pkg017/.gitignore | 2 -- tests/idris2/pkg017/expected | 22 +++++++++++++++++++ tests/idris2/pkg017/expected.in | 22 ------------------- tests/idris2/pkg017/gen_expected.sh | 3 --- tests/idris2/pkg017/run | 16 ++++---------- tests/node/node017/.gitignore | 2 -- .../expected.in => node/node017/expected} | 2 +- tests/node/node017/gen_expected.sh | 8 ------- tests/node/node017/run | 3 +-- tests/testutils.sh | 22 +++++++++++++++++++ 29 files changed, 66 insertions(+), 118 deletions(-) delete mode 100644 tests/chez/chez017/.gitignore rename tests/{node/node017/expected.in => chez/chez017/expected} (50%) delete mode 100755 tests/chez/chez017/gen_expected.sh delete mode 100644 tests/idris2/pkg010/.gitignore create mode 100644 tests/idris2/pkg010/expected delete mode 100644 tests/idris2/pkg010/expected.in delete mode 100755 tests/idris2/pkg010/gen_expected.sh delete mode 100644 tests/idris2/pkg013/.gitignore create mode 100644 tests/idris2/pkg013/expected delete mode 100644 tests/idris2/pkg013/expected.in delete mode 100755 tests/idris2/pkg013/gen_expected.sh delete mode 100644 tests/idris2/pkg014/.gitignore create mode 100644 tests/idris2/pkg014/expected delete mode 100644 tests/idris2/pkg014/expected.in delete mode 100755 tests/idris2/pkg014/gen_expected.sh delete mode 100644 tests/idris2/pkg017/.gitignore create mode 100644 tests/idris2/pkg017/expected delete mode 100644 tests/idris2/pkg017/expected.in delete mode 100755 tests/idris2/pkg017/gen_expected.sh delete mode 100644 tests/node/node017/.gitignore rename tests/{chez/chez017/expected.in => node/node017/expected} (50%) delete mode 100755 tests/node/node017/gen_expected.sh diff --git a/tests/chez/chez017/.gitignore b/tests/chez/chez017/.gitignore deleted file mode 100644 index 062cbdb0b..000000000 --- a/tests/chez/chez017/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/expected - diff --git a/tests/node/node017/expected.in b/tests/chez/chez017/expected similarity index 50% rename from tests/node/node017/expected.in rename to tests/chez/chez017/expected index 916d21080..6704aadaa 100644 --- a/tests/node/node017/expected.in +++ b/tests/chez/chez017/expected @@ -1,5 +1,5 @@ File Exists False True -Just "__PWD__testdir" +Just "__TEST_DIR__/testdir" hello diff --git a/tests/chez/chez017/gen_expected.sh b/tests/chez/chez017/gen_expected.sh deleted file mode 100755 index f67086129..000000000 --- a/tests/chez/chez017/gen_expected.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env sh -if [ "$OS" = "windows" ]; then - MY_PWD="$(cygpath -m "$(pwd)")\\\\" -else - MY_PWD="$(pwd)/" -fi - -sed -e "s|__PWD__|${MY_PWD}|g" expected.in >expected diff --git a/tests/chez/chez017/run b/tests/chez/chez017/run index f15d224d6..de86932a8 100755 --- a/tests/chez/chez017/run +++ b/tests/chez/chez017/run @@ -1,6 +1,6 @@ . ../../testutils.sh -./gen_expected.sh -run dir.idr +run dir.idr | filter_test_dir + cat testdir/test.txt rm -rf testdir diff --git a/tests/idris2/pkg010/.gitignore b/tests/idris2/pkg010/.gitignore deleted file mode 100644 index 062cbdb0b..000000000 --- a/tests/idris2/pkg010/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/expected - diff --git a/tests/idris2/pkg010/expected b/tests/idris2/pkg010/expected new file mode 100644 index 000000000..8b26eec40 --- /dev/null +++ b/tests/idris2/pkg010/expected @@ -0,0 +1,6 @@ +1/1: Building Main (Main.idr) +Installing __TEST_DIR__/build/ttc/Main.ttc to __TEST_DIR__/currently/nonexistent/dir/idris2-0.6.0/testpkg-0 +Installing __TEST_DIR__/build/ttc/Main.ttm to __TEST_DIR__/currently/nonexistent/dir/idris2-0.6.0/testpkg-0 +Installing __TEST_DIR__/build/ttc/Main.ttc to __TEST_DIR__/currently/nonexistent/dir/idris2-0.6.0/testpkg-0 +Installing __TEST_DIR__/build/ttc/Main.ttm to __TEST_DIR__/currently/nonexistent/dir/idris2-0.6.0/testpkg-0 +Installing package file for testpkg to __TEST_DIR__/currently/nonexistent/dir/idris2-0.6.0/testpkg-0 diff --git a/tests/idris2/pkg010/expected.in b/tests/idris2/pkg010/expected.in deleted file mode 100644 index 87fb1dc77..000000000 --- a/tests/idris2/pkg010/expected.in +++ /dev/null @@ -1,6 +0,0 @@ -1/1: Building Main (Main.idr) -Installing __PWD__build/ttc/Main.ttc to __PWD__currently/nonexistent/dir/idris2-0.6.0/testpkg-0 -Installing __PWD__build/ttc/Main.ttm to __PWD__currently/nonexistent/dir/idris2-0.6.0/testpkg-0 -Installing __PWD__build/ttc/Main.ttc to __PWD__currently/nonexistent/dir/idris2-0.6.0/testpkg-0 -Installing __PWD__build/ttc/Main.ttm to __PWD__currently/nonexistent/dir/idris2-0.6.0/testpkg-0 -Installing package file for testpkg to __PWD__currently/nonexistent/dir/idris2-0.6.0/testpkg-0 diff --git a/tests/idris2/pkg010/gen_expected.sh b/tests/idris2/pkg010/gen_expected.sh deleted file mode 100755 index 193a8ad31..000000000 --- a/tests/idris2/pkg010/gen_expected.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -sed -e "s|__PWD__|${MY_PWD}|g" expected.in >expected diff --git a/tests/idris2/pkg010/run b/tests/idris2/pkg010/run index 32df9792a..9277c1178 100755 --- a/tests/idris2/pkg010/run +++ b/tests/idris2/pkg010/run @@ -1,19 +1,10 @@ . ../../testutils.sh -if [ "$OS" = "windows" ]; then - MY_PWD="$(cygpath -m "$(pwd)")\\\\" -else - MY_PWD="$(pwd)/" -fi - -MY_PWD="${MY_PWD}" ./gen_expected.sh - export IDRIS2_PACKAGE_PATH=$IDRIS2_PREFIX/$NAME_VERSION -export IDRIS2_PREFIX=${MY_PWD}currently/nonexistent/dir/ +export IDRIS2_PREFIX=$test_dir/currently/nonexistent/dir/ export IDRIS2_INC_CGS= -idris2 --install ./testpkg.ipkg | sed -r "s/.([0-9]){10}//g" +idris2 --install ./testpkg.ipkg | sed -r "s/.([0-9]){10}//g" | filter_test_dir -# ../ is there for some extra safety for using rm -rf -rm -rf ../pkg010/build ../pkg010/currently +rm -rf currently diff --git a/tests/idris2/pkg013/.gitignore b/tests/idris2/pkg013/.gitignore deleted file mode 100644 index 062cbdb0b..000000000 --- a/tests/idris2/pkg013/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/expected - diff --git a/tests/idris2/pkg013/expected b/tests/idris2/pkg013/expected new file mode 100644 index 000000000..5a1648c6d --- /dev/null +++ b/tests/idris2/pkg013/expected @@ -0,0 +1 @@ +LOG package.depends:10: all depends: ["__TEST_DIR__/depends/bar-0.7.2", "__TEST_DIR__/depends/foo-0.1.0"] diff --git a/tests/idris2/pkg013/expected.in b/tests/idris2/pkg013/expected.in deleted file mode 100644 index c8780af90..000000000 --- a/tests/idris2/pkg013/expected.in +++ /dev/null @@ -1 +0,0 @@ -LOG package.depends:10: all depends: ["__PWD__depends/bar-0.7.2", "__PWD__depends/foo-0.1.0"] diff --git a/tests/idris2/pkg013/gen_expected.sh b/tests/idris2/pkg013/gen_expected.sh deleted file mode 100755 index 193a8ad31..000000000 --- a/tests/idris2/pkg013/gen_expected.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -sed -e "s|__PWD__|${MY_PWD}|g" expected.in >expected diff --git a/tests/idris2/pkg013/run b/tests/idris2/pkg013/run index 84b6a3e57..4a39ba369 100644 --- a/tests/idris2/pkg013/run +++ b/tests/idris2/pkg013/run @@ -1,11 +1,3 @@ . ../../testutils.sh -if [ "$OS" = "windows" ]; then - MY_PWD="$(cygpath -m "$(pwd)")\\\\" -else - MY_PWD="$(pwd)/" -fi - -MY_PWD="${MY_PWD}" ./gen_expected.sh - -idris2 --build test.ipkg --log package.depends:10 +idris2 --build test.ipkg --log package.depends:10 | filter_test_dir diff --git a/tests/idris2/pkg014/.gitignore b/tests/idris2/pkg014/.gitignore deleted file mode 100644 index 062cbdb0b..000000000 --- a/tests/idris2/pkg014/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/expected - diff --git a/tests/idris2/pkg014/expected b/tests/idris2/pkg014/expected new file mode 100644 index 000000000..a3766016f --- /dev/null +++ b/tests/idris2/pkg014/expected @@ -0,0 +1 @@ +LOG package.depends:10: all depends: ["__TEST_DIR__/depends/bar-0.1.0", "__TEST_DIR__/depends/baz-0.2.0", "__TEST_DIR__/depends/foo-0.2.0"] diff --git a/tests/idris2/pkg014/expected.in b/tests/idris2/pkg014/expected.in deleted file mode 100644 index 8b1b4576e..000000000 --- a/tests/idris2/pkg014/expected.in +++ /dev/null @@ -1 +0,0 @@ -LOG package.depends:10: all depends: ["__PWD__depends/bar-0.1.0", "__PWD__depends/baz-0.2.0", "__PWD__depends/foo-0.2.0"] diff --git a/tests/idris2/pkg014/gen_expected.sh b/tests/idris2/pkg014/gen_expected.sh deleted file mode 100755 index 193a8ad31..000000000 --- a/tests/idris2/pkg014/gen_expected.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -sed -e "s|__PWD__|${MY_PWD}|g" expected.in >expected diff --git a/tests/idris2/pkg014/run b/tests/idris2/pkg014/run index 84b6a3e57..4a39ba369 100644 --- a/tests/idris2/pkg014/run +++ b/tests/idris2/pkg014/run @@ -1,11 +1,3 @@ . ../../testutils.sh -if [ "$OS" = "windows" ]; then - MY_PWD="$(cygpath -m "$(pwd)")\\\\" -else - MY_PWD="$(pwd)/" -fi - -MY_PWD="${MY_PWD}" ./gen_expected.sh - -idris2 --build test.ipkg --log package.depends:10 +idris2 --build test.ipkg --log package.depends:10 | filter_test_dir diff --git a/tests/idris2/pkg017/.gitignore b/tests/idris2/pkg017/.gitignore deleted file mode 100644 index 062cbdb0b..000000000 --- a/tests/idris2/pkg017/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/expected - diff --git a/tests/idris2/pkg017/expected b/tests/idris2/pkg017/expected new file mode 100644 index 000000000..9bf1e5612 --- /dev/null +++ b/tests/idris2/pkg017/expected @@ -0,0 +1,22 @@ +(:protocol-version 2 1) +(:return (:ok "Current working directory is \"__TEST_DIR__/b1\"") 1) +(:write-string "1/1: Building B1 (src/B1.idr)" 2) +(:return (:ok ()) 2) +(:return (:ok "1" ((0 1 ((:decor :data))))) 4) +(:return (:ok (("A.i" (:filename "__TEST_DIR__/prefix/idris2-0.6.0/a1-0/A.idr") (:start 2 0) (:end 3 7)))) 5) +(:return (:ok "Current working directory is \"__TEST_DIR__/b2\"") 6) +(:write-string "1/1: Building B2 (src/B2.idr)" 7) +(:return (:ok ()) 7) +(:return (:ok "2" ((0 1 ((:decor :data))))) 8) +(:return (:ok (("A.i" (:filename "__TEST_DIR__/prefix/idris2-0.6.0/a2-0/A.idr") (:start 2 0) (:end 3 7)))) 9) +he file is done, aborting +(:protocol-version 2 1) +(:return (:ok "Current working directory is \"__TEST_DIR__/b2\"") 1) +(:return (:ok ()) 2) +(:return (:ok "2" ((0 1 ((:decor :data))))) 4) +(:return (:ok (("A.i" (:filename "__TEST_DIR__/prefix/idris2-0.6.0/a2-0/A.idr") (:start 2 0) (:end 3 7)))) 5) +(:return (:ok "Current working directory is \"__TEST_DIR__/b1\"") 6) +(:return (:ok ()) 7) +(:return (:ok "1" ((0 1 ((:decor :data))))) 8) +(:return (:ok (("A.i" (:filename "__TEST_DIR__/prefix/idris2-0.6.0/a1-0/A.idr") (:start 2 0) (:end 3 7)))) 9) +he file is done, aborting diff --git a/tests/idris2/pkg017/expected.in b/tests/idris2/pkg017/expected.in deleted file mode 100644 index 9c5483764..000000000 --- a/tests/idris2/pkg017/expected.in +++ /dev/null @@ -1,22 +0,0 @@ -(:protocol-version 2 1) -(:return (:ok "Current working directory is \"__PWD__b1\"") 1) -(:write-string "1/1: Building B1 (src/B1.idr)" 2) -(:return (:ok ()) 2) -(:return (:ok "1" ((0 1 ((:decor :data))))) 4) -(:return (:ok (("A.i" (:filename "__PWD__prefix/idris2-0.6.0/a1-0/A.idr") (:start 2 0) (:end 3 7)))) 5) -(:return (:ok "Current working directory is \"__PWD__b2\"") 6) -(:write-string "1/1: Building B2 (src/B2.idr)" 7) -(:return (:ok ()) 7) -(:return (:ok "2" ((0 1 ((:decor :data))))) 8) -(:return (:ok (("A.i" (:filename "__PWD__prefix/idris2-0.6.0/a2-0/A.idr") (:start 2 0) (:end 3 7)))) 9) -he file is done, aborting -(:protocol-version 2 1) -(:return (:ok "Current working directory is \"__PWD__b2\"") 1) -(:return (:ok ()) 2) -(:return (:ok "2" ((0 1 ((:decor :data))))) 4) -(:return (:ok (("A.i" (:filename "__PWD__prefix/idris2-0.6.0/a2-0/A.idr") (:start 2 0) (:end 3 7)))) 5) -(:return (:ok "Current working directory is \"__PWD__b1\"") 6) -(:return (:ok ()) 7) -(:return (:ok "1" ((0 1 ((:decor :data))))) 8) -(:return (:ok (("A.i" (:filename "__PWD__prefix/idris2-0.6.0/a1-0/A.idr") (:start 2 0) (:end 3 7)))) 9) -he file is done, aborting diff --git a/tests/idris2/pkg017/gen_expected.sh b/tests/idris2/pkg017/gen_expected.sh deleted file mode 100755 index 193a8ad31..000000000 --- a/tests/idris2/pkg017/gen_expected.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -sed -e "s|__PWD__|${MY_PWD}|g" expected.in >expected diff --git a/tests/idris2/pkg017/run b/tests/idris2/pkg017/run index 3cbf19eb7..b99a65f8a 100644 --- a/tests/idris2/pkg017/run +++ b/tests/idris2/pkg017/run @@ -1,20 +1,12 @@ . ../../testutils.sh -if [ "$OS" = "windows" ]; then - MY_PWD="$(cygpath -m "$(pwd)")\\\\" -else - MY_PWD="$(pwd)/" -fi - -MY_PWD="${MY_PWD}" ./gen_expected.sh - mkdir prefix -IDRIS2_PREFIX="${MY_PWD}/prefix" idris2 --install-with-src a1/a1.ipkg > /dev/null -IDRIS2_PREFIX="${MY_PWD}/prefix" idris2 --install-with-src a2/a2.ipkg > /dev/null +IDRIS2_PREFIX="$test_dir/prefix" idris2 --install-with-src a1/a1.ipkg > /dev/null +IDRIS2_PREFIX="$test_dir/prefix" idris2 --install-with-src a2/a2.ipkg > /dev/null -IDRIS2_PREFIX="${MY_PWD}/prefix" idris2 --no-prelude --ide-mode < input1 | grep -v ":highlight-source" | cut -c 7- -IDRIS2_PREFIX="${MY_PWD}/prefix" idris2 --no-prelude --ide-mode < input2 | grep -v ":highlight-source" | cut -c 7- +IDRIS2_PREFIX="$test_dir/prefix" idris2 --no-prelude --ide-mode < input1 | grep -v ":highlight-source" | cut -c 7- | filter_test_dir +IDRIS2_PREFIX="$test_dir/prefix" idris2 --no-prelude --ide-mode < input2 | grep -v ":highlight-source" | cut -c 7- | filter_test_dir rm -r a1/build a2/build b1/build b2/build rm -rf prefix diff --git a/tests/node/node017/.gitignore b/tests/node/node017/.gitignore deleted file mode 100644 index 062cbdb0b..000000000 --- a/tests/node/node017/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/expected - diff --git a/tests/chez/chez017/expected.in b/tests/node/node017/expected similarity index 50% rename from tests/chez/chez017/expected.in rename to tests/node/node017/expected index 916d21080..6704aadaa 100644 --- a/tests/chez/chez017/expected.in +++ b/tests/node/node017/expected @@ -1,5 +1,5 @@ File Exists False True -Just "__PWD__testdir" +Just "__TEST_DIR__/testdir" hello diff --git a/tests/node/node017/gen_expected.sh b/tests/node/node017/gen_expected.sh deleted file mode 100755 index f67086129..000000000 --- a/tests/node/node017/gen_expected.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env sh -if [ "$OS" = "windows" ]; then - MY_PWD="$(cygpath -m "$(pwd)")\\\\" -else - MY_PWD="$(pwd)/" -fi - -sed -e "s|__PWD__|${MY_PWD}|g" expected.in >expected diff --git a/tests/node/node017/run b/tests/node/node017/run index 45e683248..beb8b73c5 100755 --- a/tests/node/node017/run +++ b/tests/node/node017/run @@ -2,6 +2,5 @@ rm -rf testdir -./gen_expected.sh -run --cg node dir.idr +run --cg node dir.idr | filter_test_dir cat testdir/test.txt diff --git a/tests/testutils.sh b/tests/testutils.sh index 24951eb14..6dcb4179b 100755 --- a/tests/testutils.sh +++ b/tests/testutils.sh @@ -21,3 +21,25 @@ check() { run() { idris2 --exec main "$@" } + +# Escape a string as a sed pattern literal +# Usage: sed -e "s/$(sed_literal 'some\literal/')/some replacement/g" +sed_literal() { + # Using printf instead of echo, as echo interprets backslashes as escape sequences on some platforms + printf '%s\n' "$1" | sed -e 's/[]\/$*.^[]/\\&/g' +} + +# Folder containing the currently running test +if [ "$OS" = "windows" ]; then + test_dir="$(cygpath -m "$(pwd)")" +else + test_dir="$(pwd)" +fi + +# Remove test directory from output +# Useful for consistency of output between machines +# Usage: run SomeTest.idr | filter_test_dir +filter_test_dir() { + sed -e 's/\\\{1,2\}\b/\//g' | # Guess at where Windows \ need to be replaced by / + sed -e "s/$(sed_literal "$test_dir")/__TEST_DIR__/g" +}