Commit 8113d8bd authored by Alberto Mardegan's avatar Alberto Mardegan
Browse files

build: add testing infrastructure

parent 0a1acb51
......@@ -4,6 +4,9 @@ import qbs.Environment
Project {
name: "Lomiri VNC"
property bool buildTests: false
property bool enableCoverage: false
property string packageName: "it.mardy.lomiri-vnc"
property string version: "0.1"
......@@ -99,4 +102,13 @@ Project {
]
}
}
references: [
"tests/tests.qbs",
]
AutotestRunner {
name: "check"
Depends { productTypes: ["coverage-clean"] }
}
}
import qbs
Product {
name: "coverage-clean"
builtByDefault: false
files: ["**"]
type: ["coverage-clean"]
Rule {
multiplex: true
outputFileTags: "coverage-clean"
requiresInputs: false
prepare: {
var cleanCmd = new Command("find", [
project.sourceDirectory,
"-type", "f",
"(",
"-name", "*.gcda",
"-o",
"-name", "coverage.info",
")",
"-delete",
]);
cleanCmd.description = "Clearing coverage data";
cleanCmd.highlight = "coverage";
cleanCmd.silent = false;
return [cleanCmd];
}
}
}
import qbs
Product {
name: "coverage"
property string outputDirectory: "coverage-html"
property stringList extractPatterns: []
builtByDefault: false
files: ["**"]
type: ["coverage.html"]
Depends { productTypes: ["autotest-result"] }
Rule {
multiplex: true
explicitlyDependsOnFromDependencies: ["autotest-result"]
outputFileTags: "coverage.html"
requiresInputs: false
prepare: {
var commands = []
var captureCmd = new Command("lcov", [
"--directory", project.sourceDirectory,
"--capture",
"--output-file", "coverage.info",
"--no-checksum",
"--compat-libtool",
]);
captureCmd.description = "Collecting coverage data";
captureCmd.highlight = "coverage";
captureCmd.silent = false;
commands.push(captureCmd);
var extractArgs = []
for (var i = 0; i < product.extractPatterns.length; i++) {
extractArgs.push("--extract");
extractArgs.push("coverage.info");
extractArgs.push(product.extractPatterns[i]);
}
if (product.extractPatterns.length > 0) {
extractArgs.push("-o");
extractArgs.push("coverage.info");
var extractCmd = new Command("lcov", extractArgs);
extractCmd.description = "Extracting coverage data";
extractCmd.highlight = "coverage";
extractCmd.silent = false;
commands.push(extractCmd);
}
var filterCmd = new Command("lcov", [
"--remove", "coverage.info", 'moc_*.cpp',
"--remove", "coverage.info", 'qrc_*.cpp',
"--remove", "coverage.info", '*/tests/*',
"-o", "coverage.info",
]);
filterCmd.description = "Filtering coverage data";
filterCmd.highlight = "coverage";
filterCmd.silent = false;
commands.push(filterCmd);
var genhtmlCmd = new Command("genhtml", [
"--prefix", project.sourceDirectory,
"--output-directory", product.outputDirectory,
"--title", "Code coverage",
"--legend",
"--show-details",
"coverage.info",
]);
genhtmlCmd.description = "Generate HTML coverage report";
genhtmlCmd.highlight = "coverage";
genhtmlCmd.silent = false;
commands.push(genhtmlCmd);
return commands;
}
}
}
import qbs
Product {
files: ["**"]
type: ["application", "autotest"]
cpp.cxxFlags: {
if (project.enableCoverage) {
return ["--coverage"]
}
}
cpp.cxxLanguageVersion: "c++14"
cpp.debugInformation: true
cpp.dynamicLibraries: project.enableCoverage ? ["gcov"] : undefined
cpp.includePaths: [project.sourceDirectory + '/src']
Depends { name: 'cpp' }
Depends { name: 'Qt.core' }
Depends { name: 'Qt.gui' }
Depends { name: 'Qt.test' }
}
import qbs 1.0
Project {
condition: project.buildTests
CoverageClean {
condition: project.enableCoverage
}
CoverageReport {
condition: project.enableCoverage
extractPatterns: [ '*/src/*.cpp' ]
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment