as-test 0.2.1 → 0.3.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/.github/workflows/as-test.yml +3 -0
- package/CHANGELOG.md +1 -1
- package/README.md +73 -68
- package/as-test.config.json +7 -10
- package/assembly/__tests__/array.spec.ts +19 -0
- package/assembly/__tests__/math.spec.ts +16 -0
- package/assembly/__tests__/sleep.spec.ts +28 -0
- package/assembly/index.ts +181 -165
- package/assembly/src/expectation.ts +119 -112
- package/assembly/src/log.ts +19 -0
- package/assembly/src/suite.ts +99 -0
- package/assembly/src/tests.ts +10 -0
- package/assembly/tsconfig.json +1 -1
- package/assembly/util/helpers.ts +0 -33
- package/assembly/util/term.ts +55 -0
- package/assets/img/download.png +0 -0
- package/bin/about.js +135 -0
- package/bin/build.js +72 -131
- package/bin/index.js +70 -112
- package/bin/init.js +211 -39
- package/bin/reporter.js +1 -0
- package/bin/run.js +226 -68
- package/bin/types.js +25 -31
- package/bin/util.js +44 -20
- package/cli/build.ts +70 -109
- package/cli/index.ts +148 -159
- package/cli/init.ts +235 -34
- package/cli/reporter.ts +1 -0
- package/cli/run.ts +266 -57
- package/cli/types.ts +6 -11
- package/cli/util.ts +35 -0
- package/package.json +6 -2
- package/run/package.json +27 -0
- package/tests/array.run.js +7 -0
- package/tests/math.run.js +7 -0
- package/tests/sleep.run.js +7 -0
- package/transform/lib/coverage.js +325 -319
- package/transform/lib/index.js +51 -31
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/mock.js +60 -52
- package/transform/lib/mock.js.map +1 -1
- package/transform/package.json +1 -1
- package/transform/src/index.ts +22 -3
- package/transform/src/mock.ts +1 -1
- package/asconfig.json +0 -31
- package/assembly/__tests__/example.spec.ts +0 -79
- package/assembly/reporters/tap.ts +0 -30
- package/assembly/src/group.ts +0 -44
- package/assembly/src/node.ts +0 -13
- package/test.config.json +0 -0
- package/tests/test.tap +0 -14
- package/unision +0 -38
- package/unision.pub +0 -1
- package/utils.ts +0 -1
|
@@ -1,44 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
BlockStatement,
|
|
3
|
+
ExpressionStatement,
|
|
4
|
+
Node,
|
|
5
|
+
} from "assemblyscript/dist/assemblyscript.js";
|
|
2
6
|
import { BaseVisitor, SimpleParser } from "visitor-as/dist/index.js";
|
|
3
7
|
import { RangeTransform } from "visitor-as/dist/transformRange.js";
|
|
4
8
|
import { isStdlib } from "visitor-as/dist/utils.js";
|
|
5
9
|
var CoverType;
|
|
6
10
|
(function (CoverType) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
CoverType[(CoverType["Function"] = 0)] = "Function";
|
|
12
|
+
CoverType[(CoverType["Expression"] = 1)] = "Expression";
|
|
13
|
+
CoverType[(CoverType["Block"] = 2)] = "Block";
|
|
10
14
|
})(CoverType || (CoverType = {}));
|
|
11
15
|
class CoverPoint {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
file = "";
|
|
17
|
+
hash = "";
|
|
18
|
+
line = 0;
|
|
19
|
+
column = 0;
|
|
20
|
+
type;
|
|
21
|
+
executed = false;
|
|
18
22
|
}
|
|
19
23
|
export class CoverageTransform extends BaseVisitor {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
24
|
+
mustImport = false;
|
|
25
|
+
points = new Map();
|
|
26
|
+
globalStatements = [];
|
|
27
|
+
visitBinaryExpression(node) {
|
|
28
|
+
super.visitBinaryExpression(node);
|
|
29
|
+
if (node.visited) return;
|
|
30
|
+
node.visited = true;
|
|
31
|
+
const path = node.range.source.normalizedPath;
|
|
32
|
+
switch (node.operator) {
|
|
33
|
+
case 98:
|
|
34
|
+
case 97: {
|
|
35
|
+
const right = node.right;
|
|
36
|
+
const rightLc = getLineCol(node);
|
|
37
|
+
const point = new CoverPoint();
|
|
38
|
+
point.line = rightLc?.line;
|
|
39
|
+
point.column = rightLc?.column;
|
|
40
|
+
point.file = path;
|
|
41
|
+
point.type = CoverType.Expression;
|
|
42
|
+
point.hash = hash(point);
|
|
43
|
+
const replacer = new RangeTransform(node);
|
|
44
|
+
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
42
45
|
file: "${point.file}",
|
|
43
46
|
hash: "${point.hash}",
|
|
44
47
|
line: ${point.line},
|
|
@@ -46,35 +49,35 @@ export class CoverageTransform extends BaseVisitor {
|
|
|
46
49
|
type: "Expression",
|
|
47
50
|
executed: false
|
|
48
51
|
});`);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
replacer.visit(registerStmt);
|
|
53
|
+
let coverExpression = SimpleParser.parseExpression(
|
|
54
|
+
`(__COVER("${point.hash}"), $$REPLACE_ME)`,
|
|
55
|
+
);
|
|
56
|
+
replacer.visit(coverExpression);
|
|
57
|
+
coverExpression.expression.expressions[1] = right;
|
|
58
|
+
node.right = coverExpression;
|
|
59
|
+
this.globalStatements.push(registerStmt);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
58
62
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
63
|
+
}
|
|
64
|
+
visitMethodDeclaration(node) {
|
|
65
|
+
super.visitMethodDeclaration(node);
|
|
66
|
+
if (node.visited) return;
|
|
67
|
+
node.visited = true;
|
|
68
|
+
if (node.body) {
|
|
69
|
+
if (node.body.visited) return;
|
|
70
|
+
node.body.visited = true;
|
|
71
|
+
const path = node.range.source.normalizedPath;
|
|
72
|
+
const funcLc = getLineCol(node);
|
|
73
|
+
const point = new CoverPoint();
|
|
74
|
+
point.line = funcLc?.line;
|
|
75
|
+
point.column = funcLc?.column;
|
|
76
|
+
point.file = path;
|
|
77
|
+
point.type = CoverType.Function;
|
|
78
|
+
point.hash = hash(point);
|
|
79
|
+
const replacer = new RangeTransform(node);
|
|
80
|
+
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
78
81
|
file: "${point.file}",
|
|
79
82
|
hash: "${point.hash}",
|
|
80
83
|
line: ${point.line},
|
|
@@ -82,33 +85,34 @@ export class CoverageTransform extends BaseVisitor {
|
|
|
82
85
|
type: "Function",
|
|
83
86
|
executed: false
|
|
84
87
|
})`);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
replacer.visit(registerStmt);
|
|
89
|
+
const coverStmt = SimpleParser.parseStatement(
|
|
90
|
+
`__COVER("${point.hash}")`,
|
|
91
|
+
true,
|
|
92
|
+
);
|
|
93
|
+
replacer.visit(coverStmt);
|
|
94
|
+
const bodyBlock = node.body;
|
|
95
|
+
bodyBlock.statements.unshift(coverStmt);
|
|
96
|
+
this.globalStatements.push(registerStmt);
|
|
92
97
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
98
|
+
}
|
|
99
|
+
visitParameter(node) {
|
|
100
|
+
if (node.visited) return;
|
|
101
|
+
node.visited = true;
|
|
102
|
+
const path = node.range.source.normalizedPath;
|
|
103
|
+
if (node.initializer) {
|
|
104
|
+
if (node.initializer.visited) return;
|
|
105
|
+
node.initializer.visited = true;
|
|
106
|
+
super.visitParameter(node);
|
|
107
|
+
const paramLc = getLineCol(node.initializer);
|
|
108
|
+
const point = new CoverPoint();
|
|
109
|
+
point.line = paramLc?.line;
|
|
110
|
+
point.column = paramLc?.column;
|
|
111
|
+
point.file = path;
|
|
112
|
+
point.type = CoverType.Expression;
|
|
113
|
+
point.hash = hash(point);
|
|
114
|
+
const replacer = new RangeTransform(node);
|
|
115
|
+
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
112
116
|
file: "${point.file}",
|
|
113
117
|
hash: "${point.hash}",
|
|
114
118
|
line: ${point.line},
|
|
@@ -116,34 +120,33 @@ export class CoverageTransform extends BaseVisitor {
|
|
|
116
120
|
type: "Expression",
|
|
117
121
|
executed: false
|
|
118
122
|
})`);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
replacer.visit(registerStmt);
|
|
124
|
+
const coverExpression = SimpleParser.parseExpression(
|
|
125
|
+
`(__COVER("${point.hash}"), $$REPLACE_ME)`,
|
|
126
|
+
);
|
|
127
|
+
replacer.visit(coverExpression);
|
|
128
|
+
coverExpression.expression.expressions[1] = node.initializer;
|
|
129
|
+
node.initializer = coverExpression;
|
|
130
|
+
this.globalStatements.push(registerStmt);
|
|
127
131
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
132
|
+
}
|
|
133
|
+
visitFunctionDeclaration(node, isDefault) {
|
|
134
|
+
super.visitFunctionDeclaration(node, isDefault);
|
|
135
|
+
if (node.visited) return;
|
|
136
|
+
node.visited = true;
|
|
137
|
+
if (node.body) {
|
|
138
|
+
if (node.body.visited) return;
|
|
139
|
+
node.body.visited = true;
|
|
140
|
+
const path = node.range.source.normalizedPath;
|
|
141
|
+
const funcLc = getLineCol(node);
|
|
142
|
+
const point = new CoverPoint();
|
|
143
|
+
point.line = funcLc?.line;
|
|
144
|
+
point.column = funcLc?.column;
|
|
145
|
+
point.file = path;
|
|
146
|
+
point.type = CoverType.Function;
|
|
147
|
+
point.hash = hash(point);
|
|
148
|
+
const replacer = new RangeTransform(node);
|
|
149
|
+
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
147
150
|
file: "${point.file}",
|
|
148
151
|
hash: "${point.hash}",
|
|
149
152
|
line: ${point.line},
|
|
@@ -151,54 +154,57 @@ export class CoverageTransform extends BaseVisitor {
|
|
|
151
154
|
type: "Function",
|
|
152
155
|
executed: false
|
|
153
156
|
})`);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
157
|
+
replacer.visit(registerStmt);
|
|
158
|
+
this.globalStatements.push(registerStmt);
|
|
159
|
+
if (node.body.kind === 35) {
|
|
160
|
+
const coverStmt = SimpleParser.parseStatement(`{
|
|
158
161
|
__COVER("${point.hash}")
|
|
159
162
|
return $$REPLACE_ME
|
|
160
163
|
}`);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
164
|
+
replacer.visit(coverStmt);
|
|
165
|
+
const bodyReturn = coverStmt.statements[1];
|
|
166
|
+
const body = node.body;
|
|
167
|
+
node.arrowKind = 2;
|
|
168
|
+
bodyReturn.value = body.expression;
|
|
169
|
+
node.body = body;
|
|
170
|
+
} else {
|
|
171
|
+
const coverStmt = SimpleParser.parseStatement(
|
|
172
|
+
`__COVER("${point.hash}")`,
|
|
173
|
+
true,
|
|
174
|
+
);
|
|
175
|
+
replacer.visit(coverStmt);
|
|
176
|
+
if (node.body instanceof BlockStatement) {
|
|
177
|
+
node.body.statements.unshift(coverStmt);
|
|
178
|
+
} else if (node.body instanceof ExpressionStatement) {
|
|
179
|
+
const expression = node.body.expression;
|
|
180
|
+
node.body = Node.createBlockStatement(
|
|
181
|
+
[Node.createReturnStatement(expression, expression.range)],
|
|
182
|
+
expression.range,
|
|
183
|
+
);
|
|
184
|
+
const bodyBlock = node.body;
|
|
185
|
+
bodyBlock.statements.unshift(coverStmt);
|
|
181
186
|
}
|
|
187
|
+
}
|
|
182
188
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
189
|
+
}
|
|
190
|
+
visitIfStatement(node) {
|
|
191
|
+
if (node.visited) return;
|
|
192
|
+
node.visited = true;
|
|
193
|
+
let visitIfTrue = false;
|
|
194
|
+
let visitIfFalse = false;
|
|
195
|
+
const ifTrue = node.ifTrue;
|
|
196
|
+
const ifFalse = node.ifFalse;
|
|
197
|
+
const path = node.range.source.normalizedPath;
|
|
198
|
+
if (ifTrue.kind !== 30) {
|
|
199
|
+
const trueLc = getLineCol(ifTrue);
|
|
200
|
+
const point = new CoverPoint();
|
|
201
|
+
point.line = trueLc?.line;
|
|
202
|
+
point.column = trueLc?.column;
|
|
203
|
+
point.file = path;
|
|
204
|
+
point.type = CoverType.Expression;
|
|
205
|
+
point.hash = hash(point);
|
|
206
|
+
const replacer = new RangeTransform(ifTrue);
|
|
207
|
+
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
202
208
|
file: "${point.file}",
|
|
203
209
|
hash: "${point.hash}",
|
|
204
210
|
line: ${point.line},
|
|
@@ -206,25 +212,28 @@ export class CoverageTransform extends BaseVisitor {
|
|
|
206
212
|
type: "Expression",
|
|
207
213
|
executed: false
|
|
208
214
|
})`);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
215
|
+
replacer.visit(registerStmt);
|
|
216
|
+
const coverStmt = SimpleParser.parseStatement(
|
|
217
|
+
`{__COVER("${point.hash}")};`,
|
|
218
|
+
true,
|
|
219
|
+
);
|
|
220
|
+
replacer.visit(coverStmt);
|
|
221
|
+
coverStmt.statements.push(ifTrue);
|
|
222
|
+
node.ifTrue = coverStmt;
|
|
223
|
+
this.globalStatements.push(registerStmt);
|
|
224
|
+
visitIfTrue = true;
|
|
225
|
+
visitIfFalse = !!ifFalse;
|
|
226
|
+
}
|
|
227
|
+
if (ifFalse && ifFalse.kind !== 30) {
|
|
228
|
+
const falseLc = getLineCol(ifFalse);
|
|
229
|
+
const point = new CoverPoint();
|
|
230
|
+
point.line = falseLc?.line;
|
|
231
|
+
point.column = falseLc?.column;
|
|
232
|
+
point.file = path;
|
|
233
|
+
point.type = CoverType.Expression;
|
|
234
|
+
point.hash = hash(point);
|
|
235
|
+
const replacer = new RangeTransform(ifTrue);
|
|
236
|
+
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
228
237
|
file: "${point.file}",
|
|
229
238
|
hash: "${point.hash}",
|
|
230
239
|
line: ${point.line},
|
|
@@ -232,51 +241,50 @@ export class CoverageTransform extends BaseVisitor {
|
|
|
232
241
|
type: "Expression",
|
|
233
242
|
executed: false
|
|
234
243
|
})`);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
244
|
+
replacer.visit(registerStmt);
|
|
245
|
+
const coverStmt = SimpleParser.parseStatement(
|
|
246
|
+
`{__COVER("${point.hash}")};`,
|
|
247
|
+
true,
|
|
248
|
+
);
|
|
249
|
+
replacer.visit(coverStmt);
|
|
250
|
+
coverStmt.statements.push(ifFalse);
|
|
251
|
+
node.ifFalse = coverStmt;
|
|
252
|
+
this.globalStatements.push(registerStmt);
|
|
253
|
+
visitIfTrue = true;
|
|
254
|
+
visitIfFalse = true;
|
|
255
|
+
}
|
|
256
|
+
if (visitIfTrue || visitIfFalse) {
|
|
257
|
+
if (visitIfTrue) {
|
|
258
|
+
if (ifTrue.visited) return;
|
|
259
|
+
ifTrue.visited = true;
|
|
260
|
+
this._visit(ifTrue);
|
|
261
|
+
}
|
|
262
|
+
if (visitIfFalse) {
|
|
263
|
+
if (ifFalse.visited) return;
|
|
264
|
+
ifFalse.visited = true;
|
|
265
|
+
this._visit(ifFalse);
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
super.visitIfStatement(node);
|
|
261
269
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
270
|
+
}
|
|
271
|
+
visitTernaryExpression(node) {
|
|
272
|
+
if (node.visited) return;
|
|
273
|
+
node.visited = true;
|
|
274
|
+
super.visitTernaryExpression(node);
|
|
275
|
+
const trueExpression = node.ifThen;
|
|
276
|
+
const falseExpression = node.ifElse;
|
|
277
|
+
const path = node.range.source.normalizedPath;
|
|
278
|
+
{
|
|
279
|
+
const trueLc = getLineCol(trueExpression);
|
|
280
|
+
const point = new CoverPoint();
|
|
281
|
+
point.line = trueLc?.line;
|
|
282
|
+
point.column = trueLc?.column;
|
|
283
|
+
point.file = path;
|
|
284
|
+
point.type = CoverType.Expression;
|
|
285
|
+
point.hash = hash(point);
|
|
286
|
+
const replacer = new RangeTransform(trueExpression);
|
|
287
|
+
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
280
288
|
file: "${point.file}",
|
|
281
289
|
hash: "${point.hash}",
|
|
282
290
|
line: ${point.line},
|
|
@@ -284,24 +292,25 @@ export class CoverageTransform extends BaseVisitor {
|
|
|
284
292
|
type: "Expression",
|
|
285
293
|
executed: false
|
|
286
294
|
})`);
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
295
|
+
replacer.visit(registerStmt);
|
|
296
|
+
const coverExpression = SimpleParser.parseExpression(
|
|
297
|
+
`(__COVER("${point.hash}"), $$REPLACE_ME)`,
|
|
298
|
+
);
|
|
299
|
+
replacer.visit(coverExpression);
|
|
300
|
+
coverExpression.expression.expressions[1] = trueExpression;
|
|
301
|
+
node.ifThen = coverExpression;
|
|
302
|
+
this.globalStatements.push(registerStmt);
|
|
303
|
+
}
|
|
304
|
+
{
|
|
305
|
+
const falseLc = getLineCol(falseExpression);
|
|
306
|
+
const point = new CoverPoint();
|
|
307
|
+
point.line = falseLc?.line;
|
|
308
|
+
point.column = falseLc?.column;
|
|
309
|
+
point.file = path;
|
|
310
|
+
point.type = CoverType.Expression;
|
|
311
|
+
point.hash = hash(point);
|
|
312
|
+
const replacer = new RangeTransform(falseExpression);
|
|
313
|
+
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
305
314
|
file: "${point.file}",
|
|
306
315
|
hash: "${point.hash}",
|
|
307
316
|
line: ${point.line},
|
|
@@ -309,29 +318,29 @@ export class CoverageTransform extends BaseVisitor {
|
|
|
309
318
|
type: "Expression",
|
|
310
319
|
executed: false
|
|
311
320
|
})`);
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
321
|
+
replacer.visit(registerStmt);
|
|
322
|
+
const coverExpression = SimpleParser.parseExpression(
|
|
323
|
+
`(__COVER("${point.hash}"), $$REPLACE_ME)`,
|
|
324
|
+
);
|
|
325
|
+
replacer.visit(coverExpression);
|
|
326
|
+
coverExpression.expression.expressions[1] = falseExpression;
|
|
327
|
+
node.ifElse = coverExpression;
|
|
328
|
+
this.globalStatements.push(registerStmt);
|
|
320
329
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
330
|
+
}
|
|
331
|
+
visitSwitchCase(node) {
|
|
332
|
+
if (node.visited) return;
|
|
333
|
+
node.visited = true;
|
|
334
|
+
const path = node.range.source.normalizedPath;
|
|
335
|
+
const caseLc = getLineCol(node);
|
|
336
|
+
const point = new CoverPoint();
|
|
337
|
+
point.line = caseLc?.line;
|
|
338
|
+
point.column = caseLc?.column;
|
|
339
|
+
point.file = path;
|
|
340
|
+
point.type = CoverType.Block;
|
|
341
|
+
point.hash = hash(point);
|
|
342
|
+
const replacer = new RangeTransform(node);
|
|
343
|
+
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
335
344
|
file: "${point.file}",
|
|
336
345
|
hash: "${point.hash}",
|
|
337
346
|
line: ${point.line},
|
|
@@ -339,27 +348,26 @@ export class CoverageTransform extends BaseVisitor {
|
|
|
339
348
|
type: "Block",
|
|
340
349
|
executed: false
|
|
341
350
|
})`);
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
351
|
+
replacer.visit(registerStmt);
|
|
352
|
+
const coverStmt = SimpleParser.parseStatement(`__COVER("${point.hash}")`);
|
|
353
|
+
replacer.visit(coverStmt);
|
|
354
|
+
this.globalStatements.push(registerStmt);
|
|
355
|
+
super.visitSwitchCase(node);
|
|
356
|
+
node.statements.unshift(coverStmt);
|
|
357
|
+
}
|
|
358
|
+
visitBlockStatement(node) {
|
|
359
|
+
if (node.visited) return;
|
|
360
|
+
node.visited = true;
|
|
361
|
+
const path = node.range.source.normalizedPath;
|
|
362
|
+
const blockLc = getLineCol(node);
|
|
363
|
+
const point = new CoverPoint();
|
|
364
|
+
point.line = blockLc?.line;
|
|
365
|
+
point.column = blockLc?.column;
|
|
366
|
+
point.file = path;
|
|
367
|
+
point.type = CoverType.Block;
|
|
368
|
+
point.hash = hash(point);
|
|
369
|
+
const replacer = new RangeTransform(node);
|
|
370
|
+
const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
|
|
363
371
|
file: "${point.file}",
|
|
364
372
|
hash: "${point.hash}",
|
|
365
373
|
line: ${point.line},
|
|
@@ -367,51 +375,49 @@ export class CoverageTransform extends BaseVisitor {
|
|
|
367
375
|
type: "Block",
|
|
368
376
|
executed: false
|
|
369
377
|
})`);
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
return;
|
|
384
|
-
super.visitSource(node);
|
|
385
|
-
}
|
|
378
|
+
replacer.visit(registerStmt);
|
|
379
|
+
const coverStmt = SimpleParser.parseStatement(`__COVER("${point.hash}")`);
|
|
380
|
+
replacer.visit(coverStmt);
|
|
381
|
+
this.globalStatements.push(registerStmt);
|
|
382
|
+
super.visitBlockStatement(node);
|
|
383
|
+
node.statements.unshift(coverStmt);
|
|
384
|
+
}
|
|
385
|
+
visitSource(node) {
|
|
386
|
+
if (node.isLibrary) return;
|
|
387
|
+
if (node.simplePath === "coverage") return;
|
|
388
|
+
if (isStdlib(node)) return;
|
|
389
|
+
super.visitSource(node);
|
|
390
|
+
}
|
|
386
391
|
}
|
|
387
392
|
function djb2Hash(str) {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
+
const points = Array.from(str);
|
|
394
|
+
let h = 5381;
|
|
395
|
+
for (let p = 0; p < points.length; p++)
|
|
396
|
+
h = ((h << 5) - h + points[p].codePointAt(0)) | 0;
|
|
397
|
+
return h;
|
|
393
398
|
}
|
|
394
399
|
function hash(point) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
400
|
+
const hsh = djb2Hash(
|
|
401
|
+
point.file +
|
|
402
|
+
point.line.toString() +
|
|
403
|
+
point.column.toString() +
|
|
404
|
+
point.type.toString(),
|
|
405
|
+
);
|
|
406
|
+
if (hsh < 0) {
|
|
407
|
+
const out = hsh.toString(16);
|
|
408
|
+
return "3" + out.slice(1);
|
|
409
|
+
} else {
|
|
410
|
+
return hsh.toString(16);
|
|
411
|
+
}
|
|
406
412
|
}
|
|
407
413
|
class LineColumn {
|
|
408
|
-
|
|
409
|
-
|
|
414
|
+
line;
|
|
415
|
+
column;
|
|
410
416
|
}
|
|
411
417
|
function getLineCol(node) {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
418
|
+
return {
|
|
419
|
+
line: node.range.source.lineAt(node.range.start),
|
|
420
|
+
column: node.range.source.columnAt(),
|
|
421
|
+
};
|
|
416
422
|
}
|
|
417
|
-
//# sourceMappingURL=coverage.js.map
|
|
423
|
+
//# sourceMappingURL=coverage.js.map
|