Skip to content

Commit

Permalink
Merge pull request #57 from jwnimmer-tri/22370
Browse files Browse the repository at this point in the history
fixup
  • Loading branch information
RussTedrake authored Jan 2, 2025
2 parents fd88e8c + d07173e commit 9fef6a2
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions multibody/parsing/test/detail_mujoco_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ class MujocoParserTest : public test::DiagnosticPolicyTestBase {
"drake/multibody/parsing/test/box_package/urdfs/box.urdf"))};
};

// Given a name for a TEST_SUITE_P test case, returns a safe version of the
// string (i.e., with only alphanumeric characters). Google Test case names
// must not contain any other kinds of characters.
std::string MakeSafeTestCaseName(std::string_view name) {
std::string result{name};
std::replace_if(
result.begin(), result.end(),
[](char c) {
return !std::isalnum(c);
},
'_');
return result;
}

class DeepMindControlTest : public MujocoParserTest,
public testing::WithParamInterface<const char*> {};

Expand All @@ -142,7 +156,14 @@ const char* dm_control_models[] = {
"pendulum", "point_mass", "quadruped", "reacher", "stacker",
"swimmer", "walker"};
INSTANTIATE_TEST_SUITE_P(DeepMindControl, DeepMindControlTest,
testing::ValuesIn(dm_control_models));
testing::ValuesIn(dm_control_models),
([](const auto& test_info) {
// This lambda provides a nice human-readable test
// case name while running the test, or in case the
// test case fails.
const auto& model = test_info.param;
return MakeSafeTestCaseName(model);
}));

class MujocoMenagerieTest
: public MujocoParserTest,
Expand Down Expand Up @@ -319,8 +340,14 @@ const std::pair<const char*, const char*> mujoco_menagerie_models[] = {
};

INSTANTIATE_TEST_SUITE_P(MujocoMenagerie, MujocoMenagerieTest,
testing::ValuesIn(mujoco_menagerie_models));

testing::ValuesIn(mujoco_menagerie_models),
([](const auto& test_info) {
// This lambda provides a nice human-readable test
// case name while running the test, or in case the
// test case fails.
const auto& [model, error_regex] = test_info.param;
return MakeSafeTestCaseName(model);
}));

// In addition to confirming that the parser can successfully parse the model,
// this test can be used to manually inspect the resulting visualization.
Expand Down

0 comments on commit 9fef6a2

Please sign in to comment.