From c176efb13ae266a4fe8b2c90011434efbd7754a1 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Fri, 4 Oct 2024 11:11:46 -0700 Subject: [PATCH] Add some tests for modules * .gitignore now ignores *.got for *anything* under the tests/ directory * runtests.sh ignores files in the tests/ directory that have the string "test_import_" in them, so they are not run as tests themselves * Add a couple of basic module functionality tests Signed-off-by: Alek Ratzloff --- .gitignore | 2 +- runtests.sh | 2 +- tests/modules.npp | 6 ++++++ tests/modules.npp.expect | 5 +++++ tests/modules/test_import_directory.npp | 1 + tests/test_import_local.npp | 5 +++++ 6 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/modules.npp create mode 100644 tests/modules.npp.expect create mode 100644 tests/modules/test_import_directory.npp create mode 100644 tests/test_import_local.npp diff --git a/.gitignore b/.gitignore index e03a67d..a6c53c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -tests/*.got +tests/**/*.got /target diff --git a/runtests.sh b/runtests.sh index 06a00a1..982d97a 100755 --- a/runtests.sh +++ b/runtests.sh @@ -17,7 +17,7 @@ echo "building" cargo build $flags || die "build failed" echo "testing" -find "$tests" -type f -name '*.npp' | while read f; do +find "$tests" -type f -name '*.npp' -not -name "*test_import_*" | while read f; do result="$(cargo run $flags -- "$f")" echo "$result" > "$f.got" diff --git a/tests/modules.npp b/tests/modules.npp new file mode 100644 index 0000000..e202c61 --- /dev/null +++ b/tests/modules.npp @@ -0,0 +1,6 @@ +import "modules/test_import_directory.npp" +import test_import_local + +println(test_import_local.foo) +println(test_import_local.bar) +println(test_import_local.baz) diff --git a/tests/modules.npp.expect b/tests/modules.npp.expect new file mode 100644 index 0000000..b8de9d0 --- /dev/null +++ b/tests/modules.npp.expect @@ -0,0 +1,5 @@ +importing test_import_directory +importing test_import_local +1 +2 +3 diff --git a/tests/modules/test_import_directory.npp b/tests/modules/test_import_directory.npp new file mode 100644 index 0000000..e8d9b90 --- /dev/null +++ b/tests/modules/test_import_directory.npp @@ -0,0 +1 @@ +println("importing test_import_directory") diff --git a/tests/test_import_local.npp b/tests/test_import_local.npp new file mode 100644 index 0000000..9240add --- /dev/null +++ b/tests/test_import_local.npp @@ -0,0 +1,5 @@ +println("importing test_import_local") + +foo = 1 +bar = 2 +baz = 3