Skip to content

Commit 651fec0

Browse files
committed
fix: proper handling of situations where AS files are not invalid
1 parent a53faaf commit 651fec0

File tree

12 files changed

+94
-17
lines changed

12 files changed

+94
-17
lines changed

bin/cli.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ const configPath = resolve(".", options.config);
3232
if (!fs.pathExistsSync(configPath)) {
3333
console.error(chalk.redBright("Miss config file") + "\n");
3434
console.error(program.helpInformation());
35-
exit(-1);
35+
exit(3);
3636
}
3737
const config = (await import(pathToFileURL(configPath))).default;
3838

3939
const includes = config.include;
4040
if (includes === undefined) {
4141
console.error(chalk.redBright("Miss include in config file") + "\n");
42-
exit(-1);
42+
exit(3);
4343
}
4444
const excludes = config.exclude || [];
4545
validateArgument(includes, excludes);
@@ -83,7 +83,7 @@ start_unit_test(testOption)
8383
.then((success) => {
8484
if (!success) {
8585
console.error(chalk.redBright("Test Failed") + "\n");
86-
exit(255);
86+
exit(1);
8787
}
8888
})
8989
.catch((e) => {

docs/.vitepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default defineConfig({
3434
{ text: "Matchers", link: "/api-documents/matchers" },
3535
{ text: "Mock Function", link: "/api-documents/mock-function" },
3636
{ text: "Report", link: "/api-documents/coverage-report" },
37+
{ text: "Return Code", link: "/api-documents/return-code.md" },
3738
],
3839
},
3940
{

docs/api-documents/return-code.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Return Code
2+
3+
The platform indicates different error situations by returning different exit codes.
4+
5+
- exit code 1 indicates a test failure.
6+
- exit code 2 indicates that the input AS file cannot be compiled.
7+
- exit code 3 or higher indicates an error in the configuration file.

docs/release-note.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Release Note
22

3+
## 1.3.1
4+
5+
🚀 Highlight Features
6+
7+
- Defined the meanings of the return values in different situations.
8+
- `0` means success.
9+
- `1` means test failed.
10+
- `2` means invalid AS file.
11+
- `>2` means configuration error.
12+
13+
🚀 Improvements
14+
15+
- Proper handling of situations where AS files are not invalid.
16+
317
## 1.3.0
418

519
🚀 Highlight Features
@@ -13,7 +27,7 @@
1327
- Expose the framework's `log` function in the configuration file, and the logs redirected to this function will be appended to the final test report.
1428
- Support test crashes and provide good call stack information.
1529

16-
Improvements
30+
🚀 Improvements
1731

1832
- Code coverage calculation.
1933
- Skip type definitions.

src/core/compile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export async function compile(testCodePaths: string[], outputFolder: string, com
2828
const { error, stderr } = await main(ascArgv);
2929
if (error) {
3030
// eslint-disable-next-line @typescript-eslint/no-base-to-string
31-
console.error(stderr.toString());
32-
throw error;
31+
console.log(stderr.toString());
32+
process.exit(2);
3333
}
3434
};
3535

src/core/precompile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ async function transform(transformFunction: string, codePath: string, flags: str
9494
const { error, stderr } = await main(ascArgv);
9595
if (error) {
9696
// eslint-disable-next-line @typescript-eslint/no-base-to-string
97-
console.error(stderr.toString());
98-
throw error;
97+
console.log(stderr.toString());
98+
process.exit(2);
9999
}
100100
collectCallback();
101101
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import path from "node:path";
2+
3+
const __dirname = path.dirname(new URL(import.meta.url).pathname);
4+
5+
export default {
6+
include: [__dirname],
7+
imports(runtime) {
8+
return {
9+
env: {
10+
log: (msg) => {
11+
runtime.framework.log(runtime.exports.__getString(msg));
12+
},
13+
},
14+
};
15+
},
16+
temp: path.join(__dirname, "tmp"),
17+
output: path.join(__dirname, "tmp"),
18+
mode: [],
19+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test, expect } from "../../../assembly";
2+
3+
test("assert on test", () => {
4+
f = 1;
5+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
code analysis: OK
2+
ERROR TS2304: Cannot find name 'f'.
3+
:
4+
4 │ f = 1;
5+
│ ~
6+
└─ in tests/e2e/compilationFailed/incorrect.test.ts(4,3)
7+
8+
FAILURE 1 compile error(s)
9+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "assemblyscript/std/assembly.json",
3+
"include": [
4+
"./**/*.ts"
5+
]
6+
}

0 commit comments

Comments
 (0)