From 968b84e0b58c9aea95369841ee91d2244f228016 Mon Sep 17 00:00:00 2001 From: Reed Everis Date: Wed, 6 Mar 2024 18:54:18 +0000 Subject: [PATCH] all tests except compiles-4-section --- tests/plcc/can-print-json-ast/prints-json-ast.bats | 14 ++++++++------ .../compiles-4-section/compiles-4-section.bats | 10 ++++++---- tests/plcc/compiles-obj/compiles-obj.bats | 6 ++++-- tests/plcc/detects-illegal-tokens.bats | 7 ++++--- tests/plcc/generate-python.bats | 14 ++++++++------ tests/plcc/no-4th-section.bats | 10 ++++++---- tests/plcc/parses.bats | 8 +++++--- tests/plcc/scans-tokens.bats | 8 +++++--- 8 files changed, 46 insertions(+), 31 deletions(-) diff --git a/tests/plcc/can-print-json-ast/prints-json-ast.bats b/tests/plcc/can-print-json-ast/prints-json-ast.bats index 7f1e0d31..2e683264 100644 --- a/tests/plcc/can-print-json-ast/prints-json-ast.bats +++ b/tests/plcc/can-print-json-ast/prints-json-ast.bats @@ -1,19 +1,21 @@ #!/usr/bin/env bats +teardown() { + rm -rf ${BATS_TMPDIR}/expected.json + rm -rf ${BATS_TMPDIR}/given-grammar.lang + rm -rf ${BATS_TMPDIR}/given-program.lang + rm -rf ${BATS_TMPDIR}/result.json + rm -rf ${BATS_TMPDIR}/Java +} + @test "PLCC can print JSON AST." { FILES="expected.json given-grammar.lang given-program.lang" for f in $FILES ; do cp "${BATS_TEST_DIRNAME}/${f}" "${BATS_TMPDIR}" done - cp "${BATS_TEST_DIRNAME}"/* "$BATS_TMPDIR/" cd "${BATS_TMPDIR}" plccmk --json_ast given-grammar.lang parse -n --json_ast < given-program.lang > result.json diff expected.json result.json - - for f in $FILES ; do - rm "${BATS_TMPDIR}/${f}" - done - rm "${BATS_TMPDIR}/result.json" } diff --git a/tests/plcc/compiles-4-section/compiles-4-section.bats b/tests/plcc/compiles-4-section/compiles-4-section.bats index 9f5a540a..b4775ce0 100644 --- a/tests/plcc/compiles-4-section/compiles-4-section.bats +++ b/tests/plcc/compiles-4-section/compiles-4-section.bats @@ -1,6 +1,10 @@ #!/usr/bin/env bats -@test "PLCC compiles the OBJ language." { +teardown() { + rm -rf "$BATS_TMPDIR/OBJ" +} + +@test "PLCC compiles with 4 sections." { # Copy the OBJ language to the temp directory for this test cp -R "${BATS_TEST_DIRNAME}/OBJ" "${BATS_TMPDIR}" @@ -14,7 +18,7 @@ cd Java # Compile the Java files. - run javac *.java + run javac -cp /../../../../../lib/jackson/* *.java # Print stdout and stderr for debugging. echo "OUTPUT: $output" @@ -22,6 +26,4 @@ # Assert success. [ "$status" -eq 0 ] - - rm -rf "$BATS_TMPDIR/OBJ" } diff --git a/tests/plcc/compiles-obj/compiles-obj.bats b/tests/plcc/compiles-obj/compiles-obj.bats index 9f5a540a..011fa5cd 100644 --- a/tests/plcc/compiles-obj/compiles-obj.bats +++ b/tests/plcc/compiles-obj/compiles-obj.bats @@ -1,5 +1,9 @@ #!/usr/bin/env bats +teardown() { + rm -rf "$BATS_TMPDIR/OBJ" +} + @test "PLCC compiles the OBJ language." { # Copy the OBJ language to the temp directory for this test cp -R "${BATS_TEST_DIRNAME}/OBJ" "${BATS_TMPDIR}" @@ -22,6 +26,4 @@ # Assert success. [ "$status" -eq 0 ] - - rm -rf "$BATS_TMPDIR/OBJ" } diff --git a/tests/plcc/detects-illegal-tokens.bats b/tests/plcc/detects-illegal-tokens.bats index a54bbd99..27aaca3e 100644 --- a/tests/plcc/detects-illegal-tokens.bats +++ b/tests/plcc/detects-illegal-tokens.bats @@ -1,5 +1,9 @@ #!/usr/bin/env bats +teardown() { + rm -rf ${BATS_TMPDIR}/grammar +} + @test "PLCC detects illegal tokens." { # GIVEN a grammar file with a bad token name cat << EOF > "$BATS_TMPDIR/grammar" @@ -18,7 +22,4 @@ EOF # AND plcc reports that there is an "illegal token name" [[ "$output" = *"illegal token name"* ]] - - # cleanup - rm "$BATS_TMPDIR/grammar" } diff --git a/tests/plcc/generate-python.bats b/tests/plcc/generate-python.bats index 5d3ec83e..7470b5fc 100644 --- a/tests/plcc/generate-python.bats +++ b/tests/plcc/generate-python.bats @@ -1,5 +1,11 @@ #!/usr/bin/env bats +teardown() { + rm -rf ${BATS_TMPDIR}/grammar + rm -rf ${BATS_TMPDIR}/Java + rm -rf ${BATS_TMPDIR}/Python +} + @test "Creates Python directory when 4th section detected." { cat << EOF > "$BATS_TMPDIR/grammar" A 'A' @@ -12,12 +18,8 @@ skip OTHER '.' % EOF - RESULT="$(cd "$BATS_TMPDIR" && plccmk -c grammar)" + RESULT="$(cd "$BATS_TMPDIR" && plccmk --json_ast grammar)" echo "RESULT: $RESULT" [[ -d $BATS_TMPDIR/Python ]] - - rm -rf "$BATS_TMPDIR/grammar" - rm -rf "$BATS_TMPDIR/Java" - rm -rf "$BATS_TMPDIR/Python" -} \ No newline at end of file +} diff --git a/tests/plcc/no-4th-section.bats b/tests/plcc/no-4th-section.bats index 2f792dd8..bd72afbd 100644 --- a/tests/plcc/no-4th-section.bats +++ b/tests/plcc/no-4th-section.bats @@ -1,5 +1,10 @@ #!/usr/bin/env bats +teardown() { + rm -rf ${BATS_TMPDIR}/grammar + rm -rf ${BATS_TMPDIR}/Java +} + @test "Functions correctly when no 4th section exists." { cat << EOF > "$BATS_TMPDIR/grammar" A 'A' @@ -15,7 +20,4 @@ EOF echo "RESULT: $RESULT" [[ ! -d $BATS_TMPDIR/Python ]] - - rm -rf "$BATS_TMPDIR/grammar" - rm -rf "$BATS_TMPDIR/Java" -} \ No newline at end of file +} diff --git a/tests/plcc/parses.bats b/tests/plcc/parses.bats index 65556d8b..cec2de5c 100644 --- a/tests/plcc/parses.bats +++ b/tests/plcc/parses.bats @@ -1,5 +1,10 @@ #!/usr/bin/env bats +teardown() { + rm -rf ${BATS_TMPDIR}/grammar + rm -rf ${BATS_TMPDIR}/Java +} + @test "PLCC parses." { cat << EOF > "$BATS_TMPDIR/grammar" A 'A' @@ -14,7 +19,4 @@ EOF echo "RESULT: $RESULT" [[ "$RESULT" =~ .*OK.* ]] - - rm -rf "$BATS_TMPDIR/grammar" - rm -rf "$BATS_TMPDIR/Java" } diff --git a/tests/plcc/scans-tokens.bats b/tests/plcc/scans-tokens.bats index e28280ba..d667be73 100644 --- a/tests/plcc/scans-tokens.bats +++ b/tests/plcc/scans-tokens.bats @@ -1,5 +1,10 @@ #!/usr/bin/env bats +teardown() { + rm -rf ${BATS_TMPDIR}/grammar + rm -rf ${BATS_TMPDIR}/Java +} + @test "PLCC scans." { cat << EOF > "$BATS_TMPDIR/grammar" skip WHITESPACE '\s' @@ -20,7 +25,4 @@ EOF [[ "$TOKENS" =~ "FOO 'foo'" ]] [[ "$TOKENS" =~ "BAR 'bar'" ]] [[ "$TOKENS" =~ "ID 'foobar'" ]] - - rm -rf "$BATS_TMPDIR/grammar" - rm -rf "$BATS_TMPDIR/Java" }