-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-libraries.js
80 lines (58 loc) · 2.19 KB
/
build-libraries.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/node
const os = require('os');
const fs = require('fs');
const path = require('path');
const ConfigLoader = require('./configLoader');
const config = new ConfigLoader();
const loadTests = require('./loadTests');
const { generateEmptyResults } = require('./resultsShared');
async function main() {
const tests = loadTests.load();
// Set this to true to run only the first group of tests
const quickTest = config.Debug.QuickTest
const emptyResults = await generateEmptyResults(tests, quickTest);
const skipMap = config.skipListMap();
for (let testFile of emptyResults) {
await generateLibrariesFromTests(testFile, skipMap);
}
}
main();
async function generateLibrariesFromTests(group, skipMap) {
if (!group || group.length === 0) return;
const cqlFileVersion = config.Build.CqlFileVersion;
const cqlOutputPath = config.Build.CqlOutputPath;
let testsName = '';
let body = '';
for (let r of group) {
if (!testsName) {
testsName = r.testsName;
}
if (r.invalid !== 'semantic') {
const defineVal = `define "${r.groupName}.${r.testName}": ${r.expression}`;
const key = `${r.testsName}-${r.groupName}-${r.testName}`;
let reason = '';
if (r.testStatus === 'skip') {
console.log(`Skipping ${key}`);
reason = "Skipped by cql-tests-runner";
} else if (skipMap.has(key)) {
console.log(`Skipping ${key}`);
reason = skipMap.get(key);
}
if (reason) {
body += `/* ${os.EOL} Skipped: ${reason} ${os.EOL} ${defineVal} ${os.EOL}*/${os.EOL}${os.EOL}`;
} else {
body += `${defineVal}${os.EOL}${os.EOL}`;
}
}
}
if (!testsName) return;
body = `library ${testsName} version '${cqlFileVersion}'${os.EOL}${os.EOL}${body}`;
if (!fs.existsSync(cqlOutputPath)) {
fs.mkdirSync(cqlOutputPath, { recursive: true });
}
const fileName = `${testsName}.cql`;
const filePath = path.join(cqlOutputPath, fileName);
fs.writeFileSync(filePath, body, (error) => {
if (error) throw error;
});
}