@syntest/core
Version:
The common core of the SynTest Framework
84 lines • 3.69 kB
JavaScript
;
/*
* Copyright 2020-2021 Delft University of Technology and SynTest contributors
*
* This file is part of SynTest Framework - SynTest Core.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.SummaryWriter = void 0;
const csv = require("@fast-csv/format");
const RuntimeVariable_1 = require("./RuntimeVariable");
const fs = require("fs");
/**
* Writer for the summary statistics.
*
* @author Mitchell Olsthoorn
*/
class SummaryWriter {
constructor() {
this.VARIABLES = [
RuntimeVariable_1.RuntimeVariable.SUBJECT,
RuntimeVariable_1.RuntimeVariable.CONFIGURATION,
RuntimeVariable_1.RuntimeVariable.SEED,
RuntimeVariable_1.RuntimeVariable.ALGORITHM,
RuntimeVariable_1.RuntimeVariable.PROBE_ENABLED,
RuntimeVariable_1.RuntimeVariable.CONSTANT_POOL_ENABLED,
RuntimeVariable_1.RuntimeVariable.COVERAGE,
RuntimeVariable_1.RuntimeVariable.COVERED_BRANCHES,
RuntimeVariable_1.RuntimeVariable.TOTAL_BRANCHES,
RuntimeVariable_1.RuntimeVariable.BRANCH_COVERAGE,
RuntimeVariable_1.RuntimeVariable.COVERED_LINES,
RuntimeVariable_1.RuntimeVariable.TOTAL_LINES,
RuntimeVariable_1.RuntimeVariable.LINE_COVERAGE,
RuntimeVariable_1.RuntimeVariable.COVERED_FUNCTIONS,
RuntimeVariable_1.RuntimeVariable.TOTAL_FUNCTIONS,
RuntimeVariable_1.RuntimeVariable.FUNCTION_COVERAGE,
RuntimeVariable_1.RuntimeVariable.COVERED_PROBES,
RuntimeVariable_1.RuntimeVariable.TOTAL_PROBES,
RuntimeVariable_1.RuntimeVariable.PROBE_COVERAGE,
RuntimeVariable_1.RuntimeVariable.INITIALIZATION_TIME,
RuntimeVariable_1.RuntimeVariable.INSTRUMENTATION_TIME,
RuntimeVariable_1.RuntimeVariable.TYPE_RESOLVING_TIME,
RuntimeVariable_1.RuntimeVariable.SEARCH_TIME,
RuntimeVariable_1.RuntimeVariable.TOTAL_TIME,
RuntimeVariable_1.RuntimeVariable.ITERATIONS,
RuntimeVariable_1.RuntimeVariable.EVALUATIONS,
RuntimeVariable_1.RuntimeVariable.VERSION,
];
}
/**
* Write the summary statistics to file.
*
* @param collector The collector for the statistics
* @param filePath The file path to write to
*/
write(collector, filePath) {
const variables = collector.getVariables();
// For each enabled statistic, copy the data from the collector over
const data = {};
this.VARIABLES.forEach((variable) => {
data[RuntimeVariable_1.RuntimeVariable[variable]] = variables.get(variable);
});
// Create a write stream in append mode
const ws = fs.createWriteStream(filePath, { flags: "a" });
// Write the data to the stream and add headers when the file does not exist
csv.writeToStream(ws, [data], {
headers: !fs.existsSync(filePath),
includeEndRowDelimiter: true,
});
}
}
exports.SummaryWriter = SummaryWriter;
//# sourceMappingURL=SummaryWriter.js.map