Skip to content

Commit

Permalink
finalize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reedeveris committed Apr 7, 2024
1 parent 56be1a9 commit ca65f2a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/plccmk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,7 +58,7 @@ then
done

(cd ./Java ; javac -cp ".:${CP}" *.java)
else
else
(cd ./Java ; javac *.java)
fi

21 changes: 10 additions & 11 deletions tests/plcc/compiles-4-section/compiles-4-section.bats
Original file line number Diff line number Diff line change
@@ -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 ]]
}
2 changes: 1 addition & 1 deletion tests/plcc/compiles-obj/compiles-obj.bats
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ teardown() {
echo "ERROR: $error"

# Assert success.
[ "$status" -eq 0 ]
[[ "$status" -eq 0 ]]
}
14 changes: 8 additions & 6 deletions tests/plcc/generate-python.bats
Original file line number Diff line number Diff line change
@@ -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 '.'
Expand All @@ -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 ]]
}
14 changes: 9 additions & 5 deletions tests/plcc/no-4th-section.bats
Original file line number Diff line number Diff line change
@@ -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 '.'
Expand All @@ -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 ]]
}

0 comments on commit ca65f2a

Please sign in to comment.