Skip to content

Commit

Permalink
Merge pull request #59 from pecoose/main
Browse files Browse the repository at this point in the history
Update testing scripts and descriptions in README
  • Loading branch information
Lynn-Dai authored Mar 5, 2024
2 parents 132f2f5 + 89859eb commit 059b20d
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,26 @@ $java -jar enre_java.jar java ...\frameworks\base base -d ...\base

## Testing

### Prerequests
### Prerequisite

* Node.js 16~18

### Steps

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:

Expand All @@ -137,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
```

15 changes: 0 additions & 15 deletions scripts/gen_tests.bat

This file was deleted.

51 changes: 51 additions & 0 deletions scripts/gen_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#! /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(["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"):
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()
27 changes: 0 additions & 27 deletions scripts/gen_tests.sh

This file was deleted.

14 changes: 14 additions & 0 deletions scripts/update_submodule.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 059b20d

Please sign in to comment.