From 2e99cd056e7ebaad35b0eb34c1f776ab0fb46a74 Mon Sep 17 00:00:00 2001 From: ba1man <1152575283@qq.com> Date: Tue, 23 Jan 2024 09:06:14 +0800 Subject: [PATCH 1/3] update enre-java-test url && update testing scripts --- .gitmodules | 2 +- README.md | 15 +++++------ scripts/gen_tests.bat | 15 ----------- scripts/gen_tests.py | 50 +++++++++++++++++++++++++++++++++++++ scripts/gen_tests.sh | 27 -------------------- scripts/update_submodule.py | 14 +++++++++++ 6 files changed, 73 insertions(+), 50 deletions(-) delete mode 100644 scripts/gen_tests.bat create mode 100755 scripts/gen_tests.py delete mode 100755 scripts/gen_tests.sh create mode 100755 scripts/update_submodule.py diff --git a/.gitmodules b/.gitmodules index 195d956..48c7387 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "enre-java-test"] path = enre-java-test - url = git@github.com:ba1man/enre-java-test.git + url = git@github.com:xjtu-enre/enre-java-test.git diff --git a/README.md b/README.md index b1ed196..2056641 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ $java -jar enre_java.jar java ...\frameworks\base base -d ...\base ## Testing -### Prerequests +### Prerequisite * Node.js 16~18 @@ -113,17 +113,18 @@ $java -jar enre_java.jar java ...\frameworks\base base -d ...\base ENRE-java is integrated with [ENRE-test](https://github.com/xjtu-enre/enre-test). All you need to do for performing unit test is running the following script: +1. Fetch the latest enre-java-test codebase locally: + ```sh -./scripts/gen_tests.sh +python3 ./scripts/update_submodule.py ``` -or (In case you're using Windows platform): +2. Generate test cases and suites: -```cmd -scripts\gen_tests.bat +```sh +python3 ./scripts/gen_tests.py ``` - -Test cases and `JUnit` java files will be generated under directory `src/test/resources` and `src/test/java/client`. +Test cases and `JUnit` java files will be generated under directory `src/test/resources/cases` and `src/test/java/client`. you can execute all `JUnit` test cases by executing the following command in the project directory: diff --git a/scripts/gen_tests.bat b/scripts/gen_tests.bat deleted file mode 100644 index 8394d21..0000000 --- a/scripts/gen_tests.bat +++ /dev/null @@ -1,15 +0,0 @@ -@echo off - -SET ENRE_REPO=../ -SET TEST_REPO=%CD%\..\enre-java-test -git "submodule" "init" -git "submodule" "update" -pushd "%TEST_REPO%" && git "checkout" "main" && popd -IF "-d" "./%TEST_REPO%" ( - [ "-d" "./%TEST_REPO%/docs" "]" && DEL /S "./%TEST_REPO%/docs" - [ "-d" "./%TEST_REPO%/tests" "]" && DEL /S "./%TEST_REPO%/tests" - COPY "%ENRE_REPO%\docs" "%TEST_REPO%\docs" - [ "!" "-d" "%ENRE_REPO%/src/test/java/client" "]" && mkdir "-vp" "%ENRE_REPO%/src/test/java/client" - [ "!" "-d" "%ENRE_REPO%/src/test/resources" "]" && mkdir "-vp" "%ENRE_REPO%/src/test/resources" - pushd "%TEST_REPO%" && npm "install" && node "--experimental-specifier-resolution=node" "%TEST_REPO%/src/index.js" && popd && COPY "%TEST_REPO%/tests/suites/*.java" "%ENRE_REPO%/src/test/java/client/" && COPY "%TEST_REPO%/tests/cases" "%ENRE_REPO%/src/test/resources/" -) diff --git a/scripts/gen_tests.py b/scripts/gen_tests.py new file mode 100755 index 0000000..31f7d9b --- /dev/null +++ b/scripts/gen_tests.py @@ -0,0 +1,50 @@ +#! /usr/bin/env python3 + +import sys +import os +import shutil +import subprocess + +ENRE_REPO = os.getcwd() +TEST_REPO = os.path.join(ENRE_REPO, "enre-java-test") + +enre_paths = { + "docs": os.path.join(ENRE_REPO, "docs"), + "suites": os.path.join(ENRE_REPO, "src", "test", "java", "client"), + "cases": os.path.join(ENRE_REPO, "src", "test", "resources", "cases"), +} + +test_paths = { + "docs": os.path.join(TEST_REPO, "docs"), + "tests": os.path.join(TEST_REPO, "tests"), + "suites": os.path.join(TEST_REPO, "tests", "suites"), + "cases": os.path.join(TEST_REPO, "tests", "cases"), +} + +def preprocess(): + if os.path.isdir(test_paths["docs"]): + shutil.rmtree(test_paths["docs"]) + if os.path.isdir(test_paths["tests"]): + shutil.rmtree(test_paths["tests"]) + if os.path.isdir(enre_paths["suites"]): + shutil.rmtree(enre_paths["suites"]) + if os.path.isdir(enre_paths["cases"]): + shutil.rmtree(enre_paths["cases"]) + shutil.copytree(enre_paths["docs"], test_paths["docs"]) + os.makedirs(enre_paths["suites"], exist_ok=True) + # os.makedirs(enre_paths["cases"], exist_ok=True) + return + +def build(): + os.chdir(TEST_REPO) + subprocess.run(f"npm install; node --experimental-specifier-resolution=node {os.path.join('src', 'index.js')}", shell=True) + os.chdir(ENRE_REPO) + for file in os.listdir(test_paths["suites"]): + if not file.endswith(".java"): + continue + shutil.copy(os.path.join(test_paths["suites"], file), enre_paths["suites"]) + shutil.copytree(test_paths["cases"], enre_paths["cases"]) + +if __name__ == '__main__': + preprocess() + build() diff --git a/scripts/gen_tests.sh b/scripts/gen_tests.sh deleted file mode 100755 index 9f1423e..0000000 --- a/scripts/gen_tests.sh +++ /dev/null @@ -1,27 +0,0 @@ -#! /usr/bin/env bash - -ENRE_REPO="./" -TEST_REPO="./enre-java-test" - -git submodule init -git submodule update - -pushd $TEST_REPO && \ - git pull origin main && \ - git checkout main && \ - popd - -if [ -d "./$TEST_REPO" ]; then - [ -d "./$TEST_REPO/docs" ] && rm -rfv "./$TEST_REPO/docs" - [ -d "./$TEST_REPO/tests" ] && rm -rfv "./$TEST_REPO/tests" - cp -rv $ENRE_REPO/docs $TEST_REPO/docs - [ ! -d "$ENRE_REPO/src/test/java/client" ] && mkdir -vp "$ENRE_REPO/src/test/java/client" - [ ! -d "$ENRE_REPO/src/test/resources" ] && mkdir -vp "$ENRE_REPO/src/test/resources" - pushd "$TEST_REPO" && \ - npm install && \ - node --experimental-specifier-resolution=node "./src/index.js" && \ - popd && \ - cp -rv $TEST_REPO/tests/suites/*.java "$ENRE_REPO/src/test/java/client/" && \ - cp -rv "$TEST_REPO/tests/cases" "$ENRE_REPO/src/test/resources/" -fi - diff --git a/scripts/update_submodule.py b/scripts/update_submodule.py new file mode 100755 index 0000000..7b86774 --- /dev/null +++ b/scripts/update_submodule.py @@ -0,0 +1,14 @@ +#! /usr/bin/env python3 + +import subprocess +import os + +ENRE_REPO = os.getcwd() +TEST_REPO = "enre-java-test" + +subprocess.run(["git", "submodule", "init"]) +subprocess.run(["git", "submodule", "update"]) +os.chdir(TEST_REPO) +subprocess.run(["git", "pull", "origin", "main"]) +subprocess.run(["git", "checkout", "main"]) +os.chdir(ENRE_REPO) From c44a2eed19368e16bc5e50931c8cba6ffd80d348 Mon Sep 17 00:00:00 2001 From: ba1man <1152575283@qq.com> Date: Tue, 23 Jan 2024 09:09:00 +0800 Subject: [PATCH 2/3] update testing scripts --- scripts/gen_tests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/gen_tests.py b/scripts/gen_tests.py index 31f7d9b..b0a6028 100755 --- a/scripts/gen_tests.py +++ b/scripts/gen_tests.py @@ -37,7 +37,8 @@ def preprocess(): def build(): os.chdir(TEST_REPO) - subprocess.run(f"npm install; node --experimental-specifier-resolution=node {os.path.join('src', 'index.js')}", shell=True) + subprocess.run(["npm", "install"]) + subprocess.run(["node", "--experimental-specifier-resolution", "node", os.path.join("src", "index.js")]) os.chdir(ENRE_REPO) for file in os.listdir(test_paths["suites"]): if not file.endswith(".java"): From e5129176e884931f918bd61653a176ca233b27f7 Mon Sep 17 00:00:00 2001 From: ba1man <1152575283@qq.com> Date: Tue, 23 Jan 2024 14:31:36 +0800 Subject: [PATCH 3/3] update README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 2056641..50411b0 100644 --- a/README.md +++ b/README.md @@ -138,3 +138,9 @@ or execute specific test case by passing class name: mvn clean test -DTest=AClassDefinesAFieldTest ``` +If you want to build the package without executing any test case: + +```sh +mvn clean package assembly:single -DskipTests +``` +