Skip to content

additional unittest for aliases#567

Closed
rhaschke wants to merge 2 commits intojbeder:masterfrom
rhaschke:issue-alias-access
Closed

additional unittest for aliases#567
rhaschke wants to merge 2 commits intojbeder:masterfrom
rhaschke:issue-alias-access

Conversation

@rhaschke
Copy link
Copy Markdown

I'm having trouble with accessing values in a yaml file like this:

A: &DEFAULT
  str: string
  float: 3.1415
  int: 42
B: *DEFAULT

For some reason, in my application, accessing values B[key] fails, while A[key] succeeds. For this reason, I thought there might be an issue in yaml-cpp and implemented appropriate unittests with a minimal example. However, the unittests work as expected. Now idea, how to proceed now...
Nevertheless, the unittests might be interesting to you anyway. If haven't found particular tests for aliases/references.

Copy link
Copy Markdown
Owner

@jbeder jbeder left a comment

Choose a reason for hiding this comment

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

I don't know what the issue might be with your application, but thanks for these tests. A few minor comments.

}

TEST(LoadNodeTest, AliasAccessStream) {
std::ifstream input("integration/alias.yaml");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

No need to have this separate file-based loading; it causes various problems like worrying about working directories, etc.

Instead, if you're worried about flow vs. block, then you can keep the alias_access function and have two tests; otherwise, one test is fine.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Feel free to to adapt and use only what you need.
While tracking down the issue, I tried variation along many directions. One was to load from an input...

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Do you mean you're abandoning this PR?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If you don't think, it's useful, yes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I do think it's useful, and I added some comments before approval.

EXPECT_TRUE(b.IsScalar());

// a and b should be identical
EXPECT_STREQ(a.as<std::string>().c_str(), b.as<std::string>().c_str());
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

You can just expect that they're equal; you don't need to convert to c_str.

EXPECT_EQ(3, i);
}

static void alias_access(Node&& doc) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

If you do keep this function (see below):

  • change its name to camel case
  • put it in an anonymous namespace instead of being static
  • make it take a const ref instead of an rvalue reference
  • call it something that indicates it does some assertions, like VerifyAliasAccess

@rhaschke rhaschke force-pushed the issue-alias-access branch from 5a4fbb8 to 67bd615 Compare March 17, 2018 13:49
@hofbi hofbi mentioned this pull request Sep 4, 2018
Copy link
Copy Markdown
Owner

@jbeder jbeder left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. A couple minor comments, and I think this looks good.


add_test(yaml-test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/run-tests)
add_test(NAME yaml-test COMMAND run-tests
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This shouldn't be necessary since you're not using files, right?

ASSERT_TRUE(B);
ASSERT_TRUE(B.IsMap());

// A and B have the same content
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think A and B are actually the same node, so you can just check

ASSERT_TRUE(A.is(B));

or

ASSERT_TRUE(A == B);

(which is the same thing).

@rhaschke
Copy link
Copy Markdown
Author

Dear @jbeder,

please feel free to modify the pull request to your liking and merge the result. I myself abandoned the use of this library due to #568.

@jbeder jbeder closed this Feb 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants