107ac75b1Sopenharmony_ci# compiler unit testing 207ac75b1Sopenharmony_ci 307ac75b1Sopenharmony_ci**The compiler unit testing for ace2.0.** 407ac75b1Sopenharmony_ci 507ac75b1Sopenharmony_ci## Usage 607ac75b1Sopenharmony_ciHere are simplified instructions of how to get started. The following commands work both on **Windows** and **Linux** platforms. 707ac75b1Sopenharmony_ci 807ac75b1Sopenharmony_ci### 1. Install 907ac75b1Sopenharmony_ciFirst, enter the root directory of the compiler: 1007ac75b1Sopenharmony_ci``` 1107ac75b1Sopenharmony_ci$ cd compiler/ 1207ac75b1Sopenharmony_ci``` 1307ac75b1Sopenharmony_ciAnd then install the npm dependencies(You must have node&npm installed): 1407ac75b1Sopenharmony_ci``` 1507ac75b1Sopenharmony_ci$ npm install 1607ac75b1Sopenharmony_ci``` 1707ac75b1Sopenharmony_ci**Note**: If some errors occur, delete the generated package `node_modules`, config npm proxy and run `npm install` again. 1807ac75b1Sopenharmony_ci``` 1907ac75b1Sopenharmony_cinpm config set proxy http://username:password@server:port 2007ac75b1Sopenharmony_cinpm confit set https-proxy http://username:password@server:port 2107ac75b1Sopenharmony_ci``` 2207ac75b1Sopenharmony_ci 2307ac75b1Sopenharmony_ci### 2. Quick Start 2407ac75b1Sopenharmony_ciFirst, create a new test file or directory in `compiler/test`. 2507ac75b1Sopenharmony_ciWrite source code in variable 'source', and write expected code in variable 'expectResult': 2607ac75b1Sopenharmony_ci``` 2707ac75b1Sopenharmony_ci// source code 2807ac75b1Sopenharmony_ciexport const source: string = `...` 2907ac75b1Sopenharmony_ci// expected code 3007ac75b1Sopenharmony_ciexport const expectResult: string = `...` 3107ac75b1Sopenharmony_ci``` 3207ac75b1Sopenharmony_ciIn the root directory of `compiler/`: 3307ac75b1Sopenharmony_ci``` 3407ac75b1Sopenharmony_ci$ npm run test 3507ac75b1Sopenharmony_ci``` 3607ac75b1Sopenharmony_ciAll files in the `compiler/test` will be tested. 3707ac75b1Sopenharmony_ci 3807ac75b1Sopenharmony_ci### 3. Example 3907ac75b1Sopenharmony_ci1. Create a new test directory `foo` in `compiler`. 4007ac75b1Sopenharmony_ci2. Create a new test file `bar.ts` in `compiler/foo`. 4107ac75b1Sopenharmony_ci3. In the file `bar.ts`, write the following lines: 4207ac75b1Sopenharmony_ci``` 4307ac75b1Sopenharmony_ciexport const source: string = ` 4407ac75b1Sopenharmony_cistruct MyComponent { 4507ac75b1Sopenharmony_ci build() { 4607ac75b1Sopenharmony_ci } 4707ac75b1Sopenharmony_ci}` 4807ac75b1Sopenharmony_ci 4907ac75b1Sopenharmony_ciexport const expectResult: string = 5007ac75b1Sopenharmony_ci`class MyComponent { 5107ac75b1Sopenharmony_ci build() { 5207ac75b1Sopenharmony_ci } 5307ac75b1Sopenharmony_ci} 5407ac75b1Sopenharmony_ci` 5507ac75b1Sopenharmony_ci``` 5607ac75b1Sopenharmony_ci4. In the root directory of `compiler/`: 5707ac75b1Sopenharmony_ci``` 5807ac75b1Sopenharmony_ci$ npm run test 5907ac75b1Sopenharmony_ci``` 6007ac75b1Sopenharmony_ci5. All files in the `compiler/test` will be tested. The output is like the following lines: 6107ac75b1Sopenharmony_ci``` 6207ac75b1Sopenharmony_ci ✓ bar 6307ac75b1Sopenharmony_ci 1 passing (1ms) 6407ac75b1Sopenharmony_ci``` 6507ac75b1Sopenharmony_ci**Note**: If the actual building result is different from the expected result and the output is like the following lines, you should check the error: 6607ac75b1Sopenharmony_ci``` 6707ac75b1Sopenharmony_ci 1) bar 6807ac75b1Sopenharmony_ci 6907ac75b1Sopenharmony_ci 0 passing (1ms) 7007ac75b1Sopenharmony_ci 1 failing 7107ac75b1Sopenharmony_ci 7207ac75b1Sopenharmony_ci 1) compiler 7307ac75b1Sopenharmony_ci bar: 7407ac75b1Sopenharmony_ci 7507ac75b1Sopenharmony_ci AssertionError: expected 'class MyComponent {\n build() {\n }\n}\n' to deeply equal 'class MyComponent {\n build() {\n \n}\n' 7607ac75b1Sopenharmony_ci + expected - actual 7707ac75b1Sopenharmony_ci 7807ac75b1Sopenharmony_ci class MyComponent { 7907ac75b1Sopenharmony_ci build() { 8007ac75b1Sopenharmony_ci - } 8107ac75b1Sopenharmony_ci + 8207ac75b1Sopenharmony_ci } 8307ac75b1Sopenharmony_ci``` 84