Skip to content

Increase test coverage: Array.prototype.lastIndexOf #2688

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

Closed

Conversation

matedabis
Copy link
Contributor

Branch coverage:
Before: 32/40
After: 40/40

JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]

} catch (e) { }

// Checking behavior when length is 0
try{
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing space before {


// Checking behavior when the starting index is out of the range of the original array, so it points
// to an empty space, as we modified the length of the array before
try{
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing space before {


// Checking behavior when the 3rd argument (start index) is greater than the length of the first argument
try {
Array.prototype.lastIndexOf.call("foo", "foo", 999)
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing semicolon

try {
var o = {};
Object.defineProperty(o, 'toString', { 'get' : function () { throw new ReferenceError ("foo"); } });
Array.prototype.lastIndexOf.call("foo", "foo", o)
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing semicolon

var o = {};
Object.defineProperty(o, 'toString', { 'get' : function () { throw new ReferenceError ("foo"); } });
var a = { length : o }
Array.prototype.lastIndexOf.call(a, function () { })
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing semicolon

Object.defineProperty(o, 'toString', { 'get' : function () { throw new ReferenceError ("foo"); } });
var a = { length : o }
Array.prototype.lastIndexOf.call(a, function () { })
assert (false);
Copy link
Contributor

Choose a reason for hiding this comment

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

no space needed before (

Array.prototype.lastIndexOf.call(a, function () { })
assert (false);
} catch (e) {
assert (e instanceof ReferenceError);
Copy link
Contributor

Choose a reason for hiding this comment

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

no space needed before (

@matedabis
Copy link
Contributor Author

@LaszloLango
Fixed.

Copy link
Contributor

@LaszloLango LaszloLango left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@rerobika rerobika left a comment

Choose a reason for hiding this comment

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

Please apply the suggestions for all the new related test cases.

// Checking behavior when there are no arguments except "this"
try {
var a = "This is a sample text string to test this function";
Array.prototype.lastIndexOf.call(a);
Copy link
Member

Choose a reason for hiding this comment

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

Add an assert(false) after this line, to ensure that an exception has been thrown.

try {
var a = "This is a sample text string to test this function";
Array.prototype.lastIndexOf.call(a);
} catch (e) {}
Copy link
Member

Choose a reason for hiding this comment

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

Add an assert for e instanceof TypeError to validate the exception.

@matedabis matedabis force-pushed the last_index_of branch 2 times, most recently from d35de5c to 1fd95d5 Compare January 10, 2019 09:46
@matedabis
Copy link
Contributor Author

Corrected


// Checking behavior when there are no arguments except "this"
var a = "This is a sample text string to test this function";
Array.prototype.lastIndexOf.call(a);
Copy link
Member

Choose a reason for hiding this comment

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

Since it does not throw exception, add an assert for the expected result.

Array.prototype.lastIndexOf.call(a);

// Checking behavior when value is null
try{
Copy link
Member

Choose a reason for hiding this comment

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

Space before {.

}

// Checking behavior when length is 0
Array.prototype.lastIndexOf.call("", "chocolate cake");
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

}

// Checking behavior when the 3rd argument (start index) is greater than the length of the first argument
Array.prototype.lastIndexOf.call("foo", "foo", 999);
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

// to an empty space, as we modified the length of the array before
var a = [1, 2, 3];
Object.defineProperty(a, "length", {value: 10});
Array.prototype.lastIndexOf.call(a, "", 6);
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

Array.prototype.lastIndexOf.call(a, function () { });
assert(false);
} catch (e) {
assert(e instanceof ReferenceError);
Copy link
Member

Choose a reason for hiding this comment

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

Add an assert for e.message === "foo"'.

Array.prototype.lastIndexOf.call("foo", "foo", o);
assert(false);
} catch (e) {
assert(e instanceof ReferenceError);
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

Branch coverage:
   Before: 32/40
   After: 40/40

JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
@matedabis
Copy link
Contributor Author

Corrected.

@akosthekiss
Copy link
Member

@matedabis Could you please give details similar to those requested at #2674 (comment) . I.e., which source file(s) or source file entity(-ies) (function(s)) are investigated, and what is the coverage result when all test suites of the project are executed (i.e., what is the actual baseline)?

@matedabis
Copy link
Contributor Author

@akosthekiss
The function we are testing: ecma_builtin_array_prototype_object_splice
The test file: /tests/jerry/array-prototype-splice.js
I dont know yet the result if all test suites are executed. By all test suites of the project do you mean all the tests in run-tests.py or all the .js files in the tests folder, or both?

Copy link
Member

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@akosthekiss akosthekiss left a comment

Choose a reason for hiding this comment

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

I'd like to have this on hold until validity questions are sorted out at #2674 .

@matedabis
Copy link
Contributor Author

Closing pull request because the updated version of the coverage tester script wich runs --jerry-test-suite --test262 --unittests --jerry-tests tests, shows that the branches of this function are already covered so these changes are not needed.
The script:
https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

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.

5 participants