-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathscriptgen.ts
More file actions
75 lines (71 loc) · 2.61 KB
/
Copy pathscriptgen.ts
File metadata and controls
75 lines (71 loc) · 2.61 KB
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
// Copyright 2020-2026 The MathWorks, Inc.
import * as path from "path";
/**
* Interface representing collection of test-related options to pass to
* scriptgen.
*/
export interface RunTestsOptions {
JUnitTestResults?: string;
CoberturaCodeCoverage?: string;
HTMLCodeCoverage?: string;
SourceFolder?: string;
PDFTestReport?: string;
HTMLTestReport?: string;
SimulinkTestResults?: string;
CoberturaModelCoverage?: string;
HTMLModelCoverage?: string;
SelectByTag?: string;
SelectByFolder?: string;
Strict?: boolean;
UseParallel?: boolean;
OutputDetail?: string;
LoggingLevel?: string;
CodeCoverageMetrics?: string;
}
function formatMetricsCellArray(metrics: string | undefined): string {
if (!metrics || metrics.trim() === "") {
return "{}";
}
const items = metrics
.trim()
.split(/\s+/)
.map((m) => `'${m}'`)
.join(",");
return `{${items}}`;
}
/**
* Generate scriptgen command for running tests.
*
* @param options scriptgen options for running tests.
*/
export function generateCommand(options: RunTestsOptions): string {
const metricsCellArray = formatMetricsCellArray(options.CodeCoverageMetrics);
const command = `
addpath('${path.join(import.meta.dirname, "scriptgen")}');
testScript = genscript('Test',
'JUnitTestResults','${options.JUnitTestResults || ""}',
'CoberturaCodeCoverage','${options.CoberturaCodeCoverage || ""}',
'HTMLCodeCoverage','${options.HTMLCodeCoverage || ""}',
'SourceFolder','${options.SourceFolder || ""}',
'PDFTestReport','${options.PDFTestReport || ""}',
'HTMLTestReport','${options.HTMLTestReport || ""}',
'SimulinkTestResults','${options.SimulinkTestResults || ""}',
'CoberturaModelCoverage','${options.CoberturaModelCoverage || ""}',
'HTMLModelCoverage','${options.HTMLModelCoverage || ""}',
'SelectByTag','${options.SelectByTag || ""}',
'SelectByFolder','${options.SelectByFolder || ""}',
'Strict',${options.Strict || false},
'UseParallel',${options.UseParallel || false},
'OutputDetail','${options.OutputDetail || ""}',
'LoggingLevel','${options.LoggingLevel || ""}',
'Metrics',${metricsCellArray}
);
disp('Running MATLAB script with contents:');
disp(testScript.Contents);
fprintf('__________\\n\\n');
run(testScript);
`
.replace(/$\n^\s*/gm, " ")
.trim(); // replace ending newlines and starting spaces
return command;
}