Name Date Size

..25-Oct-20244 KiB

ignorecase.jsonH A D25-Oct-20244 KiB

ignorecase.json.exampleH A D25-Oct-202423

package.jsonH A D25-Oct-2024282

README.mdH A D25-Oct-20245.2 KiB

README.zh-cn.mdH A D25-Oct-20245 KiB

run.jsH A D25-Oct-202415.8 KiB

run_test.pyH A D25-Oct-2024912

testcase/H25-Oct-20244 KiB

tsconfig.jsonH A D25-Oct-202420.6 KiB

README.md

1# ArkTS Syntax Constraint Rule Set Test Cases
2## Project Description
3This project aims to validate the constraint rules in [TypeScript to ArkTS Cookbook](https://gitee.com/openharmony/docs/blob/master/en/application-dev/quick-start/typescript-to-arkts-migration-guide.md) by script and output the test result report of the cases.
4
5The test cases are stored in the default directory called "testcase", and the results are stored in the "test_results" directory.
6
7## Project Requirements
81. Provide a test case set for the ArkTS syntax constraint rule set. 
92. The framework should be able to test the cases in the test case set and return the test results, including details of successful and failed cases. It should also support optional case blocking. 
103. The test case set should cover all the ArkTS syntax rule sets, with at least 10 cases for each rule, including positive and negative examples.
11
12## Getting Started
13
141. compile build typescript lib(pwd:third_party_typescript)
15    ```shell
16    npm install
17    npm run build
18    npm run release
19    npm pack
20    ```
21    must run this step everytime if you change your code.
22
232. Install project dependencies by running(pwd:third_party_typescript/tests/arkTSTest):
24    ```shell
25    rm -r ./node_modules/ ./package-lock.json # must run everytime
26    npm install # must run everytime
27    ``` 
283. Place the test cases in the "testcase" folder. It is recommended to use the constraint name as the test case directory, such as "arkts-no-any-unknown".
294. Run the "run.js" script to perform the code testing.
30
31    ```nodejs
32    node run.js -v1.0
33    node run.js -v1.1
34    ```
35Run with a specified test case folder:
36
37```shell
38node run.js -P:testcase/arkts-identifiers-as-prop-names  // You can modify the test case to the specified directory in the current path
39```
40To get more details,you can use the command:
41```shell
42node run.js --detail
43```
44Ignore a case directory or specific case:
45
46```shell
47node run.js --ignore-list:testcase/arkts-identifiers-as-prop-names/case1.ets,testcase/arkts-no-any-unknown  # Specify via --ignore-list or add to ignorecase.json 
48```
49Example of `ignorecase.json`:
50```json
51{
52    "ignoreCase":["testcase/arkts-identifiers-as-prop-names/xxxx.ets", "testcase/arkts-no-any-unknown"]
53}
54```
55Generate test result files:
56
57```shell
58node run.js -e
59```
605. The generated test results are stored in the "test_results" directory, and basic test information is printed on the command line, such as:
61
62```plain
63Total number of test cases:2 Number of use cases passed:1 The number of use cases that failed:1 Total running time:371ms
64Failed test cases:
65testcase/arkts-no-any-unknown/test2.ets
66```
67## Usage Instructions
68
69### Print details of failed test cases
70Support printing specific details of failed cases by using the `--detail` or `-D` command, such as:
71
72```shell
73node run.js -D
74```
75Return details of failed cases:
76
77```plain
78==> Expect the error in Line null The null character. Expect exception rules:null  Actual error line 20  The 7character. Actual exception rules:Use explicit types instead of "any", "unknown" (arkts-no-any-unknown) Comparison Result:Fail!
79Total number of test cases:2 Number of use cases passed:1 The number of use cases that failed:1 Total running time:371ms
80Failed test cases:
81testcase/arkts-no-any-unknown/test2.ets
82```
83
84
85### Block specific test cases
861. Support blocking test case directories or specific cases by using the --ignore-list parameter, such as:
87```shell
88# Ignore a single case
89node run.js --ignore-list:testcase/arkts-no-any-unknown/test2.ets 
90```
91
92Return the test results:
93
94```
95Total number of test cases:44 Number of use cases passed:43 The number of use cases that failed:1 Total running time:6342ms
96Ignored test cases:
97testcase/arkts-no-any-unknown/test2.ets
98```
992. Ignore multiple cases, separated by commas (support blocking directories):
100```shell
101node run.js --ignore-list:testcase/arkts-no-any-unknown/test2.ets,testcase/arkts-identifiers-as-prop-names
102```
1033. Support importing blocked cases through a configuration file:
104Rename the "ignorecase.json.example" file in the root directory to "ignorecase.json" and configure the "ignoreCase" field for blocked cases, such as:
105
106```json
107# ignorecase.json
108{
109"ignoreCase":["testcase/arkts-no-any-unknown/test2.ets","testcase/arkts-identifiers-as-prop-names"]
110}
111```
112Run the test case command:
113
114```shell
115node run.js -D
116```
117Running results:
118
119```plain
120// It can be observed that the configuration use case is properly masked
121Total number of test cases:0 Number of use cases passed:0 The number of use cases that failed:0 Total running time:342ms
122Ignored test cases:
123testcase/arkts-no-any-unknown/test2.ets
124testcase/arkts-identifiers-as-prop-names
125```
126#### Running Test Cases Script with Other Code
127Taking Python code as an example, refer to the file `run_test.py`:
128
129```python
130import subprocess
131
132p = subprocess.Popen("node run.js --detail", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
133out, err = p.communicate()
134print(out.decode('utf-8'), err.decode('utf-8'))
135
136return_code = p.returncode
137print(return_code)
138```
139If there are any failed cases, an exception with the status code 1 will be thrown. If all cases pass, the correct status code 0 will be returned.
140