Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ourPLCC/plcc into python
Browse files Browse the repository at this point in the history
  • Loading branch information
reedeveris committed Apr 11, 2024
2 parents 4c8ca89 + 460d1e7 commit 865bbfe
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-release-candidate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
uses: addnab/docker-run-action@v3
with:
image: test-image:latest
run: /plcc/tests/run
run: /plcc/bin/test/functionality.bash
2 changes: 1 addition & 1 deletion .github/workflows/test_python-3.5.10_Java-11.0.21-tem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ jobs:
python --version
java --version
javac --version
/home/tester/.plcc/tests/run
/home/tester/.plcc/bin/test/functionality.bash
shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/test_python-max_java-max.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ jobs:
python --version
java --version
javac --version
/home/tester/.plcc/tests/run
/home/tester/.plcc/bin/test/functionality.bash
shell: bash
14 changes: 12 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ tasks:
sudo apt-get --no-install-recommends install silversearcher-ag
echo ""
echo "INSTALLING bats (for testing: https://bats-core.readthedocs.io/en/latest/index.html)"
sudo apt-get update
sudo apt-get --no-install-recommends install bats
export BATS_VERSION=v1.11.0 \
&& sudo apt-get update \
&& sudo apt-get install -y \
git \
&& sudo apt-get clean \
&& sudo rm -rf /var/lib/apt/lists/* \
&& sudo git clone https://github.com/bats-core/bats-core.git \
&& cd bats-core \
&& sudo git checkout $BATS_VERSION \
&& sudo ./install.sh /usr/local \
&& cd .. \
&& sudo rm -rf bats-core
exec bash
25 changes: 23 additions & 2 deletions bin/test/functionality.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ set -euo pipefail

SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PROJECT_ROOT="$( cd "${SCRIPT_DIR}/../.." &> /dev/null && pwd )"
cd "${PROJECT_ROOT}"

tests/run

function run_local_tests() {
cd "${PROJECT_ROOT}"
tests/run.bash
}


function run_language_tests() {
LANGUAGES_VERSION="${LANGUAGES_VERSION:-}"
cd /tmp

rm -rf languages
git clone https://github.com/ourPLCC/languages.git
if [ -n "${LANGUAGES_VERSION}" ] ; then
git -C ./languages checkout "${LANGUAGES_VERSION}"
fi
languages/bin/test.bash
rm -rf languages
}


run_local_tests
run_language_tests
15 changes: 14 additions & 1 deletion containers/configurable/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,23 @@ RUN apt-get update \
build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev \
git curl bash zip sudo bats \
git curl bash zip sudo \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

ARG BATS_VERSION=v1.11.0
RUN apt-get update \
&& apt-get install -y \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& git clone https://github.com/bats-core/bats-core.git \
&& cd bats-core \
&& git checkout $BATS_VERSION \
&& ./install.sh /usr/local \
&& cd .. \
&& rm -rf bats-core

RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
Expand Down
16 changes: 2 additions & 14 deletions tests/plcc/can-print-json-ast/prints-json-ast.bats
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
#!/usr/bin/env bats

setup() {
mkdir ${BATS_TMPDIR}/json-test
}

teardown() {
cd ../..
rm -rf ${BATS_TMPDIR}/json-test
}
load '../../relocate_to_temp.bash'

@test "PLCC can print JSON AST." {
FILES="expected.json given-grammar.lang given-program.lang"
for f in $FILES ; do
cp -R "${BATS_TEST_DIRNAME}/${f}" "${BATS_TMPDIR}/json-test"
done

cd "${BATS_TMPDIR}/json-test"
relocate_to_temp
plccmk --json_ast given-grammar.lang
parse -n --json_ast < given-program.lang > result.json
diff expected.json result.json
Expand Down
25 changes: 4 additions & 21 deletions tests/plcc/compiles-obj/compiles-obj.bats
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
#!/usr/bin/env bats

setup() {
mkdir ${BATS_TMPDIR}/obj-test
}

teardown() {
cd ../../../..
rm -rf ${BATS_TMPDIR}/obj-test
}
load '../../relocate_to_temp.bash'

@test "PLCC compiles the OBJ language." {
# Copy the OBJ language to the temporary directory for this test
cp -R "${BATS_TEST_DIRNAME}/OBJ" "${BATS_TMPDIR}/obj-test"

# Change into the temporary OBJ directory.
cd "${BATS_TMPDIR}/obj-test/OBJ"

# Use plcc to generate the Java files from the OBJ grammar file.
plcc "grammar"

# Change into the generated Java file.
cd Java
relocate_to_temp

# Compile the Java files.
run javac *.java
cd OBJ
run plccmk grammar

# Print stdout and stderr for debugging.
echo "OUTPUT: $output"
Expand Down
14 changes: 5 additions & 9 deletions tests/plcc/detects-illegal-tokens.bats
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
#!/usr/bin/env bats

setup() {
mkdir ${BATS_TMPDIR}/illegal-tokens-test
}

teardown() {
rm -rf ${BATS_TMPDIR}/illegal-tokens-test
}
load '../relocate_to_temp.bash'

@test "PLCC detects illegal tokens." {
relocate_to_temp

# GIVEN a grammar file with a bad token name
cat << EOF > "${BATS_TMPDIR}/illegal-tokens-test/grammar"
cat << EOF > grammar
token bad_token_name '.'
EOF

# WHEN plcc is ran on that grammar file
run plcc "${BATS_TMPDIR}/illegal-tokens-test/grammar"
run plcc grammar

# print stdout and stderr for debugging
echo "OUTPUT: $output"
Expand Down
14 changes: 5 additions & 9 deletions tests/plcc/parses.bats
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#!/usr/bin/env bats

setup() {
mkdir ${BATS_TMPDIR}/parse-test
}

teardown() {
rm -rf ${BATS_TMPDIR}/parse-test
}
load '../relocate_to_temp.bash'

@test "PLCC parses." {
cat << EOF > "${BATS_TMPDIR}/parse-test/grammar"
relocate_to_temp

cat << EOF > grammar
A 'A'
B 'B'
skip OTHER '.'
Expand All @@ -18,7 +14,7 @@ skip OTHER '.'
<aaa> **= A
EOF

RESULT="$(cd "${BATS_TMPDIR}/parse-test" && plccmk -c grammar > /dev/null && echo "A asdf A fdsa A B" | parse -n)"
RESULT="$(plccmk -c grammar > /dev/null && echo "A asdf A fdsa A B" | parse -n)"

echo "RESULT: $RESULT"
[[ "$RESULT" =~ .*OK.* ]]
Expand Down
15 changes: 5 additions & 10 deletions tests/plcc/scans-tokens.bats
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#!/usr/bin/env bats

setup() {
mkdir ${BATS_TMPDIR}/scan-test
}

teardown() {
rm -rf ${BATS_TMPDIR}/scan-test
}
load '../relocate_to_temp.bash'

@test "PLCC scans." {
cat << EOF > "${BATS_TMPDIR}/scan-test/grammar"
relocate_to_temp

cat << EOF > grammar
skip WHITESPACE '\s'
token FOO 'foo'
token BAR 'bar'
Expand All @@ -19,8 +15,7 @@ EOF
IN="foo bar \n foobar"

TOKENS="$(
cd "${BATS_TMPDIR}/scan-test" &&
plccmk -c "grammar" &&
plccmk -c grammar &&
OUT="$(echo "$IN" | scan)" &&
echo "$OUT"
)"
Expand Down
4 changes: 4 additions & 0 deletions tests/relocate_to_temp.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function relocate_to_temp () {
cd "${BATS_TEST_TMPDIR}"
cp -R "${BATS_TEST_DIRNAME}/"* .
}
File renamed without changes.

0 comments on commit 865bbfe

Please sign in to comment.