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: improve n-api array func coverage #12890

Closed
wants to merge 3 commits into from

Conversation

mhdawson
Copy link
Member

@mhdawson mhdawson commented May 8, 2017

  • add coverage for napi_has_element
  • add coverage for napi_create_array_with_length
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, n-api

- add coverage for napi_has_element
- add coverage for napi_create_array_with_length
@nodejs-github-bot nodejs-github-bot added node-api Issues and PRs related to the Node-API. test Issues and PRs related to the tests. labels May 8, 2017
@mhdawson
Copy link
Member Author

mhdawson commented May 8, 2017

The other thing I noticed while adding these tests is that we should probably change size_t for the array length in napi_create_array_with_length to a uint32_t since I think that's the maximum allowed, however I've deferred doing that to a later PR.

@@ -19,19 +19,26 @@ const array = [
]
];

assert.strictEqual(test_array.Test(array, array.length + 1),
assert.strictEqual(test_array.TestGetElement(array, array.length + 1),
'Index out of bound!');
Copy link
Contributor

Choose a reason for hiding this comment

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

Totally unrelated to this PR, but just wanted to say that this implementation doesn't look correct to me. "Index out of bound!" should be thrown as an Error. As it is, "Index out of bound!" could be a value in the Array.

@jasongin
Copy link
Member

jasongin commented May 8, 2017

we should probably change size_t for the array length in napi_create_array_with_length to a uint32_t since I think that's the maximum allowed

I think the reasoning here was that the public API would consistently use size_t for all length parameters, but implementations should return errors for any lengths which are beyond the supported maximum.

@mhdawson
Copy link
Member Author

mhdawson commented May 9, 2017

@jasongin based on that explanation we can just leave as is then, although I'll probably check at some point later if that is consistent with how size_t is used elsewhere, particularly when the bit size can be used to help indicate the maximum range.

@mhdawson
Copy link
Member Author

mhdawson commented May 9, 2017

@thefourtheye fixed up that part of the test.

assert.strictEqual(test_array.Test(array, array.length + 1),
'Index out of bound!');
assert.throws(
() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this arrow function fit on a single line?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was keeping it consistent with what I saw most often in tests. For example: test/parallel/test-punycode.js.

() => {
test_array.TestGetElement(array, array.length + 1);
},
/Index out of bounds!/
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you able to make this more strict? We've been moving toward adding ^, $, and the error type to the regular expression.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops missed that one, will add.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also fixed up the other instance which was there from the existing version of the test.

});


assert.deepStrictEqual(test_array.New(array), array);

assert(test_array.TestHasElement(array, 0));
assert.strictEqual(false, test_array.TestHasElement(array, array.length + 1));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you switch the argument order to strictEqual().

Copy link
Member Author

Choose a reason for hiding this comment

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

will do.


assert(test_array.NewWithLength(0) instanceof Array);
assert(test_array.NewWithLength(1) instanceof Array);
assert(test_array.NewWithLength(2 ^ 32 - 1) instanceof Array);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you attempting to do exponentiation here?

Copy link
Member

Choose a reason for hiding this comment

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

This would need to be (2 ** 32 - 1)

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, maybe coding at 2am in your hotel room is not always the best idea. Will fix.

@mhdawson
Copy link
Member Author

mhdawson commented May 9, 2017

@cjihrig pushed commit to address comments.

@mhdawson
Copy link
Member Author

@mhdawson
Copy link
Member Author

CI good landing.

@mhdawson
Copy link
Member Author

Landed as 654afa2

@mhdawson mhdawson closed this May 11, 2017
mhdawson added a commit that referenced this pull request May 11, 2017
- add coverage for napi_has_element
- add coverage for napi_create_array_with_length

PR-URL: #12890
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
anchnk pushed a commit to anchnk/node that referenced this pull request May 19, 2017
- add coverage for napi_has_element
- add coverage for napi_create_array_with_length

PR-URL: nodejs#12890
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@jasnell jasnell mentioned this pull request May 28, 2017
@mhdawson mhdawson deleted the array-coverage branch June 28, 2017 19:24
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Apr 10, 2018
- add coverage for napi_has_element
- add coverage for napi_create_array_with_length

PR-URL: nodejs#12890
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Apr 16, 2018
- add coverage for napi_has_element
- add coverage for napi_create_array_with_length

Backport-PR-URL: #19447
PR-URL: #12890
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Apr 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node-api Issues and PRs related to the Node-API. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants