-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomparisonManager.js
243 lines (208 loc) · 5.9 KB
/
comparisonManager.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
// Comparison Managager
//
// Can make CoverageIncrements
//
// Take a list of CoverageIncrements and get the corresponding
// code coverage and production coverage statics.
//
// Want to aggregate a set of CoverageIncrements so we can graph
var CONFIG_FILE = "config.json";
var TESTS_FILE = "covIncrements.json";
var TEST_SOURCE_DIR = "src/test/java/";
var TEST_CLASSES_DIR = "target/test-classes/";
var TEST_STORE = "testStore/";
var TEST_INCREMENTS_DIR = "tests";
var origTestDir = "";
var argv = require('yargs')
.usage('Usage: $0 -c configFile -t file -r ')
.demand('r')
.choices('r', ['full', 'cov', 'odfe', 'list', 'restore', 'csv', 'split', 'testsDir'])
.describe('r', 'run options')
.describe('c', 'config file (default config.json)')
.describe('t', 'test increments file (default covIncrements.json)')
.epilog("ODF Testing for all")
.argv;
var jsonfile = require('jsonfile');
var async = require('async');
var shelljs = require('shelljs');
var fs = require('fs-extra');
var testMover = require('./testMover');
var testRunner = require('./testRunner');
var odfeRunner = require('./odfeRunner');
var results2CSV = require('./results2CSV');
coverageInc = require('./coverageIncrement');
var configFile = CONFIG_FILE;
var testsFile = TESTS_FILE;
var testIncrementsDirectory = TEST_INCREMENTS_DIR;
var config = {};
var coverageTests = {};
//where from
var srcDir = "";
//to local directory
var trgDir = TEST_STORE;
//Given a config file?
//If not assume it is predefined -c for config
//
//Lets use a yargs to provide some command line options
// List tests
// supply test details
// List results
if (argv.c) {
configFile = argv.c;
}
// Get the list of test increments
// That is a list of tests and their associated input and output documents
if (argv.t) {
testsFile = argv.t;
}
if (argv.d) {
testIncrementsDirectory = argv.d;
}
// Control a run
// Run the maven part
// Run the ODFE part
// Full run
console.log("Production Coverage Comparison Manager");
console.log("--------------------------------------\n");
if (argv.r) {
readConfig(configFile);
readTests(testsFile);
origTestDir = config.odftoolkitProject + TEST_SOURCE_DIR + coverageTests.project;
setupTestMover();
setupTestRunner();
switch (argv.r) {
case "full":
fullTests();
break;
case "cov":
console.log("Run Coverage Tests Only");
break;
case "odfe":
console.log("Run ODFE Tests Only");
break;
case "restore":
moveThemBack();
break;
case "list":
listTests();
break;
case "csv":
generateCSVs();
break;
case "split":
splitTests();
break;
case "testsDir":
runTestsFromDir();
}
}
// Expect the configuration data in "config.json"
function readConfig(cfgFile) {
config = jsonfile.readFileSync(cfgFile);
console.log("Config Parameters Read from " + cfgFile);
console.log("ODF Toolkit: " + config.odftoolkitProject);
console.log("ODFE: " + config.odfeBaseDirectory);
console.log("\n");
}
function readTests(testsFile) {
console.log("Test increments from " + testsFile);
coverageTests = jsonfile.readFileSync(testsFile);
}
function setupTestRunner() {
testRunner.setTestsToRun(coverageTests.increments);
testRunner.setTrgDir(origTestDir);
testRunner.setSrcDir(TEST_STORE);
testRunner.setProjectDir(config.odftoolkitProject);
testRunner.setTestClassesDirectory(config.odftoolkitProject + TEST_CLASSES_DIR);
testRunner.setTestProject(coverageTests.project);
}
function setupTestMover() {
testMover.setTestsDir(origTestDir);
testMover.setStoreDir(TEST_STORE);
}
function listTests() {
console.log("Tests name: " + coverageTests.name);
console.log("Project Directory: " + coverageTests.project);
var numTests = coverageTests.increments.length;
console.log("Number of tests: " + numTests);
for (var t = 0; t < numTests; t++) {
console.log(coverageTests.increments[t].test);
}
}
// Get the original tests
// store the tests
//
// for the tests in the tests file
// run coverage
// run odfe
// restore the tests - not the ones in tests file?
// they will have been already moves anyway?
//
// First cut just simulate the coverage and odfe
//
// should this be a queue of tasks to be run
//
function fullTests() {
console.log("Run Full Tests");
//should clear out old cobertura set file
//and old Aggregations records
async.series([
testMover.getOrigTests,
testMover.moveOrigTests,
testRunner.runCoverage,
testMover.getStoredTests
// testMover.restoreTests
], fullTestsDone);
}
function moveThemBack() {
console.log("Move Tests back");
async.series([
testMover.getStoredTests,
testMover.restoreTests
], moveBackDone);
}
function fullTestsDone(err) {
if (err) {
console.log(err);
} else {
console.log("Full Test Run Completed");
}
}
function moveBackDone(err) {
if (err) {
console.log(err);
} else {
console.log("Move back Completed");
}
}
function generateCSVs() {
console.log("\nGenerate Results CSV files");
results2CSV.generate();
}
function splitTests() {
console.log("Split Tests:");
var numTests = coverageTests.increments.length;
console.log("Number of tests: " + numTests);
for (var t = 0; t < numTests; t++) {
writeSingleTestToJSON(coverageTests.increments[t]);
}
}
function writeSingleTestToJSON(entry) {
var singleTest = {};
singleTest.name = entry.test;
singleTest.project = coverageTests.project;
singleTest.increments = [];
singleTest.increments.push(entry);
jsonfile.writeFileSync("tests/" + entry.test + ".json", singleTest, {spaces: 2});
}
function runTestsFromDir() {
console.log("\Run test increments from " + testIncrementsDirectory);
var testIncrementFiles = shelljs.ls('-R', testIncrementsDirectory).filter(function (file) {
return file.match(/.json$/);
});
var numTestIncrements = testIncrementFiles.length;
console.log("Number of test increments: " + numTestIncrements);
for(var t=0; t<numTestIncrements; t++) {
console.log(t+1 + " " + testIncrementFiles[t]);
}
}