summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-12-05 17:26:03 +0200
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-12-09 17:53:34 +0200
commit3d0001642ba2d6290252f05592d54fd928f56b63 (patch)
treea1fbdbb54f788ea7a038fba4d17b50c2d66bd4d6
parent7eee124677983a01bbbddaa8005b399c277df5dd (diff)
downloadqtlocation-mapboxgl-3d0001642ba2d6290252f05592d54fd928f56b63.tar.gz
[test-runner] Simplify update option and remove obsolete ifdefs
-rw-r--r--render-test/render_test.cpp37
-rw-r--r--render-test/runner.cpp8
2 files changed, 12 insertions, 33 deletions
diff --git a/render-test/render_test.cpp b/render-test/render_test.cpp
index 89536a0605..163c148291 100644
--- a/render-test/render_test.cpp
+++ b/render-test/render_test.cpp
@@ -41,30 +41,14 @@ void operator delete(void* ptr, size_t) noexcept {
namespace {
-template <typename T>
-TestRunner::UpdateResults initUpdateResults(T& testUpdateResultsValue) {
- if (!testUpdateResultsValue) {
-#if !TEST_READ_ONLY
- if (getenv("UPDATE_DEFAULT")) return TestRunner::UpdateResults::DEFAULT;
- if (getenv("UPDATE_PLATFORM")) return TestRunner::UpdateResults::PLATFORM;
- if (getenv("UPDATE_METRICS")) return TestRunner::UpdateResults::METRICS;
-#endif
- return TestRunner::UpdateResults::NO;
- }
- std::string str = args::get(testUpdateResultsValue);
-#if !TEST_READ_ONLY
- if (str == "default") return TestRunner::UpdateResults::DEFAULT;
- if (str == "platform") return TestRunner::UpdateResults::PLATFORM;
- if (str == "metrics") return TestRunner::UpdateResults::METRICS;
-#endif
- mbgl::Log::Warning(
- mbgl::Event::General, "Unsupported update test results mode: \"%s\" will be ignored", str.c_str());
- return TestRunner::UpdateResults::NO;
-}
-
using ArgumentsTuple =
std::tuple<bool, bool, uint32_t, std::string, TestRunner::UpdateResults, std::vector<std::string>, std::string>;
ArgumentsTuple parseArguments(int argc, char** argv) {
+ const static std::unordered_map<std::string, TestRunner::UpdateResults> updateResultsFlags = {
+ {"default", TestRunner::UpdateResults::DEFAULT},
+ {"platform", TestRunner::UpdateResults::PLATFORM},
+ {"metrics", TestRunner::UpdateResults::METRICS}};
+
args::ArgumentParser argumentParser("Mapbox GL Test Runner");
args::HelpFlag helpFlag(argumentParser, "help", "Display this help menu", {'h', "help"});
@@ -75,11 +59,13 @@ ArgumentsTuple parseArguments(int argc, char** argv) {
args::ValueFlag<std::string> testPathValue(
argumentParser, "manifestPath", "Test manifest file path", {'p', "manifestPath"});
args::ValueFlag<std::string> testFilterValue(argumentParser, "filter", "Test filter regex", {'f', "filter"});
- args::ValueFlag<std::string> testUpdateResultsValue(
+ args::MapFlag<std::string, TestRunner::UpdateResults> testUpdateResultsValue(
argumentParser,
"update",
"Test results update mode. Supported values are: \"default\", \"platform\", \"metrics\"",
- {'u', "update"});
+ {'u', "update"},
+ updateResultsFlags);
+
args::PositionalList<std::string> testNameValues(argumentParser, "URL", "Test name(s)");
try {
@@ -108,14 +94,15 @@ ArgumentsTuple parseArguments(int argc, char** argv) {
mbgl::Log::Error(mbgl::Event::General,
"Provided test manifest file path '%s' does not exist",
manifestPath.string().c_str());
- exit(4);
+ exit(3);
}
auto testNames = testNameValues ? args::get(testNameValues) : std::vector<std::string>{};
auto testFilter = testFilterValue ? args::get(testFilterValue) : std::string{};
const auto shuffle = shuffleFlag ? args::get(shuffleFlag) : false;
const auto seed = seedValue ? args::get(seedValue) : 1u;
- TestRunner::UpdateResults updateResults = initUpdateResults(testUpdateResultsValue);
+ TestRunner::UpdateResults updateResults =
+ testUpdateResultsValue ? args::get(testUpdateResultsValue) : TestRunner::UpdateResults::NO;
return ArgumentsTuple{recycleMapFlag ? args::get(recycleMapFlag) : false,
shuffle,
seed,
diff --git a/render-test/runner.cpp b/render-test/runner.cpp
index 67cc3aea0d..953576cf78 100644
--- a/render-test/runner.cpp
+++ b/render-test/runner.cpp
@@ -186,7 +186,6 @@ bool TestRunner::checkQueryTestResults(mbgl::PremultipliedImage&& actualImage,
return false;
}
-#if !TEST_READ_ONLY
if (updateResults == UpdateResults::PLATFORM) {
mbgl::filesystem::create_directories(expectations.back());
mbgl::util::write_file(expectations.back().string() + "/expected.json", metadata.actualJson);
@@ -197,7 +196,6 @@ bool TestRunner::checkQueryTestResults(mbgl::PremultipliedImage&& actualImage,
}
mbgl::util::write_file(base + "/actual.json", metadata.actualJson);
-#endif
std::vector<std::string> expectedJsonPaths;
mbgl::filesystem::path expectedMetricsPath;
@@ -256,7 +254,6 @@ bool TestRunner::checkRenderTestResults(mbgl::PremultipliedImage&& actualImage,
return false;
}
-#if !TEST_READ_ONLY
if (updateResults == UpdateResults::PLATFORM) {
mbgl::filesystem::create_directories(expectations.back());
mbgl::util::write_file(expectations.back().string() + "/expected.png", mbgl::encodePNG(actualImage));
@@ -267,7 +264,6 @@ bool TestRunner::checkRenderTestResults(mbgl::PremultipliedImage&& actualImage,
}
mbgl::util::write_file(base + "/actual.png", metadata.actual);
-#endif
mbgl::PremultipliedImage expectedImage{actualImage.size};
mbgl::PremultipliedImage imageDiff{actualImage.size};
@@ -307,9 +303,7 @@ bool TestRunner::checkRenderTestResults(mbgl::PremultipliedImage&& actualImage,
metadata.diff = mbgl::encodePNG(imageDiff);
-#if !TEST_READ_ONLY
mbgl::util::write_file(base + "/diff.png", metadata.diff);
-#endif
metadata.difference = pixels / expectedImage.size.area();
if (metadata.difference <= metadata.allowed) {
@@ -323,13 +317,11 @@ bool TestRunner::checkRenderTestResults(mbgl::PremultipliedImage&& actualImage,
bool TestRunner::checkProbingResults(TestMetadata& metadata) {
if (metadata.metrics.isEmpty()) return true;
const std::vector<mbgl::filesystem::path>& expectedMetrics = metadata.paths.expectedMetrics;
-#if !TEST_READ_ONLY
if (updateResults == UpdateResults::METRICS) {
mbgl::filesystem::create_directories(expectedMetrics.back());
mbgl::util::write_file(expectedMetrics.back().string() + "/metrics.json", serializeMetrics(metadata.metrics));
return true;
}
-#endif
// Check the possible paths in reverse order, so that the default path with the test style will only be checked in
// the very end.