ic-mops 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/test.js +72 -33
- package/package.json +4 -3
- package/templates/mops-test.yml +1 -1
package/commands/test.js
CHANGED
|
@@ -4,6 +4,7 @@ import glob from 'glob';
|
|
|
4
4
|
import chokidar from 'chokidar';
|
|
5
5
|
import debounce from 'debounce';
|
|
6
6
|
import path from 'path';
|
|
7
|
+
import fs from 'fs';
|
|
7
8
|
import {MMF1} from './mmf1.js';
|
|
8
9
|
import {sources} from './sources.js';
|
|
9
10
|
import {getRootDir} from '../mops.js';
|
|
@@ -58,7 +59,6 @@ let mocPath = process.env.DFX_MOC_PATH;
|
|
|
58
59
|
export async function runAll(filter = '') {
|
|
59
60
|
let start = Date.now();
|
|
60
61
|
let rootDir = getRootDir();
|
|
61
|
-
|
|
62
62
|
let files = [];
|
|
63
63
|
let libFiles = glob.sync('**/test?(s)/lib.mo', globConfig);
|
|
64
64
|
if (libFiles.length) {
|
|
@@ -81,8 +81,6 @@ export async function runAll(filter = '') {
|
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
let absToRel = (p) => path.relative(rootDir, path.resolve(p));
|
|
85
|
-
|
|
86
84
|
console.log('Test files:');
|
|
87
85
|
for (let file of files) {
|
|
88
86
|
console.log(chalk.gray(`• ${absToRel(file)}`));
|
|
@@ -98,44 +96,44 @@ export async function runAll(filter = '') {
|
|
|
98
96
|
mocPath = execSync('dfx cache show').toString().trim() + '/moc';
|
|
99
97
|
}
|
|
100
98
|
|
|
99
|
+
let wasmDir = `${getRootDir()}/.mops/.test/`;
|
|
100
|
+
fs.mkdirSync(wasmDir, {recursive: true});
|
|
101
|
+
|
|
101
102
|
for (let file of files) {
|
|
102
103
|
let mmf1 = new MMF1;
|
|
103
104
|
|
|
104
105
|
await new Promise((resolve) => {
|
|
106
|
+
let wasiMode = fs.readFileSync(file, 'utf8').startsWith('// @testmode wasi');
|
|
107
|
+
|
|
105
108
|
file !== files[0] && console.log('-'.repeat(50));
|
|
106
|
-
console.log(`Running ${chalk.gray(absToRel(file))}`);
|
|
109
|
+
console.log(`Running ${chalk.gray(absToRel(file))} ${wasiMode ? chalk.gray('(wasi)') : ''}`);
|
|
110
|
+
|
|
111
|
+
let mocArgs = ['--hide-warnings', '--error-detail=2', ...sourcesArr.join(' ').split(' '), file].filter(x => x);
|
|
107
112
|
|
|
108
|
-
|
|
113
|
+
// build and run wasm
|
|
114
|
+
if (wasiMode) {
|
|
115
|
+
let wasmFile = `${path.join(wasmDir, path.parse(file).name)}.wasm`;
|
|
109
116
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
// build
|
|
118
|
+
let buildProc = spawn(mocPath, [`-o=${wasmFile}`, '-wasi-system-api', ...mocArgs]);
|
|
119
|
+
pipeMMF(buildProc, mmf1).then(async () => {
|
|
120
|
+
if (mmf1.failed > 0) {
|
|
121
|
+
resolve();
|
|
122
|
+
return;
|
|
116
123
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
proc.on('exit', (code) => {
|
|
131
|
-
if (code === 0) {
|
|
132
|
-
mmf1.pass();
|
|
133
|
-
}
|
|
134
|
-
else if (code !== 1) {
|
|
135
|
-
console.log(chalk.red('unknown code:'), code);
|
|
136
|
-
}
|
|
137
|
-
resolve();
|
|
138
|
-
});
|
|
124
|
+
// run
|
|
125
|
+
let proc = spawn('wasmtime', [wasmFile]);
|
|
126
|
+
await pipeMMF(proc, mmf1);
|
|
127
|
+
}).finally(() => {
|
|
128
|
+
fs.rmSync(wasmFile);
|
|
129
|
+
resolve();
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
// interpret
|
|
133
|
+
else {
|
|
134
|
+
let proc = spawn(mocPath, ['-r', '-ref-system-api', ...mocArgs]);
|
|
135
|
+
pipeMMF(proc, mmf1).then(resolve);
|
|
136
|
+
}
|
|
139
137
|
});
|
|
140
138
|
|
|
141
139
|
passed += mmf1.passed;
|
|
@@ -143,6 +141,8 @@ export async function runAll(filter = '') {
|
|
|
143
141
|
skipped += mmf1.skipped;
|
|
144
142
|
}
|
|
145
143
|
|
|
144
|
+
fs.rmSync(wasmDir, {recursive: true, force: true});
|
|
145
|
+
|
|
146
146
|
console.log('='.repeat(50));
|
|
147
147
|
if (failed) {
|
|
148
148
|
console.log(chalk.redBright('Tests failed'));
|
|
@@ -158,4 +158,43 @@ export async function runAll(filter = '') {
|
|
|
158
158
|
);
|
|
159
159
|
|
|
160
160
|
return failed === 0;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function absToRel(p) {
|
|
164
|
+
let rootDir = getRootDir();
|
|
165
|
+
return path.relative(rootDir, path.resolve(p));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function pipeMMF(proc, mmf1) {
|
|
169
|
+
return new Promise((resolve) => {
|
|
170
|
+
// stdout
|
|
171
|
+
proc.stdout.on('data', (data) => {
|
|
172
|
+
for (let line of data.toString().split('\n')) {
|
|
173
|
+
line = line.trim();
|
|
174
|
+
if (line) {
|
|
175
|
+
mmf1.parseLine(line);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// stderr
|
|
181
|
+
proc.stderr.on('data', (data) => {
|
|
182
|
+
let text = data.toString().trim();
|
|
183
|
+
// change absolute file path to relative
|
|
184
|
+
// change :line:col-line:col to :line:col to work in vscode
|
|
185
|
+
text = text.replace(/([\w+._/-]+):(\d+).(\d+)(-\d+.\d+)/g, (m0, m1, m2, m3) => `${absToRel(m1)}:${m2}:${m3}`);
|
|
186
|
+
mmf1.fail(text);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// exit
|
|
190
|
+
proc.on('exit', (code) => {
|
|
191
|
+
if (code === 0) {
|
|
192
|
+
mmf1.pass();
|
|
193
|
+
}
|
|
194
|
+
else if (code !== 1) {
|
|
195
|
+
console.log(chalk.red('unknown code:'), code);
|
|
196
|
+
}
|
|
197
|
+
resolve();
|
|
198
|
+
});
|
|
199
|
+
});
|
|
161
200
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ic-mops",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"mops": "cli.js"
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"@dfinity/principal": "^0.11.1",
|
|
29
29
|
"@iarna/toml": "^2.2.5",
|
|
30
30
|
"as-table": "^1.0.55",
|
|
31
|
+
"cacheable-request": "10.2.10",
|
|
31
32
|
"chalk": "^4.1.2",
|
|
32
33
|
"chokidar": "^3.5.3",
|
|
33
34
|
"commander": "^9.2.0",
|
|
@@ -36,11 +37,11 @@
|
|
|
36
37
|
"del": "^6.0.0",
|
|
37
38
|
"dhall-to-json-cli": "^1.7.6",
|
|
38
39
|
"eslint": "^8.15.0",
|
|
39
|
-
"execa": "
|
|
40
|
+
"execa": "6.1.0",
|
|
40
41
|
"get-folder-size": "^4.0.0",
|
|
41
42
|
"glob": "^8.1.0",
|
|
42
43
|
"globby": "^13.1.1",
|
|
43
|
-
"got": "
|
|
44
|
+
"got": "12.5.3",
|
|
44
45
|
"log-update": "^5.0.1",
|
|
45
46
|
"minimatch": "^5.0.1",
|
|
46
47
|
"ncp": "^2.0.0",
|