From ca65f2ae6eec918ccd1bcccefeefa75debba12fa Mon Sep 17 00:00:00 2001 From: Reed Everis Date: Sun, 7 Apr 2024 22:29:53 +0000 Subject: [PATCH] finalize tests --- src/plccmk | 3 ++- .../compiles-4-section.bats | 21 +++++++++---------- tests/plcc/compiles-obj/compiles-obj.bats | 2 +- tests/plcc/generate-python.bats | 14 +++++++------ tests/plcc/no-4th-section.bats | 14 ++++++++----- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/plccmk b/src/plccmk index e95ee675..ba6e0a67 100755 --- a/src/plccmk +++ b/src/plccmk @@ -10,6 +10,7 @@ JACKSON_ANNOTATIONS="${LIBPLCC_LIB}/lib/jackson/jackson-annotations-${JACKSON_VE JACKSON_CORE="${LIBPLCC_LIB}/lib/jackson/jackson-core-${JACKSON_VERSION}.jar" JACKSON_DATABIND="${LIBPLCC_LIB}/lib/jackson/jackson-databind-${JACKSON_VERSION}.jar" CP="${JACKSON_ANNOTATIONS}:${JACKSON_CORE}:${JACKSON_DATABIND}" +export CLASSPATH=".:${CP}" if [ "$1" = "-c" ]; then @@ -57,7 +58,7 @@ then done (cd ./Java ; javac -cp ".:${CP}" *.java) -else +else (cd ./Java ; javac *.java) fi diff --git a/tests/plcc/compiles-4-section/compiles-4-section.bats b/tests/plcc/compiles-4-section/compiles-4-section.bats index dd144967..f6867d3c 100644 --- a/tests/plcc/compiles-4-section/compiles-4-section.bats +++ b/tests/plcc/compiles-4-section/compiles-4-section.bats @@ -1,29 +1,28 @@ #!/usr/bin/env bats +setup() { + mkdir ${BATS_TMPDIR}/4-section-test +} + teardown() { - rm -rf "$BATS_TMPDIR/OBJ" + cd ../../../.. + rm -rf ${BATS_TMPDIR}/4-section-test } @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}" + cp -R "${BATS_TEST_DIRNAME}/OBJ" "${BATS_TMPDIR}/4-section-test" # Change into the temporary OBJ directory. - cd "${BATS_TMPDIR}/OBJ" + cd "${BATS_TMPDIR}/4-section-test/OBJ" # Use plcc to generate the Java files from the OBJ grammar file. - plcc "grammar" - - # Change into the generated Java file. - cd Java - - # Compile the Java files. - run javac -cp "/${BATS_TEST_DIRNAME}/../../../lib/jackson/*" *.java + plccmk grammar # Print stdout and stderr for debugging. echo "OUTPUT: $output" echo "ERROR: $error" # Assert success. - [ "$status" -eq 0 ] + [[ "$status" -eq 0 ]] } diff --git a/tests/plcc/compiles-obj/compiles-obj.bats b/tests/plcc/compiles-obj/compiles-obj.bats index bf38be7d..856861a1 100644 --- a/tests/plcc/compiles-obj/compiles-obj.bats +++ b/tests/plcc/compiles-obj/compiles-obj.bats @@ -30,5 +30,5 @@ teardown() { echo "ERROR: $error" # Assert success. - [ "$status" -eq 0 ] + [[ "$status" -eq 0 ]] } diff --git a/tests/plcc/generate-python.bats b/tests/plcc/generate-python.bats index 7470b5fc..1bcb71b0 100644 --- a/tests/plcc/generate-python.bats +++ b/tests/plcc/generate-python.bats @@ -1,13 +1,15 @@ #!/usr/bin/env bats +setup() { + mkdir ${BATS_TMPDIR}/generate-python-test +} + teardown() { - rm -rf ${BATS_TMPDIR}/grammar - rm -rf ${BATS_TMPDIR}/Java - rm -rf ${BATS_TMPDIR}/Python + rm -rf ${BATS_TMPDIR}/generate-python-test } @test "Creates Python directory when 4th section detected." { - cat << EOF > "$BATS_TMPDIR/grammar" + cat << EOF > "$BATS_TMPDIR/generate-python-test/grammar" A 'A' B 'B' skip OTHER '.' @@ -18,8 +20,8 @@ skip OTHER '.' % EOF - RESULT="$(cd "$BATS_TMPDIR" && plccmk --json_ast grammar)" + RESULT="$(cd "$BATS_TMPDIR/generate-python-test" && plccmk --json_ast grammar)" echo "RESULT: $RESULT" - [[ -d $BATS_TMPDIR/Python ]] + [[ -d $BATS_TMPDIR/generate-python-test/Python ]] } diff --git a/tests/plcc/no-4th-section.bats b/tests/plcc/no-4th-section.bats index bd72afbd..b3892daf 100644 --- a/tests/plcc/no-4th-section.bats +++ b/tests/plcc/no-4th-section.bats @@ -1,12 +1,16 @@ #!/usr/bin/env bats +setup() { + mkdir ${BATS_TMPDIR}/no-4th-test +} + teardown() { - rm -rf ${BATS_TMPDIR}/grammar - rm -rf ${BATS_TMPDIR}/Java + cd ../../../.. + rm -rf ${BATS_TMPDIR}/no-4th-test } @test "Functions correctly when no 4th section exists." { - cat << EOF > "$BATS_TMPDIR/grammar" + cat << EOF > "$BATS_TMPDIR/no-4th-test/grammar" A 'A' B 'B' skip OTHER '.' @@ -16,8 +20,8 @@ skip OTHER '.' % EOF - RESULT="$(cd "$BATS_TMPDIR" && plccmk -c grammar)" + RESULT="$(cd "$BATS_TMPDIR/no-4th-test" && plccmk -c grammar)" echo "RESULT: $RESULT" - [[ ! -d $BATS_TMPDIR/Python ]] + [[ ! -d $BATS_TMPDIR/no-4th-test/Python ]] }