Add filter_test_dir test utility

This commit is contained in:
Robert Wright 2023-08-30 14:46:49 +01:00 committed by G. Allais
parent 61878ef1b6
commit 2bde9104e0
29 changed files with 66 additions and 118 deletions

View File

@ -1,2 +0,0 @@
/expected

View File

@ -1,5 +1,5 @@
File Exists File Exists
False False
True True
Just "__PWD__testdir" Just "__TEST_DIR__/testdir"
hello hello

View File

@ -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

View File

@ -1,6 +1,6 @@
. ../../testutils.sh . ../../testutils.sh
./gen_expected.sh run dir.idr | filter_test_dir
run dir.idr
cat testdir/test.txt cat testdir/test.txt
rm -rf testdir rm -rf testdir

View File

@ -1,2 +0,0 @@
/expected

View File

@ -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

View File

@ -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

View File

@ -1,3 +0,0 @@
#!/usr/bin/env sh
sed -e "s|__PWD__|${MY_PWD}|g" expected.in >expected

View File

@ -1,19 +1,10 @@
. ../../testutils.sh . ../../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_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= 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 currently
rm -rf ../pkg010/build ../pkg010/currently

View File

@ -1,2 +0,0 @@
/expected

View File

@ -0,0 +1 @@
LOG package.depends:10: all depends: ["__TEST_DIR__/depends/bar-0.7.2", "__TEST_DIR__/depends/foo-0.1.0"]

View File

@ -1 +0,0 @@
LOG package.depends:10: all depends: ["__PWD__depends/bar-0.7.2", "__PWD__depends/foo-0.1.0"]

View File

@ -1,3 +0,0 @@
#!/usr/bin/env sh
sed -e "s|__PWD__|${MY_PWD}|g" expected.in >expected

View File

@ -1,11 +1,3 @@
. ../../testutils.sh . ../../testutils.sh
if [ "$OS" = "windows" ]; then idris2 --build test.ipkg --log package.depends:10 | filter_test_dir
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

View File

@ -1,2 +0,0 @@
/expected

View File

@ -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"]

View File

@ -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"]

View File

@ -1,3 +0,0 @@
#!/usr/bin/env sh
sed -e "s|__PWD__|${MY_PWD}|g" expected.in >expected

View File

@ -1,11 +1,3 @@
. ../../testutils.sh . ../../testutils.sh
if [ "$OS" = "windows" ]; then idris2 --build test.ipkg --log package.depends:10 | filter_test_dir
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

View File

@ -1,2 +0,0 @@
/expected

View File

@ -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

View File

@ -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

View File

@ -1,3 +0,0 @@
#!/usr/bin/env sh
sed -e "s|__PWD__|${MY_PWD}|g" expected.in >expected

View File

@ -1,20 +1,12 @@
. ../../testutils.sh . ../../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 mkdir prefix
IDRIS2_PREFIX="${MY_PWD}/prefix" idris2 --install-with-src a1/a1.ipkg > /dev/null IDRIS2_PREFIX="$test_dir/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 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="$test_dir/prefix" idris2 --no-prelude --ide-mode < input1 | grep -v ":highlight-source" | cut -c 7- | filter_test_dir
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 < input2 | grep -v ":highlight-source" | cut -c 7- | filter_test_dir
rm -r a1/build a2/build b1/build b2/build rm -r a1/build a2/build b1/build b2/build
rm -rf prefix rm -rf prefix

View File

@ -1,2 +0,0 @@
/expected

View File

@ -1,5 +1,5 @@
File Exists File Exists
False False
True True
Just "__PWD__testdir" Just "__TEST_DIR__/testdir"
hello hello

View File

@ -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

View File

@ -2,6 +2,5 @@
rm -rf testdir rm -rf testdir
./gen_expected.sh run --cg node dir.idr | filter_test_dir
run --cg node dir.idr
cat testdir/test.txt cat testdir/test.txt

View File

@ -21,3 +21,25 @@ check() {
run() { run() {
idris2 --exec main "$@" 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"
}