-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
63 lines (50 loc) · 1.44 KB
/
test.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
const { Command, flags } = require("@oclif/command");
const { execSync } = require("child_process");
const fs = require("fs");
const glob = require("glob");
const path = require("path");
class TestCommand extends Command {
async run() {
// Check parameters
const { flags } = this.parse(TestCommand);
if (!flags.project) {
this.error("No project directory specified (-p). Exiting.");
return;
}
// Set up paths
const packageRoot = process.cwd();
const projectRoot = path.join(packageRoot, flags.project);
const testsRoot = path.join(projectRoot, "tests");
const outputRoot = path.join(testsRoot, "generated");
if (!fs.existsSync(outputRoot)) {
fs.mkdirSync(outputRoot);
}
// Build
this.log(`Building tests...`);
const sourceFiles = glob.sync(`${testsRoot}/*.cpp`);
const testExecutable = path.join(outputRoot, "tests");
execSync(
`g++ -I${projectRoot} -I${testsRoot} ${sourceFiles.join(
" "
)} -lstdc++ -lm -o ${testExecutable}`,
{
cwd: testsRoot,
stdio: "inherit",
}
);
// Run
this.log(`Running tests...`);
execSync(testExecutable, {
cwd: testsRoot,
stdio: "inherit",
});
}
}
TestCommand.description = `Test firmware project
...
Provide name of project directory with -p
`;
TestCommand.flags = {
project: flags.string({ char: "p", description: "Project to test" }),
};
module.exports = TestCommand;