Skip to content

Commit e68b42e

Browse files
Add CI Job to run "JSON Spec Test Suite" against as-json (#168)
* add helper wasm module for testing suite * add new CI job to run JSONTestSuite * rename test runner bash script * add readme for test helper cli wasm
1 parent 10b4c50 commit e68b42e

File tree

8 files changed

+131
-0
lines changed

8 files changed

+131
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ node_modules/
22
build/
33
temp-docs/
44
tests/build
5+
utils/testsuite_helper/build
56
.DS_Store
67

78
*.wat

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ jobs:
1717
- fossa init
1818
- fossa analyze --server-scan
1919
- fossa test
20+
21+
- name: JSON Test Suite
22+
before_script:
23+
- "curl https://wasmtime.dev/install.sh -sSf | bash"
24+
script:
25+
- bash utils/run_testsuite.sh

utils/run_testsuite.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/bash
2+
# Helper scipt to run JSONTestSuite in CI
3+
4+
5+
set -e
6+
set -x
7+
8+
cd utils/testsuite_helper
9+
yarn && yarn build
10+
11+
git clone https://github.com/ashutoshvarma/JSONTestSuite.git testsuite
12+
13+
# replace with newly build wasm
14+
rm testsuite/parsers/test_as_json/index.wasm
15+
cp build/index.wasm testsuite/parsers/test_as_json/index.wasm
16+
17+
# run tests
18+
echo '["Assemblyscript-JSON"]' > filter.json
19+
python3 testsuite/run_tests.py --filter=filter.json

utils/testsuite_helper/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# testsuite_helper
2+
3+
This module is primarily used to expose `JSON.parse` through a CLI environment for testing purpose.
4+
5+
### Return codes :-
6+
- 0 - If successfully parsed the input
7+
- 2 - Can't read the file properly
8+
9+
(It needs `wasmtime` to execute)
10+
11+
## Build
12+
```
13+
yarn
14+
yarn build
15+
```
16+
17+
## Run
18+
```
19+
yarn start --dir FOLDER JSON_FILE_NAME
20+
```
21+
or
22+
```
23+
wasmtime build/index.wasm --dir FOLDER JSON_FILE_NAME
24+
```
25+

utils/testsuite_helper/index.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import "wasi";
2+
3+
import { Console, CommandLine, Process, FileSystem, Descriptor } from "as-wasi";
4+
import { JSON } from "../../assembly";
5+
6+
function parse(file: string): u32 {
7+
const fd = FileSystem.open(file);
8+
if (fd == null) {
9+
Console.error("Cannot open file - " + file);
10+
return 2;
11+
}
12+
let content: string = fd.readString()!;
13+
if (content == null) {
14+
Console.error("Cannot read file - " + file);
15+
return 2;
16+
}
17+
18+
// parse the file
19+
let res = JSON.parse(content);
20+
// Console.log(res.toString());
21+
Console.log(file + " - Success!");
22+
return 0;
23+
}
24+
25+
let cmd = new CommandLine();
26+
let f: string | null = cmd.get(1);
27+
if (f) {
28+
Process.exit(parse(<string>f));
29+
} else {
30+
Console.log("No File");
31+
Process.exit(2);
32+
}

utils/testsuite_helper/package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "testsuite_helper",
3+
"version": "1.0.0",
4+
"description": "",
5+
"scripts": {
6+
"build": "asc index.ts -b build/index.wasm --debug",
7+
"start": "wasmtime build/index.wasm --dir ."
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "MIT",
12+
"devDependencies": {
13+
"assemblyscript": "^0.18.15"
14+
},
15+
"dependencies": {
16+
"as-wasi": "^0.4.4"
17+
}
18+
}

utils/testsuite_helper/tsconfig.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "assemblyscript/std/assembly.json",
3+
"include": ["./**/*.ts"]
4+
}

utils/testsuite_helper/yarn.lock

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
as-wasi@^0.4.4:
6+
version "0.4.4"
7+
resolved "https://registry.yarnpkg.com/as-wasi/-/as-wasi-0.4.4.tgz#3b439c25e975d8cc04f6deec898b57138862aa15"
8+
integrity sha512-CNeZ3AjKSjrFXRNDRzX1VzxsWz3Fwksn4g0J7tZv5RKz4agKhVlcl0QeMIOOkJms7DujCBCpbelGxNDtvlFKmw==
9+
10+
assemblyscript@^0.18.15:
11+
version "0.18.15"
12+
resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.18.15.tgz#b66a4d96c7de14e311303fb7c8ccf14b9d689e8f"
13+
integrity sha512-s1N1qwdBhen2SLQApYCtRIPWm1Am3oAbW58GCEKbeN6ZbQRh7nq0pv4RDqKw6CgK7dySn/F2S1D6p0scyRbQRw==
14+
dependencies:
15+
binaryen "100.0.0"
16+
long "^4.0.0"
17+
18+
19+
version "100.0.0"
20+
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-100.0.0.tgz#8ed91955eff14eb4758d68d593869cbc1a9a0dff"
21+
integrity sha512-nxOt8d8/VXAuSVEtAWUdKrqpqCy365QqD223EzzB1GzS5himiZAfM/R5lXx+M/5q8TB8cYp3tYxv5rTjNTJveQ==
22+
23+
long@^4.0.0:
24+
version "4.0.0"
25+
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
26+
integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==

0 commit comments

Comments
 (0)