From fe08748f4e98afe7d419cb29b105cfc4633f1b1e Mon Sep 17 00:00:00 2001 From: Stoney Jackson Date: Wed, 1 May 2024 00:08:54 +0000 Subject: [PATCH] build: prepare to unit test Adopt Technologies: * PDM - "A modern Python package and dependency manager supporting the latest PEP standards." * pyproject.toml - Used by PDM to manage project dependencies and metadata. * pytest - A nice modern unit testing framework for python. Reorganized tests, and removed local-min-max test. They were breaking and are VERY slow. They were intended to mimic those that run in CI. But those are passing. Added bin/test/units.bash to run unit tests. Place unit tests in tests/unit/. No longer supporting python < 3.9. --- Related to #119 Closes #131 Thanks to Co-authored-by: Akshar Patel He performed the initial research for pyproject.toml --- ... test_python-3.9.19_Java-11.0.21-tem.yaml} | 6 +- .gitignore | 3 + .gitpod.yml | 5 + README.md | 6 +- bin/test/units.bash | 9 ++ pdm.lock | 96 +++++++++++++++++++ pyproject.toml | 34 +++++++ tests/__init__.py | 0 .../parse/parses/given-grammar.plcc | 0 .../parse/parses/given-program.lang | 0 .../{ => end-to-end}/parse/parses/parses.bats | 0 .../parse/print-json-ast/expected.json | 0 .../parse/print-json-ast/given-grammar.lang | 0 .../parse/print-json-ast/given-program.lang | 0 .../parse/print-json-ast/prints-json-ast.bats | 0 ...tion-grammar-does-not-generate-python.bats | 0 .../4-section-grammar-generates-python.bats | 0 .../plcc/detects-illegal-tokens.bats | 0 .../plcc/reports-version-number.bats | 0 tests/{ => end-to-end}/relocate_to_temp.bash | 0 tests/{ => end-to-end}/scan/scans-tokens.bats | 0 tests/local-min-max-test/README.md | 25 ----- tests/local-min-max-test/run.bash | 41 -------- tests/unit/__init__.py | 0 24 files changed, 153 insertions(+), 72 deletions(-) rename .github/workflows/{test_python-3.5.10_Java-11.0.21-tem.yaml => test_python-3.9.19_Java-11.0.21-tem.yaml} (87%) create mode 100755 bin/test/units.bash create mode 100644 pdm.lock create mode 100644 pyproject.toml create mode 100644 tests/__init__.py rename tests/{ => end-to-end}/parse/parses/given-grammar.plcc (100%) rename tests/{ => end-to-end}/parse/parses/given-program.lang (100%) rename tests/{ => end-to-end}/parse/parses/parses.bats (100%) rename tests/{ => end-to-end}/parse/print-json-ast/expected.json (100%) rename tests/{ => end-to-end}/parse/print-json-ast/given-grammar.lang (100%) rename tests/{ => end-to-end}/parse/print-json-ast/given-program.lang (100%) rename tests/{ => end-to-end}/parse/print-json-ast/prints-json-ast.bats (100%) rename tests/{ => end-to-end}/plcc/3-section-grammar-does-not-generate-python.bats (100%) rename tests/{ => end-to-end}/plcc/4-section-grammar-generates-python.bats (100%) rename tests/{ => end-to-end}/plcc/detects-illegal-tokens.bats (100%) rename tests/{ => end-to-end}/plcc/reports-version-number.bats (100%) rename tests/{ => end-to-end}/relocate_to_temp.bash (100%) rename tests/{ => end-to-end}/scan/scans-tokens.bats (100%) delete mode 100644 tests/local-min-max-test/README.md delete mode 100755 tests/local-min-max-test/run.bash create mode 100644 tests/unit/__init__.py diff --git a/.github/workflows/test_python-3.5.10_Java-11.0.21-tem.yaml b/.github/workflows/test_python-3.9.19_Java-11.0.21-tem.yaml similarity index 87% rename from .github/workflows/test_python-3.5.10_Java-11.0.21-tem.yaml rename to .github/workflows/test_python-3.9.19_Java-11.0.21-tem.yaml index e30bff2f..da7785ac 100644 --- a/.github/workflows/test_python-3.5.10_Java-11.0.21-tem.yaml +++ b/.github/workflows/test_python-3.9.19_Java-11.0.21-tem.yaml @@ -1,12 +1,12 @@ --- -name: test_python-3.5.10_Java-11.0.21-tem +name: test_python-3.9.19_Java-11.0.21-tem on: pull_request: jobs: build: - name: test_python-3.5.10_Java-11.0.21-tem + name: test_python-3.9.19_Java-11.0.21-tem runs-on: ubuntu-latest steps: - @@ -22,7 +22,7 @@ jobs: push: false build-args: | JAVA_VERSION=11.0.21-tem - PYTHON_VERSION=3.5.10 + PYTHON_VERSION=3.9.19 - name: Test uses: addnab/docker-run-action@v3 diff --git a/.gitignore b/.gitignore index bbebfa4b..20396fb3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# See https://pdm-project.org/latest/usage/project/#working-with-version-control +.pdm-python + # This is created by bin/test/languages.bash. But should not be committed. languages/ diff --git a/.gitpod.yml b/.gitpod.yml index 6d057627..d6cf8d53 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -32,4 +32,9 @@ tasks: && sudo ./install.sh /usr/local \ && cd .. \ && sudo rm -rf bats-core + echo "" + echo "INSTALLING PDM" + curl -sSL https://pdm-project.org/install-pdm.py | python3 - + echo "export PATH=/workspace/.pyenv_mirror/user/current/bin:\$PATH" >> ~/.bashrc exec bash + pdm install diff --git a/README.md b/README.md index c645a456..b58a0b12 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Related repositories: - [ourPLCC/languages](https://github.com/ourPLCC/languages): Languages implemented in PLCC. - [ourPLCC/course](https://github.com/ourPLCC/course): Course materials for - teaching a Programming Languages course that uses PLCC. + teaching a Programming Languages course the uses PLCC. ## Options for Installation and Use @@ -24,7 +24,7 @@ may help you determine which option is best for you and your class. | ------ | ------------------- | ----------------------- | ---------- | | GitPod | Web Browser | * Account on GitPod
* Account on hosting service (GitLab/GitHub/Bitbucket)
* Knowledge of above and Git | Yes | | Docker | Docker Desktop | Minimal understanding of Docker | Yes | -| Native | * Bash/Linux-like environment
* Java >= 11
* Python >= 3.5 | System administration knowledge | No | +| Native | * Bash/Linux-like environment
* Java >= 11
* Python >= 3.9 | System administration knowledge | No | The advantages of GitPod or Docker are (1) few or no software dependencies and (2) the ability to provide your class/developers a consistent development @@ -141,7 +141,7 @@ and use it to install Java. ### Install Python -Check if you have Python >= 3.5 +Check if you have Python >= 3.9 ```bash python3 --version diff --git a/bin/test/units.bash b/bin/test/units.bash new file mode 100755 index 00000000..ae8d5995 --- /dev/null +++ b/bin/test/units.bash @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +PROJECT_ROOT="$( cd "${SCRIPT_DIR}/../.." &> /dev/null && pwd )" + +pdm install +pdm test diff --git a/pdm.lock b/pdm.lock new file mode 100644 index 00000000..35d55146 --- /dev/null +++ b/pdm.lock @@ -0,0 +1,96 @@ +# This file is @generated by PDM. +# It is not intended for manual editing. + +[metadata] +groups = ["default", "dev"] +strategy = ["cross_platform", "inherit_metadata"] +lock_version = "4.4.1" +content_hash = "sha256:9cbdf5f4062678ffa98b0311c1562499ee0587cfd6cdc96d211e8d735bbd4263" + +[[package]] +name = "colorama" +version = "0.4.6" +requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +summary = "Cross-platform colored terminal text." +groups = ["dev"] +marker = "sys_platform == \"win32\"" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "exceptiongroup" +version = "1.2.1" +requires_python = ">=3.7" +summary = "Backport of PEP 654 (exception groups)" +groups = ["dev"] +marker = "python_version < \"3.11\"" +files = [ + {file = "exceptiongroup-1.2.1-py3-none-any.whl", hash = "sha256:5258b9ed329c5bbdd31a309f53cbfb0b155341807f6ff7606a1e801a891b29ad"}, + {file = "exceptiongroup-1.2.1.tar.gz", hash = "sha256:a4785e48b045528f5bfe627b6ad554ff32def154f42372786903b7abcfe1aa16"}, +] + +[[package]] +name = "iniconfig" +version = "2.0.0" +requires_python = ">=3.7" +summary = "brain-dead simple config-ini parsing" +groups = ["dev"] +files = [ + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, +] + +[[package]] +name = "packaging" +version = "24.0" +requires_python = ">=3.7" +summary = "Core utilities for Python packages" +groups = ["dev"] +files = [ + {file = "packaging-24.0-py3-none-any.whl", hash = "sha256:2ddfb553fdf02fb784c234c7ba6ccc288296ceabec964ad2eae3777778130bc5"}, + {file = "packaging-24.0.tar.gz", hash = "sha256:eb82c5e3e56209074766e6885bb04b8c38a0c015d0a30036ebe7ece34c9989e9"}, +] + +[[package]] +name = "pluggy" +version = "1.5.0" +requires_python = ">=3.8" +summary = "plugin and hook calling mechanisms for python" +groups = ["dev"] +files = [ + {file = "pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669"}, + {file = "pluggy-1.5.0.tar.gz", hash = "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1"}, +] + +[[package]] +name = "pytest" +version = "8.2.0" +requires_python = ">=3.8" +summary = "pytest: simple powerful testing with Python" +groups = ["dev"] +dependencies = [ + "colorama; sys_platform == \"win32\"", + "exceptiongroup>=1.0.0rc8; python_version < \"3.11\"", + "iniconfig", + "packaging", + "pluggy<2.0,>=1.5", + "tomli>=1; python_version < \"3.11\"", +] +files = [ + {file = "pytest-8.2.0-py3-none-any.whl", hash = "sha256:1733f0620f6cda4095bbf0d9ff8022486e91892245bb9e7d5542c018f612f233"}, + {file = "pytest-8.2.0.tar.gz", hash = "sha256:d507d4482197eac0ba2bae2e9babf0672eb333017bcedaa5fb1a3d42c1174b3f"}, +] + +[[package]] +name = "tomli" +version = "2.0.1" +requires_python = ">=3.7" +summary = "A lil' TOML parser" +groups = ["dev"] +marker = "python_version < \"3.11\"" +files = [ + {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, + {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, +] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..1d61bf96 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,34 @@ +[project] +name = "plcc" +version = "8.0.0" +description = "Programming Languages Compiler Compiler" +authors = [ + {name = "Tim Fossum", email = "fossum@halsum.org"}, + {name = "Stoney Jackson", email = "dr.stoney@gmail.com"} +] +dependencies = [] +requires-python = ">=3.9" +readme = "README.md" +license = {text = "GPL-3.0-or-later"} + + +[project.scripts] +plcc = "plcc.__main__:main" + + +[build-system] +requires = ["pdm-backend"] +build-backend = "pdm.backend" + + +[tool.pdm] +distribution = true + + +[tool.pdm.dev-dependencies] +dev = [ + "pytest>=8.2.0", +] + +[tool.pdm.scripts] +test = "pytest" diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/parse/parses/given-grammar.plcc b/tests/end-to-end/parse/parses/given-grammar.plcc similarity index 100% rename from tests/parse/parses/given-grammar.plcc rename to tests/end-to-end/parse/parses/given-grammar.plcc diff --git a/tests/parse/parses/given-program.lang b/tests/end-to-end/parse/parses/given-program.lang similarity index 100% rename from tests/parse/parses/given-program.lang rename to tests/end-to-end/parse/parses/given-program.lang diff --git a/tests/parse/parses/parses.bats b/tests/end-to-end/parse/parses/parses.bats similarity index 100% rename from tests/parse/parses/parses.bats rename to tests/end-to-end/parse/parses/parses.bats diff --git a/tests/parse/print-json-ast/expected.json b/tests/end-to-end/parse/print-json-ast/expected.json similarity index 100% rename from tests/parse/print-json-ast/expected.json rename to tests/end-to-end/parse/print-json-ast/expected.json diff --git a/tests/parse/print-json-ast/given-grammar.lang b/tests/end-to-end/parse/print-json-ast/given-grammar.lang similarity index 100% rename from tests/parse/print-json-ast/given-grammar.lang rename to tests/end-to-end/parse/print-json-ast/given-grammar.lang diff --git a/tests/parse/print-json-ast/given-program.lang b/tests/end-to-end/parse/print-json-ast/given-program.lang similarity index 100% rename from tests/parse/print-json-ast/given-program.lang rename to tests/end-to-end/parse/print-json-ast/given-program.lang diff --git a/tests/parse/print-json-ast/prints-json-ast.bats b/tests/end-to-end/parse/print-json-ast/prints-json-ast.bats similarity index 100% rename from tests/parse/print-json-ast/prints-json-ast.bats rename to tests/end-to-end/parse/print-json-ast/prints-json-ast.bats diff --git a/tests/plcc/3-section-grammar-does-not-generate-python.bats b/tests/end-to-end/plcc/3-section-grammar-does-not-generate-python.bats similarity index 100% rename from tests/plcc/3-section-grammar-does-not-generate-python.bats rename to tests/end-to-end/plcc/3-section-grammar-does-not-generate-python.bats diff --git a/tests/plcc/4-section-grammar-generates-python.bats b/tests/end-to-end/plcc/4-section-grammar-generates-python.bats similarity index 100% rename from tests/plcc/4-section-grammar-generates-python.bats rename to tests/end-to-end/plcc/4-section-grammar-generates-python.bats diff --git a/tests/plcc/detects-illegal-tokens.bats b/tests/end-to-end/plcc/detects-illegal-tokens.bats similarity index 100% rename from tests/plcc/detects-illegal-tokens.bats rename to tests/end-to-end/plcc/detects-illegal-tokens.bats diff --git a/tests/plcc/reports-version-number.bats b/tests/end-to-end/plcc/reports-version-number.bats similarity index 100% rename from tests/plcc/reports-version-number.bats rename to tests/end-to-end/plcc/reports-version-number.bats diff --git a/tests/relocate_to_temp.bash b/tests/end-to-end/relocate_to_temp.bash similarity index 100% rename from tests/relocate_to_temp.bash rename to tests/end-to-end/relocate_to_temp.bash diff --git a/tests/scan/scans-tokens.bats b/tests/end-to-end/scan/scans-tokens.bats similarity index 100% rename from tests/scan/scans-tokens.bats rename to tests/end-to-end/scan/scans-tokens.bats diff --git a/tests/local-min-max-test/README.md b/tests/local-min-max-test/README.md deleted file mode 100644 index 44986964..00000000 --- a/tests/local-min-max-test/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Min Max Test - -The min-max test was originally designed to run in CI/CD on GitHub. -See `./.github/workflows/test_python-*.yml` files. The files in this -directory allows developers to run an equivalent test locally. - -## Overview - -Test PLCC using the supported minimum and maximum versions of Python and Java. -The maximum supported versions are the latest, stable releases. -The minimum supported versions are currently: - -* Python: 3.5.10 (as identified with pyenv) -* Java: 11.0.21-tem (as identified with sdkman) - -## Requirements - -* Bash -* Docker - -## Run the tests - -```bash -./run.bash -``` diff --git a/tests/local-min-max-test/run.bash b/tests/local-min-max-test/run.bash deleted file mode 100755 index d74ae757..00000000 --- a/tests/local-min-max-test/run.bash +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash - -SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -PROJECT_ROOT="$SCRIPT_DIR/../.." -cd "$PROJECT_ROOT" - -function main() { - build_test_container_with_maximum_versions_of_python_and_java - run_tests_in_test_container - build_test_container_with_minimum_versions_of_python_and_java - run_tests_in_test_container -} - -function build_test_container_with_maximum_versions_of_python_and_java() { - docker build \ - --tag test \ - --file ./containers/configurable/Dockerfile \ - . -} - -function build_test_container_with_minimum_versions_of_python_and_java() { - docker build \ - --build-arg=PYTHON_VERSION=3.5.10 \ - --build-arg=JAVA_VERSION=11.0.21-tem \ - --tag test \ - --file ./containers/configurable/Dockerfile \ - . -} - -function run_tests_in_test_container() { - docker run -it --rm test bash -c '\ - source /home/tester/.sdkman/bin/sdkman-init.sh ; \ - python3 --version ; \ - python --version ; \ - java --version ; \ - javac --version ; \ - plcc --version ; \ - /home/tester/.plcc/tests/run' -} - -main "$@" diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 00000000..e69de29b