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

test: add cctest for native URL class #12042

Closed
wants to merge 1 commit into from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Mar 25, 2017

Adds a cctest for the new native URL class

Depends on: #11801 and #11956

/cc @bmeck @TimothyGu

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

url, test

@jasnell jasnell added dont-land-on-v4.x whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Mar 25, 2017
@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to build files or the CI. c++ Issues and PRs that require attention from people who are familiar with C++. dont-land-on-v4.x whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Mar 25, 2017
@mscdex mscdex added test Issues and PRs related to the tests. and removed build Issues and PRs related to build files or the CI. labels Mar 26, 2017

URL simple("https://example.org:81/a/b/c?query#fragment");

CHECK_EQ(simple.protocol().compare("https:"), 0);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Why not CHECK_EQ(simple.protocol(), "https:");?

#include "gtest/gtest.h"

TEST(URLTest, Simple) {
using node::url::URL;
Copy link
Member

Choose a reason for hiding this comment

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

I’d just put this once at the top level instead of having it in each test, tbh

@jasnell jasnell force-pushed the native-url-test branch 2 times, most recently from e62c36f to 6d369a1 Compare March 27, 2017 01:45
@jasnell
Copy link
Member Author

jasnell commented Mar 27, 2017

TEST_F(URLTest, Simple) {
URL simple("https://example.org:81/a/b/c?query#fragment");

CHECK_EQ(simple.protocol(), "https:");
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering for future reference if it is preferred to use CHECK_EQ instead of EXPECT_EQ?
The difference seems to be that CHECK_EQ will abort straight away without allowing for the rest of the tests to be run, whereas EXPECT_EQ which is non-fatal and would allow for the rest of the tests to be run and report the errors afterwards.

For example, using CHECK_EQ and forcing a check to fail:

[ RUN      ] URLTest.Simple
Assertion failed: ((simple.protocol()) == ("httpsss")), function TestBody, file ../test/cctest/test_url.cc, line 23.
make: *** [cctest] Abort trap: 6

Compared to EXPECT_EQ, and forcing a the expectation to fail:

[ RUN      ] URLTest.Simple
../test/cctest/test_url.cc:24: Failure
Value of: "httpss:"
Expected: simple.protocol()
Which is: "https:"
[  FAILED  ] URLTest.Simple (13 ms)
...
[  PASSED  ] 36 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] URLTest.Simple

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I'd actually forgotten that EXPECT_EQ existed :-) I'll switch it up to use that instead.

@@ -492,7 +492,7 @@ enum url_error_cb_args {
#define XX(name) name,
ERR_ARGS(XX)
#undef XX
} url_error_cb_args;
};
Copy link
Member

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 this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, when node_url.h is included in the cctest/test_url.h, a compile error occurs because the url_error_cb_args is defined multiple times. I had to make similar changes to the other structs defined in this file. It would likely be good to refactor the node_url.h file a bit if we intend for it to be generally includable in more than just node_url.cc.

@jasnell
Copy link
Member Author

jasnell commented Mar 27, 2017

@jasnell
Copy link
Member Author

jasnell commented Mar 27, 2017

CI failures are unrelated.

jasnell added a commit that referenced this pull request Mar 27, 2017
PR-URL: #12042
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
@jasnell
Copy link
Member Author

jasnell commented Mar 27, 2017

Landed in 51b007a

@jasnell jasnell closed this Mar 27, 2017
@jasnell jasnell reopened this Mar 27, 2017
@addaleax
Copy link
Member

@jasnell Reopened by accident?

@jasnell
Copy link
Member Author

jasnell commented Mar 27, 2017

Yep lol.

@jasnell jasnell closed this Mar 27, 2017
@MylesBorins
Copy link
Member

This needs a manual backport to v7.x

@aqrln
Copy link
Contributor

aqrln commented Apr 11, 2017

@MylesBorins it will cherry-pick cleanly after #12321.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. test Issues and PRs related to the tests. whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet