17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 06:19:19 +02:00

test: test vehicle definitions load with GCC and Clang

All the tests reading a definition failed on Linux with "unknown vehicle
definition section 0": the parsed definition was brace-initialised
(auto const json{parse(...)}), which GCC and Clang take for the
initializer list constructor of nlohmann::json, making an array holding
the definition, while MSVC copies it. Initialise it with =, and require
the definition to be a JSON object.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jerrrrycho
2026-10-14 22:53:22 +02:00
parent 60b0a335b0
commit 7b77e4cef8

View File

@@ -73,7 +73,11 @@ definition definition::load(std::string const &Name) {
throw std::runtime_error("no test vehicle definition " + path);
}
definition result;
auto const json{nlohmann::ordered_json::parse(file, nullptr, true, true)};
// not brace-initialised: json{other} makes an array of other with GCC and Clang (the initializer list constructor wins)
auto const json = nlohmann::ordered_json::parse(file, nullptr, true, true);
if (false == json.is_object()) {
throw std::runtime_error("test vehicle definition " + path + " isn't a JSON object");
}
for (auto const &[section, keys] : json.items()) {
// keys starting with _ are comments
if (section.starts_with('_')) {