@abaplint/transpiler 2.7.6 → 2.7.8

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.
@@ -12,7 +12,7 @@ class SQLFromSourceTranspiler {
12
12
  chunk.appendString(c.concatTokens() + " ");
13
13
  }
14
14
  else if (c.get() instanceof abaplint.Expressions.DatabaseTable && c.concatTokens().includes("/")) {
15
- chunk.appendString("\"" + c.concatTokens() + "\" ");
15
+ chunk.appendString("\\\"" + c.concatTokens() + "\\\" ");
16
16
  }
17
17
  else if (c.get() instanceof abaplint.Expressions.DatabaseTable && c.concatTokens().startsWith("('")) {
18
18
  const concat = c.concatTokens();
@@ -33,17 +33,17 @@ class Transpiler {
33
33
  return new Transpiler().run(reg);
34
34
  }
35
35
  async run(reg, progress) {
36
- var _a, _b, _c, _d, _e, _f, _g;
36
+ var _a, _b, _c, _d, _e;
37
37
  reg.parse();
38
38
  new keywords_1.Keywords((_a = this.options) === null || _a === void 0 ? void 0 : _a.keywords).handle(reg);
39
39
  this.validate(reg);
40
40
  const dbSetup = new db_1.DatabaseSetup(reg).run(this.options);
41
41
  const output = {
42
42
  objects: [],
43
- unitTestScript: new unit_test_1.UnitTest().unitTestScript(reg, (_b = this.options) === null || _b === void 0 ? void 0 : _b.skip, (_c = this.options) === null || _c === void 0 ? void 0 : _c.only),
44
- unitTestScriptOpen: new unit_test_1.UnitTest().unitTestScriptOpen(reg, (_d = this.options) === null || _d === void 0 ? void 0 : _d.skip, (_e = this.options) === null || _e === void 0 ? void 0 : _e.only),
45
- initializationScript: new unit_test_1.UnitTest().initializationScript(reg, dbSetup, (_f = this.options) === null || _f === void 0 ? void 0 : _f.extraSetup),
46
- initializationScript2: new unit_test_1.UnitTest().initializationScript(reg, dbSetup, (_g = this.options) === null || _g === void 0 ? void 0 : _g.extraSetup, true),
43
+ unitTestScript: new unit_test_1.UnitTest().unitTestScript(reg, (_b = this.options) === null || _b === void 0 ? void 0 : _b.skip),
44
+ unitTestScriptOpen: new unit_test_1.UnitTest().unitTestScriptOpen(reg, (_c = this.options) === null || _c === void 0 ? void 0 : _c.skip),
45
+ initializationScript: new unit_test_1.UnitTest().initializationScript(reg, dbSetup, (_d = this.options) === null || _d === void 0 ? void 0 : _d.extraSetup),
46
+ initializationScript2: new unit_test_1.UnitTest().initializationScript(reg, dbSetup, (_e = this.options) === null || _e === void 0 ? void 0 : _e.extraSetup, true),
47
47
  databaseSetup: dbSetup,
48
48
  reg: reg,
49
49
  };
@@ -47,8 +47,8 @@ export interface ITranspilerOptions {
47
47
  skipConstants?: boolean;
48
48
  /** sets behavior for unknown types, either fail at compile- or run-time */
49
49
  unknownTypes?: "compileError" | "runtimeError";
50
+ /** list of unit tests to skip */
50
51
  skip?: TestMethodList;
51
- only?: TestMethodList;
52
52
  /** extra setup script to be executed during initialization */
53
53
  extraSetup?: string;
54
54
  /** list of keywords to rename, if not supplied default will be used */
@@ -8,8 +8,9 @@ export type TestMethodList = {
8
8
  export declare class UnitTest {
9
9
  initializationScript(reg: abaplint.IRegistry, dbSetup: DatabaseSetupResult, extraSetup?: string, useImport?: boolean): string;
10
10
  private escapeNamespace;
11
- unitTestScriptOpen(reg: abaplint.IRegistry, _skip?: TestMethodList, _only?: TestMethodList): string;
12
- unitTestScript(reg: abaplint.IRegistry, skip?: TestMethodList, _only?: TestMethodList): string;
11
+ unitTestScriptOpen(reg: abaplint.IRegistry, _skip?: TestMethodList): string;
12
+ private getSortedTests;
13
+ unitTestScript(reg: abaplint.IRegistry, skip?: TestMethodList): string;
13
14
  private buildImports;
14
15
  private hasClassConstructor;
15
16
  }
@@ -44,7 +44,7 @@ export async function initializeABAP() {\n`;
44
44
  // ES modules are resolved and cached as URLs. This means that special characters must be percent-encoded, such as # with %23 and ? with %3F.
45
45
  return filename.replace(/\//g, "%23");
46
46
  }
47
- unitTestScriptOpen(reg, _skip, _only) {
47
+ unitTestScriptOpen(reg, _skip) {
48
48
  let ret = `/* eslint-disable curly */
49
49
  import fs from "fs";
50
50
  import path from "path";
@@ -99,7 +99,91 @@ run().then(() => {
99
99
  });`;
100
100
  return ret;
101
101
  }
102
- unitTestScript(reg, skip, _only) {
102
+ getSortedTests(reg) {
103
+ const tests = [];
104
+ for (const obj of reg.getObjects()) {
105
+ if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
106
+ continue;
107
+ }
108
+ const hasTestFile = obj.getFiles().some(f => { return f.getFilename().includes(".testclasses."); });
109
+ if (hasTestFile === false) {
110
+ continue;
111
+ }
112
+ for (const file of obj.getABAPFiles()) {
113
+ for (const def of file.getInfo().listClassDefinitions()) {
114
+ if (def.isForTesting === false
115
+ || def.isGlobal === true
116
+ || def.methods.length === 0
117
+ || def.isAbstract === true) {
118
+ // todo, fix, there might be global test methods
119
+ continue;
120
+ }
121
+ const methods = [];
122
+ for (const m of def.methods) {
123
+ if (m.isForTesting === false) {
124
+ continue;
125
+ }
126
+ methods.push(m.name);
127
+ }
128
+ tests.push({
129
+ obj,
130
+ localClass: def.name,
131
+ riskLevel: def.riskLevel,
132
+ duration: def.duration,
133
+ methods: methods,
134
+ });
135
+ }
136
+ }
137
+ }
138
+ const toNumber = (riskLevel, duration) => {
139
+ let int = 0;
140
+ switch (riskLevel) {
141
+ case abaplint.Info.RiskLevel.harmless:
142
+ int = 10;
143
+ break;
144
+ case abaplint.Info.RiskLevel.critical:
145
+ int = 20;
146
+ break;
147
+ case abaplint.Info.RiskLevel.dangerous:
148
+ int = 30;
149
+ break;
150
+ default:
151
+ break;
152
+ }
153
+ switch (duration) {
154
+ case abaplint.Info.Duration.short:
155
+ int += 1;
156
+ break;
157
+ case abaplint.Info.Duration.medium:
158
+ int += 2;
159
+ break;
160
+ case abaplint.Info.Duration.long:
161
+ int += 3;
162
+ break;
163
+ default:
164
+ break;
165
+ }
166
+ return int;
167
+ };
168
+ tests.sort((a, b) => {
169
+ const ai = toNumber(a.riskLevel, a.duration);
170
+ const bi = toNumber(b.riskLevel, b.duration);
171
+ let ret = ai - bi;
172
+ if (ret === 0) {
173
+ // if risk and duration are equal, then sort by name
174
+ if (a.obj.getName() < b.obj.getName()) {
175
+ ret = -1;
176
+ }
177
+ if (a.obj.getName() > b.obj.getName()) {
178
+ ret = 1;
179
+ }
180
+ ret = 0;
181
+ }
182
+ return ret;
183
+ });
184
+ return tests;
185
+ }
186
+ unitTestScript(reg, skip) {
103
187
  let ret = `/* eslint-disable curly */
104
188
  import fs from "fs";
105
189
  import path from "path";
@@ -116,54 +200,86 @@ async function run() {
116
200
  let locl;
117
201
  let meth;
118
202
  try {\n`;
119
- for (const obj of reg.getObjects()) {
120
- if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
121
- continue;
122
- }
203
+ for (const st of this.getSortedTests(reg)) {
123
204
  ret += `// --------------------------------------------\n`;
124
- ret += ` clas = unit.addObject("${obj.getName()}");\n`;
125
- for (const file of obj.getABAPFiles()) {
205
+ ret += ` clas = unit.addObject("${st.obj.getName()}");\n`;
206
+ ret += ` {
207
+ const {${st.localClass}} = await import("./${this.escapeNamespace(st.obj.getName().toLowerCase())}.${st.obj.getType().toLowerCase()}.testclasses.mjs");
208
+ locl = clas.addTestClass("${st.localClass}");
209
+ if (${st.localClass}.class_setup) await ${st.localClass}.class_setup();\n`;
210
+ for (const m of st.methods) {
211
+ const skipThis = (skip || []).some(a => a.object === st.obj.getName() && a.class === st.localClass && a.method === m);
212
+ if (skipThis) {
213
+ ret += ` console.log('${st.obj.getName()}: running ${st.localClass}->${m}, skipped');\n`;
214
+ ret += ` meth = locl.addMethod("${m}");\n`;
215
+ ret += ` meth.skip();\n`;
216
+ continue;
217
+ }
218
+ ret += ` {\n const test = await (new ${st.localClass}()).constructor_();\n`;
219
+ ret += ` if (test.setup) await test.setup();\n`;
220
+ ret += ` console.log("${st.obj.getName()}: running ${st.localClass}->${m}");\n`;
221
+ ret += ` meth = locl.addMethod("${m}");\n`;
222
+ ret += ` await test.${m}();\n`;
223
+ ret += ` meth.pass();\n`;
224
+ ret += ` if (test.teardown) await test.teardown();\n`;
225
+ ret += ` }\n`;
226
+ }
227
+ ret += ` if (${st.localClass}.class_teardown) await ${st.localClass}.class_teardown();\n`;
228
+ ret += ` }\n`;
229
+ }
230
+ /*
231
+ for (const obj of reg.getObjects()) {
232
+ if (reg.isDependency(obj) || !(obj instanceof abaplint.Objects.Class)) {
233
+ continue;
234
+ }
235
+ ret += `// --------------------------------------------\n`;
236
+ ret += ` clas = unit.addObject("${obj.getName()}");\n`;
237
+ for (const file of obj.getABAPFiles()) {
126
238
  for (const def of file.getInfo().listClassDefinitions()) {
127
- if (def.isForTesting === false
128
- || def.isGlobal === true
129
- || def.methods.length === 0
130
- || def.isAbstract === true) {
131
- // todo, fix, there might be global test methods
132
- continue;
239
+ if (def.isForTesting === false
240
+ || def.isGlobal === true
241
+ || def.methods.length === 0
242
+ || def.isAbstract === true) {
243
+ // todo, fix, there might be global test methods
244
+ continue;
245
+ }
246
+ const hasTestFile = obj.getFiles().some(f => { return f.getFilename().includes(".testclasses."); });
247
+ if (hasTestFile === false) {
248
+ break;
249
+ }
250
+ ret += ` {
251
+ const {${def.name}} = await import("./${this.escapeNamespace(obj.getName().toLowerCase())}.${obj.getType().toLowerCase()}.testclasses.mjs");
252
+ locl = clas.addTestClass("${def.name}");
253
+ if (${def.name}.class_setup) await ${def.name}.class_setup();\n`;
254
+
255
+ for (const m of def.methods) {
256
+ if (m.isForTesting === false) {
257
+ continue;
133
258
  }
134
- const hasTestFile = obj.getFiles().some(f => { return f.getFilename().includes(".testclasses."); });
135
- if (hasTestFile === false) {
136
- break;
259
+ const skipThis = (skip || []).some(a => a.object === obj.getName() && a.class === def.name && a.method === m.name);
260
+ if (skipThis) {
261
+ ret += ` console.log('${obj.getName()}: running ${def.name}->${m.name}, skipped');\n`;
262
+ ret += ` meth = locl.addMethod("${m.name}");\n`;
263
+ ret += ` meth.skip();\n`;
264
+ continue;
137
265
  }
138
- ret += ` {
139
- const {${def.name}} = await import("./${this.escapeNamespace(obj.getName().toLowerCase())}.${obj.getType().toLowerCase()}.testclasses.mjs");
140
- locl = clas.addTestClass("${def.name}");
141
- if (${def.name}.class_setup) await ${def.name}.class_setup();\n`;
142
- for (const m of def.methods) {
143
- if (m.isForTesting === false) {
144
- continue;
145
- }
146
- const skipThis = (skip || []).some(a => a.object === obj.getName() && a.class === def.name && a.method === m.name);
147
- if (skipThis) {
148
- ret += ` console.log('${obj.getName()}: running ${def.name}->${m.name}, skipped');\n`;
149
- ret += ` meth = locl.addMethod("${m.name}");\n`;
150
- ret += ` meth.skip();\n`;
151
- continue;
152
- }
153
- ret += ` {\n const test = await (new ${def.name}()).constructor_();\n`;
154
- ret += ` if (test.setup) await test.setup();\n`;
155
- ret += ` console.log("${obj.getName()}: running ${def.name}->${m.name}");\n`;
156
- ret += ` meth = locl.addMethod("${m.name}");\n`;
157
- ret += ` await test.${m.name}();\n`;
158
- ret += ` meth.pass();\n`;
159
- ret += ` if (test.teardown) await test.teardown();\n`;
160
- ret += ` }\n`;
161
- }
162
- ret += ` if (${def.name}.class_teardown) await ${def.name}.class_teardown();\n`;
163
- ret += ` }\n`;
266
+
267
+ ret += ` {\n const test = await (new ${def.name}()).constructor_();\n`;
268
+ ret += ` if (test.setup) await test.setup();\n`;
269
+ ret += ` console.log("${obj.getName()}: running ${def.name}->${m.name}");\n`;
270
+ ret += ` meth = locl.addMethod("${m.name}");\n`;
271
+ ret += ` await test.${m.name}();\n`;
272
+ ret += ` meth.pass();\n`;
273
+ ret += ` if (test.teardown) await test.teardown();\n`;
274
+ ret += ` }\n`;
275
+ }
276
+
277
+ ret += ` if (${def.name}.class_teardown) await ${def.name}.class_teardown();\n`;
278
+ ret += ` }\n`;
164
279
  }
280
+ }
165
281
  }
166
- }
282
+ */
167
283
  ret += `// -------------------END-------------------
168
284
  fs.writeFileSync(__dirname + path.sep + "_output.xml", unit.xUnitXML());
169
285
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.7.6",
3
+ "version": "2.7.8",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "author": "abaplint",
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
- "@abaplint/core": "^2.101.0",
32
+ "@abaplint/core": "^2.101.2",
33
33
  "source-map": "^0.7.4"
34
34
  },
35
35
  "devDependencies": {