Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support parsing elements that are not part of the schema #638

Merged
merged 8 commits into from
Aug 5, 2021

Conversation

jennuine
Copy link
Collaborator

🦟 Bug fix

Fixes #603

Summary

sdf::Param::Get parses a value to a given type regardless of the typeName of the sdf::Param. Previously when typeName = "string" then sdf::Param::Get<double>("inf") would return 0, now it returns the expected value inf.

Test:

./build/sdformat9/src/UNIT_Param_TEST --gtest_filter=SetFromString.DoublePositiveInf
./build/sdformat9/src/UNIT_Param_TEST --gtest_filter=SetFromString.DoubleNegativeInf

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge

Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Copy link
Collaborator

@azeey azeey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I have some comments to help with the CI failure.

include/sdf/Param.hh Outdated Show resolved Hide resolved
src/Param.cc Outdated Show resolved Hide resolved
include/sdf/Param.hh Outdated Show resolved Hide resolved
include/sdf/Param.hh Outdated Show resolved Hide resolved
include/sdf/Param.hh Outdated Show resolved Hide resolved
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
@@ -75,11 +77,6 @@ TEST(Param, Bool)
strParam.Get<bool>(value);
EXPECT_TRUE(value);

// Anything other than 1 or true is treated as a false value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for removing this test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this section was removed:
https://github.com/ignitionrobotics/sdformat/blob/f3dbe1d225939ff1bc038b0789fff884d763cfa7/include/sdf/Param.hh#L296-L315

It now reaches this error: https://github.com/ignitionrobotics/sdformat/blob/f0f9759ec9d4572db9c5fd9e0dd861e6f679a7cf/src/Param.cc#L329

To me, it made more sense to error when a random value such as % was set rather than defaulting to false. Should I change this back?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think making it an error makes sense, but I'd like to avoid changing behavior since this is a stable version and someone wrote a test to deliberately check this behavior. Would it be possible to assign the value regardless of the error? I know printing the error is still a change in behavior but I think it's small enough not to break anything.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How's this? 650b544

This seemed to be the easiest fix. Changing ParamPrivate::ValueFromStringImpl bool section to assign the value regardless of the error and return true (since _valueToSet was successfully set) caused Param.InvalidBool test to fail

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works. Can you add a comment there saying that the piece of code handling bool types is there to keep backward behavior?

I'm thinking we should change the behavior for Fortress. Would you agree?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I'll add the comment and put a TODO to remove for Fortress

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/Param.cc Show resolved Hide resolved
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏰 citadel Ignition Citadel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support parsing "inf", "+inf", "-inf" for elements that are not part of the schema
2 participants