Make sure modes are sorted in ModeInfo (#7097)
authorGereon Kremer <nafur42@gmail.com>
Tue, 31 Aug 2021 19:27:55 +0000 (12:27 -0700)
committerGitHub <noreply@github.com>
Tue, 31 Aug 2021 19:27:55 +0000 (19:27 +0000)
This PR ensures that the possible modes returned in getOptionInfo() are always sorted. Their order would depend on the python dictionary ordering, which changed with a somewhat recent python version and thereby breaks our tests.

src/options/mkoptions.py
test/unit/api/solver_black.cpp

index 41f2ef543d7d2b35190a12d60eb5f0f53000ec19..30c2fc1c34392bdfbeabd473616b7bd5c14d9f29 100644 (file)
@@ -806,7 +806,7 @@ def codegen_all_modules(modules, build_dir, dst_dir, tpls):
                     elif option.type == 'double' or is_numeric_cpp_type(option.type):
                         constr = 'OptionInfo::NumberInfo<{type}>{{{default}, {value}, {minimum}, {maximum}}}'.format(**fmt)
                     elif option.mode:
-                        values = ', '.join(map(lambda s: '"{}"'.format(s), option.mode.keys()))
+                        values = ', '.join(map(lambda s: '"{}"'.format(s), sorted(option.mode.keys())))
                         assert(option.default)
                         constr = 'OptionInfo::ModeInfo{{"{default}", {value}, {{ {modes} }}}}'.format(**fmt, modes=values)
                     else:
index df4b42ca66bf9c7a2bf4a163f39586532fcd5a61..1daa3fba4e481689a4f0351eeb72d938891e3de0 100644 (file)
@@ -1371,7 +1371,7 @@ TEST_F(TestApiBlackSolver, getOptionInfo)
     auto modeInfo = std::get<OptionInfo::ModeInfo>(info.valueInfo);
     EXPECT_EQ("NONE", modeInfo.defaultValue);
     EXPECT_EQ("OutputTag::NONE", modeInfo.currentValue);
-    std::vector<std::string> modes{"NONE", "INST", "SYGUS", "TRIGGER"};
+    std::vector<std::string> modes{"INST", "NONE", "SYGUS", "TRIGGER"};
     EXPECT_EQ(modes, modeInfo.modes);
   }
 }