• Home
Name Date Size #Lines LOC

..--

testcase/12-May-2024-32,70128,014

README.mdD12-May-20244.9 KiB129106

README.zh-cn.mdD12-May-20244.6 KiB143107

ignorecase.json.exampleD12-May-202423 33

package.jsonD12-May-2024271 1514

run.jsD12-May-202413.6 KiB346305

run_test.pyD12-May-2024911 256

tsconfig.jsonD12-May-202420.3 KiB792791

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. Install project dependencies by running:
15    ```shell
16    npm install
17    ```
182. 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".
193. Run the "run.js" script to perform the code testing.
20
21    ```nodejs
22    node run.js
23    ```
24Run with a specified test case folder:
25
26```shell
27node run.js -P:.\testcase\arkts-identifiers-as-prop-names\  // You can modify the test case to the specified directory in the current path
28```
29To get more details,you can use the command:
30```shell
31node run.js --detail
32```
33Ignore a case directory or specific case:
34
35```shell
36node 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
37```
38Example of `ignorecase.json`:
39```json
40{
41    "ignoreCase":["testcase/arkts-identifiers-as-prop-names/xxxx.ets", "testcase/arkts-no-any-unknown"]
42}
43```
44Generate test result files:
45
46```shell
47node run.js -e
48```
494. The generated test results are stored in the "test_results" directory, and basic test information is printed on the command line, such as:
50
51```plain
52Total number of test cases:2 Number of use cases passed:1 The number of use cases that failed:1 Total running time:371ms
53Failed test cases:
54testcase/arkts-no-any-unknown/test2.ets
55```
56## Usage Instructions
57
58### Print details of failed test cases
59Support printing specific details of failed cases by using the `--detail` or `-D` command, such as:
60
61```shell
62node run.js -D
63```
64Return details of failed cases:
65
66```plain
67==> 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!
68Total number of test cases:2 Number of use cases passed:1 The number of use cases that failed:1 Total running time:371ms
69Failed test cases:
70testcase/arkts-no-any-unknown/test2.ets
71```
72
73
74### Block specific test cases
751. Support blocking test case directories or specific cases by using the --ignore-list parameter, such as:
76```shell
77# Ignore a single case
78node run.js --ignore-list:testcase/arkts-no-any-unknown/test2.ets
79```
80
81Return the test results:
82
83```
84Total number of test cases:44 Number of use cases passed:43 The number of use cases that failed:1 Total running time:6342ms
85Ignored test cases:
86testcase/arkts-no-any-unknown/test2.ets
87```
882. Ignore multiple cases, separated by commas (support blocking directories):
89```shell
90node run.js --ignore-list:testcase/arkts-no-any-unknown/test2.ets,testcase/arkts-identifiers-as-prop-names
91```
923. Support importing blocked cases through a configuration file:
93Rename the "ignorecase.json.example" file in the root directory to "ignorecase.json" and configure the "ignoreCase" field for blocked cases, such as:
94
95```json
96# ignorecase.json
97{
98"ignoreCase":["testcase/arkts-no-any-unknown/test2.ets","testcase/arkts-identifiers-as-prop-names"]
99}
100```
101Run the test case command:
102
103```shell
104node run.js -D
105```
106Running results:
107
108```plain
109// It can be observed that the configuration use case is properly masked
110Total number of test cases:0 Number of use cases passed:0 The number of use cases that failed:0 Total running time:342ms
111Ignored test cases:
112testcase/arkts-no-any-unknown/test2.ets
113testcase/arkts-identifiers-as-prop-names
114```
115#### Running Test Cases Script with Other Code
116Taking Python code as an example, refer to the file `run_test.py`:
117
118```python
119import subprocess
120
121p = subprocess.Popen("node run.js --detail", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
122out, err = p.communicate()
123print(out.decode('utf-8'), err.decode('utf-8'))
124
125return_code = p.returncode
126print(return_code)
127```
128If 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.
129

README.zh-cn.md

1# ArkTS语法约束规则集测试用例
2
3## 项目说明
4
5本项目旨在对[从TypeScript到ArkTS的适配规则](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/typescript-to-arkts-migration-guide.md)中的约束规则通过脚本方式进行验证并输出用例的测试结果报告。
6
7其中测试用例默认存放在`testcase`目录,运行结果存放在`test_results`目录。
8
9## 项目要求
10
111. 提供对ArkTS语法约束规则集的测试用例集
122. 框架能对用例集中的用例进行测试,并返回测试结果,成功/失败用例详情。并支持可选屏蔽用例
133. 用例集覆盖所有arkTS语法规则集,每条规则要有正例和反例覆盖,平均用例数不少于10个
14
15## 快速开始
16
171. 安装项目依赖,执行
18    ```shell
19    npm install
20    ```
212. 将测试用例放至 testcase 文件夹,建议使用约束名称作为测试用例目录,如`arkts-no-any-unknown`
223. 运行`run.js`,进行代码测试
23
24    ```nodejs
25    node run.js
26    ```
27
28    指定测试用例文件夹运行:
29
30    ```shell
31    node run.js -P:.\testcase\arkts-identifiers-as-prop-names\  // 可修改为当前路径下指定目录的测试用例
32    ```
33
34    打印详情:
35
36    ```shell
37    node run.js --detail
38    ```
39
40    屏蔽用例目录或具体用例:
41
42    ```shell
43    node run.js --ignore-list:testcase/arkts-identifiers-as-prop-names/case1.ets,testcase/arkts-no-any-unknown  # 通过--ignore-list指定或添加至 ignorecase.json
44    ```
45
46    `ignorecase.json`示例:
47
48    ```json
49    {
50        "ignoreCase":["testcase/arkts-identifiers-as-prop-names/xxxx.ets", "testcase/arkts-no-any-unknown"]
51    }
52    ```
53
54    生成测试结果文件:
55
56    ```shell
57    node run.js -e
58    ```
59
604. 生成的测试结果存放至 `test_results` 目录,命令行打印基本的测试信息,如:
61
62    ```plain
63    Total number of test cases:2 Number of use cases passed:1 The number of use cases that failed:1 Total running time:371ms
64    Failed test cases:
65    testcase/arkts-no-any-unknown/test2.ets
66    ```
67
68## 用法说明
69
70### 打印失败测试用例详情
71
72支持通过`--detail`或者`-D`指令打印具体失败用例细节,如运行指令:
73
74```shell
75node run.js -D
76```
77返回未通过用例详情:
78```plain
79==> 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!
80Total number of test cases:2 Number of use cases passed:1 The number of use cases that failed:1 Total running time:371ms
81Failed test cases:
82testcase/arkts-no-any-unknown/test2.ets
83```
84
85### 屏蔽指定测试用例
86
871. 支持使用 `--ignore-list` 参数传入屏蔽的用例目录或具体用例,如运行指令:
88
89```shell
90# 忽略单个用例
91node run.js --ignore-list:testcase/arkts-no-any-unknown/test2.ets
92```
93返回用例测试结果:
94```
95Total number of test cases:1 Number of use cases passed:1 The number of use cases that failed:0 Total running time:342ms
96Ignored test cases:
97testcase/arkts-no-any-unknown/test2.ets
98```
992. 忽略多个用例,请使用`,`分割输入(支持屏蔽目录)
100
101```shell
102node run.js --ignore-list:testcase/arkts-no-any-unknown/test2.ets,testcase/arkts-identifiers-as-prop-names
103```
1043. 支持通过配置文件导入屏蔽用例:
105
106修改根目录下的`ignorecase.json.example`为`ignorecase.json`,配置`ignoreCase`字段为屏蔽用例字段,如:
107```json
108# ignorecase.json
109{
110"ignoreCase":["testcase/arkts-no-any-unknown/test2.ets","testcase/arkts-identifiers-as-prop-names"]
111}
112```
113
114执行测试用例指令:
115
116```shell
117node run.js -D
118```
119运行结果:
120```plain
121// It can be observed that the configuration use case is properly masked
122Total number of test cases:0 Number of use cases passed:0 The number of use cases that failed:0 Total running time:342ms
123Ignored test cases:
124testcase/arkts-no-any-unknown/test2.ets
125testcase/arkts-identifiers-as-prop-names
126```
127
128### 使用其他代码运行测试用例脚本
129
130以`Python`代码为例,参考文件`run_test.py`:
131```python
132import subprocess
133
134p = subprocess.Popen("node run.js --detail", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
135out, err = p.communicate()
136print(out.decode('utf-8'), err.decode('utf-8'))
137
138# 获取返回值
139return_code = p.returncode
140print(return_code)
141```
142预期如果有用例不通过,则抛出异常状态码为`1`,如果用例全部通过,则返回正确状态码为`0`。
143