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

tools: enforce two arguments in assert.throws #12270

Merged
merged 2 commits into from Apr 13, 2017

Conversation

Projects
None yet
7 participants
@targos
Copy link
Member

commented Apr 7, 2017

First commit adds a RegExp argument to the remaining places where it is missing in preparation for the second commit that enforces the presence of at least two arguments in assert.throws().

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)

test, tools

@targos targos requested a review from Trott Apr 7, 2017

@cjihrig

cjihrig approved these changes Apr 7, 2017

@mscdex mscdex added the assert label Apr 7, 2017

test/addons-napi/test_constructor/test.js Outdated
assert.throws(() => { test_object.readonlyValue = 3; });
const expected = new RegExp(
'^TypeError: Cannot assign to read only property \'readonlyValue\' of ' +
'object \'#<MyObject>\'$'

This comment has been minimized.

Copy link
@jasongin

jasongin Apr 7, 2017

Contributor

Matching the complete error message seems fragile. What if V8 changes the wording of the error message?

Would matching the type of error object be sufficient, using the overload of assert.throws() that takes a constructor?

assert.throws(() => { /* some code that throws a TypeError */ }, TypeError);
test/parallel/test-assert-checktag.js Outdated
@@ -45,7 +45,8 @@ function re(literals, ...values) {
}
assert.doesNotThrow(() => assert.deepEqual(fakeGlobal, global));
// Message will be truncated anyway, don't validate
assert.throws(() => assert.deepStrictEqual(fakeGlobal, global));
assert.throws(() => assert.deepStrictEqual(fakeGlobal, global),
/^AssertionError: /);

This comment has been minimized.

Copy link
@jasongin

jasongin Apr 7, 2017

Contributor

As above, consider just passing the AssertionError constructor here instead of a regexp.

This comment has been minimized.

Copy link
@targos

targos Apr 7, 2017

Author Member

Will do. I actually tried to put AssertionError first but realized it's not globally available. Your comment made me look closer and I saw that it is exported by the assert module.

@Trott

Trott approved these changes Apr 7, 2017

Copy link
Member

left a comment

LGTM (with changes suggested by @jasongin). I'm slightly bummed about this, though, because I was going to hand all these changes out at Code + Learn later this month. :-D

@targos targos force-pushed the targos:assert-throws-requiretwo branch 2 times, most recently Apr 10, 2017

@targos

This comment has been minimized.

Copy link
Member Author

commented Apr 10, 2017

targos added some commits Apr 7, 2017

test: add second argument to assert.throws
This adds RegExp or error constructor arguments to the remaining places
where it is missing in preparation for the commit that will enforce the
presence of at least two arguments.

PR-URL: #12270
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
tools: enforce two arguments in assert.throws
Enables the requireTwo option of our custom rule.

PR-URL: #12270
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>

@targos targos force-pushed the targos:assert-throws-requiretwo branch to a4b9c58 Apr 13, 2017

@targos targos merged commit a4b9c58 into nodejs:master Apr 13, 2017

@targos targos deleted the targos:assert-throws-requiretwo branch Apr 13, 2017

@jasnell jasnell referenced this pull request May 11, 2017

Closed

8.0.0 Release Proposal #12220

@gibfahn gibfahn referenced this pull request Jun 15, 2017

Closed

Auditing for 6.11.1 #230

2 of 3 tasks complete
@gibfahn

This comment has been minimized.

Copy link
Member

commented Jun 18, 2017

Should this be backported to v6.x-staging? If yes please follow the guide and raise a backport PR, if no let me know or add the dont-land-on label.

@gibfahn

This comment has been minimized.

Copy link
Member

commented Jun 18, 2017

@targos when you merge multiple commits, could you still comment with Landed in HASH1 and HASH2 as per the Collaborator Guide?

@targos

This comment has been minimized.

Copy link
Member Author

commented Jun 19, 2017

Backport PR: #13785

gibfahn added a commit that referenced this pull request Jun 19, 2017

test: add second argument to assert.throws
This adds RegExp or error constructor arguments to the remaining places
where it is missing in preparation for the commit that will enforce the
presence of at least two arguments.

PR-URL: #12270
Backport-PR-URL: #13785
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>

gibfahn added a commit that referenced this pull request Jun 19, 2017

tools: enforce two arguments in assert.throws
Enables the requireTwo option of our custom rule.

PR-URL: #12270
Backport-PR-URL: #13785
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>

gibfahn added a commit that referenced this pull request Jun 20, 2017

test: add second argument to assert.throws
This adds RegExp or error constructor arguments to the remaining places
where it is missing in preparation for the commit that will enforce the
presence of at least two arguments.

PR-URL: #12270
Backport-PR-URL: #13785
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>

gibfahn added a commit that referenced this pull request Jun 20, 2017

tools: enforce two arguments in assert.throws
Enables the requireTwo option of our custom rule.

PR-URL: #12270
Backport-PR-URL: #13785
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>

MylesBorins added a commit that referenced this pull request Jul 11, 2017

test: add second argument to assert.throws
This adds RegExp or error constructor arguments to the remaining places
where it is missing in preparation for the commit that will enforce the
presence of at least two arguments.

PR-URL: #12270
Backport-PR-URL: #13785
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>

MylesBorins added a commit that referenced this pull request Jul 11, 2017

tools: enforce two arguments in assert.throws
Enables the requireTwo option of our custom rule.

PR-URL: #12270
Backport-PR-URL: #13785
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>

@MylesBorins MylesBorins referenced this pull request Jul 18, 2017

Merged

v6.11.2 proposal #14356

gabrielschulhof added a commit to gabrielschulhof/node that referenced this pull request Mar 11, 2018

test: add second argument to assert.throws
This adds RegExp or error constructor arguments to the remaining places
where it is missing in preparation for the commit that will enforce the
presence of at least two arguments.

This applies portions of 9de2e15 that
are relevant to N-API.

PR-URL: nodejs#12270
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>

gabrielschulhof added a commit to gabrielschulhof/node that referenced this pull request Mar 31, 2018

test: add second argument to assert.throws
This adds RegExp or error constructor arguments to the remaining places
where it is missing in preparation for the commit that will enforce the
presence of at least two arguments.

PR-URL: nodejs#12270
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>

gabrielschulhof added a commit to gabrielschulhof/node that referenced this pull request Apr 10, 2018

test: add second argument to assert.throws
This adds RegExp or error constructor arguments to the remaining places
where it is missing in preparation for the commit that will enforce the
presence of at least two arguments.

PR-URL: nodejs#12270
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

test: add second argument to assert.throws
This adds RegExp or error constructor arguments to the remaining places
where it is missing in preparation for the commit that will enforce the
presence of at least two arguments.

Backport-PR-URL: #19447
PR-URL: #12270
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>

@MylesBorins MylesBorins referenced this pull request Apr 16, 2018

Merged

v6.14.2 proposal #19996

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.