File tests/sub_commands.cpp changed (mode: 100644) (index d79f9d4..8b67086) |
... |
... |
TEST_CASE("Empty coverage data is imported", |
1062 |
1062 |
BuildHistory bh(db); |
BuildHistory bh(db); |
1063 |
1063 |
|
|
1064 |
1064 |
auto runner = [](std::vector<std::string> &&cmd, |
auto runner = [](std::vector<std::string> &&cmd, |
1065 |
|
const std::string &/*dir*/) { |
|
|
1065 |
|
const std::string &/*from*/) { |
1066 |
1066 |
REQUIRE(cmd.size() == 4U); |
REQUIRE(cmd.size() == 4U); |
|
1067 |
|
return std::string(); |
1067 |
1068 |
}; |
}; |
1068 |
1069 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1069 |
1070 |
|
|
|
... |
... |
TEST_CASE("Coverage file is discovered", |
1097 |
1098 |
std::ofstream{gcnoFile}; |
std::ofstream{gcnoFile}; |
1098 |
1099 |
|
|
1099 |
1100 |
auto runner = [&gcnoFile](std::vector<std::string> &&cmd, |
auto runner = [&gcnoFile](std::vector<std::string> &&cmd, |
1100 |
|
const std::string &/*dir*/) { |
|
|
1101 |
|
const std::string &/*from*/) { |
1101 |
1102 |
REQUIRE(cmd.size() == 5U); |
REQUIRE(cmd.size() == 5U); |
1102 |
1103 |
CHECK(boost::ends_with(cmd[4], gcnoFile)); |
CHECK(boost::ends_with(cmd[4], gcnoFile)); |
|
1104 |
|
return std::string(); |
1103 |
1105 |
}; |
}; |
1104 |
1106 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1105 |
1107 |
|
|
|
... |
... |
TEST_CASE("Unexecuted files can be excluded", |
1127 |
1129 |
BuildHistory bh(db); |
BuildHistory bh(db); |
1128 |
1130 |
|
|
1129 |
1131 |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
1130 |
|
const std::string &/*dir*/) { |
|
|
1132 |
|
const std::string &/*from*/) { |
|
1133 |
|
return std::string(); |
1131 |
1134 |
}; |
}; |
1132 |
1135 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1133 |
1136 |
|
|
|
... |
... |
TEST_CASE("new-gcovi --prefix", "[subcommands][new-gcovi-subcommand]") |
1155 |
1158 |
BuildHistory bh(db); |
BuildHistory bh(db); |
1156 |
1159 |
|
|
1157 |
1160 |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
1158 |
|
const std::string &dir) { |
|
1159 |
|
std::ofstream{dir + "/subdir#file.gcov"} |
|
|
1161 |
|
const std::string &from) { |
|
1162 |
|
std::ofstream{from + "/subdir#file.gcov"} |
1160 |
1163 |
<< "file:file.cpp\n"; |
<< "file:file.cpp\n"; |
|
1164 |
|
return std::string(); |
1161 |
1165 |
}; |
}; |
1162 |
1166 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1163 |
1167 |
|
|
|
... |
... |
TEST_CASE("Executed files can be excluded", |
1186 |
1190 |
BuildHistory bh(db); |
BuildHistory bh(db); |
1187 |
1191 |
|
|
1188 |
1192 |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
1189 |
|
const std::string &dir) { |
|
1190 |
|
std::ofstream{dir + "/subdir#file.gcov"} |
|
|
1193 |
|
const std::string &from) { |
|
1194 |
|
std::ofstream{from + "/subdir#file.gcov"} |
1191 |
1195 |
<< "file:subdir/file.cpp\n"; |
<< "file:subdir/file.cpp\n"; |
|
1196 |
|
return std::string(); |
1192 |
1197 |
}; |
}; |
1193 |
1198 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1194 |
1199 |
|
|
|
... |
... |
TEST_CASE("Gcov file is found and parsed", |
1217 |
1222 |
BuildHistory bh(db); |
BuildHistory bh(db); |
1218 |
1223 |
|
|
1219 |
1224 |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
1220 |
|
const std::string &dir) { |
|
|
1225 |
|
const std::string &from) { |
|
1226 |
|
std::string json = R"({ |
|
1227 |
|
"current_working_directory": "./", |
|
1228 |
|
"files": [{ |
|
1229 |
|
"file": "test-file1.cpp", |
|
1230 |
|
"lines": [ |
|
1231 |
|
{ "line_number": 2, "count": 1 }, |
|
1232 |
|
{ "line_number": 4, "count": 1 } |
|
1233 |
|
] |
|
1234 |
|
}] |
|
1235 |
|
})"; |
|
1236 |
|
|
1221 |
1237 |
GcovInfo gcovInfo; |
GcovInfo gcovInfo; |
1222 |
|
if (gcovInfo.hasJsonFormat()) { |
|
1223 |
|
makeGz(dir + "/test-file1.gcno.gcov.json.gz", R"({ |
|
1224 |
|
"current_working_directory": "./", |
|
1225 |
|
"files": [{ |
|
1226 |
|
"file": "test-file1.cpp", |
|
1227 |
|
"lines": [ |
|
1228 |
|
{ "line_number": 2, "count": 1 }, |
|
1229 |
|
{ "line_number": 4, "count": 1 } |
|
1230 |
|
] |
|
1231 |
|
}] |
|
1232 |
|
})"); |
|
|
1238 |
|
if (from == "-") { |
|
1239 |
|
removeChars(json, '\n'); |
|
1240 |
|
return json; |
|
1241 |
|
} else if (gcovInfo.hasJsonFormat()) { |
|
1242 |
|
makeGz(from + "/test-file1.gcno.gcov.json.gz", json); |
1233 |
1243 |
} else { |
} else { |
1234 |
|
std::ofstream{dir + "/test-file1.gcov"} |
|
|
1244 |
|
std::ofstream{from + "/test-file1.gcov"} |
1235 |
1245 |
<< "file:test-file1.cpp\n" |
<< "file:test-file1.cpp\n" |
1236 |
1246 |
<< "lcount:2,1\n" |
<< "lcount:2,1\n" |
1237 |
1247 |
<< "lcount:4,1\n"; |
<< "lcount:4,1\n"; |
1238 |
1248 |
} |
} |
|
1249 |
|
|
|
1250 |
|
return std::string(); |
1239 |
1251 |
}; |
}; |
1240 |
1252 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1241 |
1253 |
|
|
|
... |
... |
TEST_CASE("Gcov file with broken format causes an exception", |
1260 |
1272 |
BuildHistory bh(db); |
BuildHistory bh(db); |
1261 |
1273 |
|
|
1262 |
1274 |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
1263 |
|
const std::string &dir) { |
|
|
1275 |
|
const std::string &from) { |
|
1276 |
|
std::string json = R"({ |
|
1277 |
|
"files": [{ |
|
1278 |
|
"file": "test-file1.cpp", |
|
1279 |
|
"lines": [ { "line_number": 2, "count": 0 }, ] |
|
1280 |
|
}] |
|
1281 |
|
})"; |
|
1282 |
|
|
1264 |
1283 |
GcovInfo gcovInfo; |
GcovInfo gcovInfo; |
1265 |
|
if (gcovInfo.hasJsonFormat()) { |
|
1266 |
|
makeGz(dir + "/test-file1.gcno.gcov.json.gz", R"({ |
|
1267 |
|
"files": [{ |
|
1268 |
|
"file": "test-file1.cpp", |
|
1269 |
|
"lines": [ { "line_number": 2, "count": 0 }, ] |
|
1270 |
|
}] |
|
1271 |
|
})"); |
|
|
1284 |
|
if (from == "-") { |
|
1285 |
|
removeChars(json, '\n'); |
|
1286 |
|
return json; |
|
1287 |
|
} else if (gcovInfo.hasJsonFormat()) { |
|
1288 |
|
makeGz(from + "/test-file1.gcno.gcov.json.gz", json); |
1272 |
1289 |
} else { |
} else { |
1273 |
|
std::ofstream{dir + "/test-file1.gcov"} |
|
|
1290 |
|
std::ofstream{from + "/test-file1.gcov"} |
1274 |
1291 |
<< "file:test-file1.cpp\n" |
<< "file:test-file1.cpp\n" |
1275 |
1292 |
<< "lcount:2\n"; |
<< "lcount:2\n"; |
1276 |
1293 |
} |
} |
|
1294 |
|
|
|
1295 |
|
return std::string(); |
1277 |
1296 |
}; |
}; |
1278 |
1297 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1279 |
1298 |
|
|
|
... |
... |
TEST_CASE("Modified source file is captured", |
1305 |
1324 |
std::ofstream{sourceFile} << "int f() { return 666; }"; |
std::ofstream{sourceFile} << "int f() { return 666; }"; |
1306 |
1325 |
|
|
1307 |
1326 |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
1308 |
|
const std::string &/*dir*/) { |
|
|
1327 |
|
const std::string &/*from*/) { |
|
1328 |
|
return std::string(); |
1309 |
1329 |
}; |
}; |
1310 |
1330 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1311 |
1331 |
|
|
|
... |
... |
TEST_CASE("Untracked source file is captured", |
1340 |
1360 |
std::ofstream{untrackedFile}; |
std::ofstream{untrackedFile}; |
1341 |
1361 |
|
|
1342 |
1362 |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
1343 |
|
const std::string &/*dir*/) { |
|
|
1363 |
|
const std::string &/*from*/) { |
|
1364 |
|
return std::string(); |
1344 |
1365 |
}; |
}; |
1345 |
1366 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1346 |
1367 |
|
|
|
... |
... |
TEST_CASE("Untracked source file is rejected without capture", |
1377 |
1398 |
std::ofstream{untrackedFile}; |
std::ofstream{untrackedFile}; |
1378 |
1399 |
|
|
1379 |
1400 |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
1380 |
|
const std::string &/*dir*/) { |
|
|
1401 |
|
const std::string &/*from*/) { |
|
1402 |
|
return std::string(); |
1381 |
1403 |
}; |
}; |
1382 |
1404 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1383 |
1405 |
|
|
|
... |
... |
TEST_CASE("Unmatched source fails build addition", |
1409 |
1431 |
std::ofstream{sourceFile} << "int f() { return 666; }"; |
std::ofstream{sourceFile} << "int f() { return 666; }"; |
1410 |
1432 |
|
|
1411 |
1433 |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
1412 |
|
const std::string &/*dir*/) { |
|
|
1434 |
|
const std::string &/*from*/) { |
|
1435 |
|
return std::string(); |
1413 |
1436 |
}; |
}; |
1414 |
1437 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1415 |
1438 |
|
|
|
... |
... |
TEST_CASE("new-gcovi --help", "[subcommands][new-gcovi-subcommand]") |
1431 |
1454 |
BuildHistory bh(db); |
BuildHistory bh(db); |
1432 |
1455 |
|
|
1433 |
1456 |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
1434 |
|
const std::string &/*dir*/) { |
|
|
1457 |
|
const std::string &/*from*/) { |
|
1458 |
|
return std::string(); |
1435 |
1459 |
}; |
}; |
1436 |
1460 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1437 |
1461 |
|
|
|
... |
... |
TEST_CASE("new-gcovi --ref-name", "[subcommands][new-gcovi-subcommand]") |
1457 |
1481 |
BuildHistory bh(db); |
BuildHistory bh(db); |
1458 |
1482 |
|
|
1459 |
1483 |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
1460 |
|
const std::string &/*dir*/) { |
|
|
1484 |
|
const std::string &/*from*/) { |
|
1485 |
|
return std::string(); |
1461 |
1486 |
}; |
}; |
1462 |
1487 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1463 |
1488 |
|
|
|
... |
... |
TEST_CASE("new-gcovi --capture-worktree can be noop", |
1486 |
1511 |
BuildHistory bh(db); |
BuildHistory bh(db); |
1487 |
1512 |
|
|
1488 |
1513 |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
1489 |
|
const std::string &/*dir*/) { |
|
|
1514 |
|
const std::string &/*from*/) { |
|
1515 |
|
return std::string(); |
1490 |
1516 |
}; |
}; |
1491 |
1517 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1492 |
1518 |
|
|
|
... |
... |
TEST_CASE("new-gcovi --verbose", "[subcommands][new-gcovi-subcommand]") |
1517 |
1543 |
std::ofstream{untrackedFile}; |
std::ofstream{untrackedFile}; |
1518 |
1544 |
|
|
1519 |
1545 |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
auto runner = [](std::vector<std::string> &&/*cmd*/, |
1520 |
|
const std::string &/*dir*/) { |
|
|
1546 |
|
const std::string &/*from*/) { |
|
1547 |
|
return std::string(); |
1521 |
1548 |
}; |
}; |
1522 |
1549 |
GcovImporter::setRunner(runner); |
GcovImporter::setRunner(runner); |
1523 |
1550 |
|
|