mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-07 23:42:29 +01: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:
@@ -73,7 +73,11 @@ definition definition::load(std::string const &Name) {
|
|||||||
throw std::runtime_error("no test vehicle definition " + path);
|
throw std::runtime_error("no test vehicle definition " + path);
|
||||||
}
|
}
|
||||||
definition result;
|
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()) {
|
for (auto const &[section, keys] : json.items()) {
|
||||||
// keys starting with _ are comments
|
// keys starting with _ are comments
|
||||||
if (section.starts_with('_')) {
|
if (section.starts_with('_')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user