-
Notifications
You must be signed in to change notification settings - Fork 684
Increase test coverage: Array.prototype.splice #2682
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
Increase test coverage: Array.prototype.splice #2682
Conversation
e5f8e7b
to
c108b17
Compare
assert (e instanceof ReferenceError); | ||
} | ||
|
||
try{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space before '{'
There are many minor style issues like this in the added test file. Please always put a space before '{'
, put semicolon after statements, do not write space before '('
in function calls (e.g.: assert(false);
, etc.)
Check your code and fix these issues.
2ef0f11
to
8f29248
Compare
@LaszloLango |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing left, good to me after that.
try { | ||
Array.prototype.splice.call(undefined); | ||
assert(false); | ||
} catch(e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space: } catch (e) {
Please fix it in the whole file.
8f29248
to
54074ec
Compare
Fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
obj = {get: f, valueOf : f, toString: f}; | ||
arr = [1, 2, obj, 4, 5]; | ||
Object.defineProperty(arr, '2',{ 'get' : f } ); | ||
print(arr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print
??? Why is it even needed?
var a = [1, 5, 6, 7, 8, 5]; | ||
Object.defineProperty(a, '1', { 'get' : function() { throw new ReferenceError("foo"); } }); | ||
Object.defineProperty(a, '0', { 'get' : function() { throw new ReferenceError("foo"); } }); | ||
Object.defineProperty(a, '2', { 'get' : function() { throw new ReferenceError("foo"); } }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use different error messages, and assert in the catch block which error has been thrown.
Also I'd rather call the |
54074ec
to
96f1bf1
Compare
@rerobika |
96f1bf1
to
4179d55
Compare
Corrected. |
@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)? |
@akosthekiss |
I almost forgot about unit tests and various configurations. So, I think combining the coverage results of all run-tests.py executions is the best way. |
There was a problem hiding this 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 .
@akosthekiss |
} | ||
|
||
var a = {length : 13}; | ||
Array.prototype.splice.call(a, function () {delete a}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces around the function body's expression statement.
} catch (e) {} | ||
|
||
try { | ||
f = function() { for(var i = 0; i < arr.length; i++) { delete arr[i]} }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Break it into multiple lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. (Plus: there are multiple similar constructs in the code; apply a consistent style everywhere)
Object.defineProperty(arr, '2', { 'get' : f }); | ||
Object.defineProperty(arr, '3', { 'get' : f }); | ||
Object.defineProperty(arr, '4', { 'get' : f }); | ||
Object.defineProperty(arr, '5', { 'get' : f }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using a for loop for these 6 property definitions?
assert(e.message == "4"); | ||
} | ||
|
||
try{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a short description for each new testcase? After this point the test cases are slightly complicated, it would be good to know what is happening.
4179d55
to
05c044f
Compare
I updated the patch according to the review. |
assert(e instanceof TypeError); | ||
} | ||
|
||
// Checking behaior when elements are getting deleted the same way, but there are more elements and arguments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: behaior
Object.defineProperty(arr, '8', { 'get' : f }); | ||
Object.defineProperty(arr, '9', { 'get' : f2 }); | ||
Object.defineProperty(arr, '10', { 'get' : f3 }); | ||
arr.splice(1, 7, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really the simplest use case to test a feature of the engine? Is a 24 element array, 7 manually defined properties, and a 21 element splice needed to cover some path?
assert(e instanceof TypeError); | ||
} | ||
|
||
// Checking behavior when first 3 elements throw error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which code path needs the first/last 3 elements to be handled specially?
|
||
// Checking behavior when last 3 elements throw error | ||
try { | ||
f = function() { for(var i=0; i<arr.length; i++) { delete arr[i]} }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: spacing (too many + missing). also: missing ; from after delete statement.
|
||
// Checking behavior when the last element gets deleted | ||
try { | ||
f = function () { delete arr[23];}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: spacing
f = function () { delete arr[23];}; | ||
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]; | ||
delete arr[23]; | ||
Object.defineProperty(arr, '23',{ 'get' : f }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: spacing
} catch (e) {} | ||
|
||
try { | ||
f = function() { for(var i = 0; i < arr.length; i++) { delete arr[i]} }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. (Plus: there are multiple similar constructs in the code; apply a consistent style everywhere)
f = function() { for(var i = 0; i < arr.length; i++) { delete arr[i]} }; | ||
f1 = function() { delete arr[2];}; | ||
f2 = function() { delete arr[3];}; | ||
f3 = function() { delete arr[4];}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: spacing
|
||
// Checking behaior when elements are getting deleted the same way, but there are more elements and arguments | ||
try { | ||
f = function() { for(var i=0; i<arr.length; i++) { delete arr[i]} }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: spacing, semicolon
e4f635b
to
676a3d1
Compare
676a3d1
to
4abd6ac
Compare
delete arr[3]; | ||
arr.length = 13; | ||
Object.defineProperty(arr, '5', function() { }); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This style has became even worse than it was before. Please use the following format:
f = function() {
delete arr[3];
arr.length = 13;
Object.defineProperty(arr, '5', function() { });
};
arr = [1, 2, obj, 4, 5]; | ||
Object.defineProperty(arr, '2',{ 'get' : f } ); | ||
for(var i = 0; i < arr.length; i++) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the open curly brace up:
for (var i = 0; i < arr.length; i++) {
//...body
}
11fe246
to
44c2b34
Compare
Updated the patch:
|
dc682a3
to
fee86e5
Compare
Added new test cases to improve branch coverage in Array.prototype routines. The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file. https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs. Branch coverage including jerryscript-project#2682 and jerryscript-project#2674: -before: 492 / 578 -after: 570 / 574 There are 28 functions in ecma-builtin-arraybuffer-prototype.c, we hit 14 from them. The other 14 functions are either already covered, or we could not improve the coverage of it. Co-authored-by: Mate Dabis [email protected] JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected] JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]
Added new test cases to improve branch coverage in Array.prototype routines. The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file. https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs. Branch coverage including jerryscript-project#2682 and jerryscript-project#2674: -before: 492 / 578 -after: 570 / 574 There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them. The other 14 functions are either already covered, or we could not improve the coverage of it. Co-authored-by: Mate Dabis [email protected] JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected] JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]
Summary: While measuring the branch coverage we don't count JERRY_ASSERT s. Branch coverage (covered branch/all branch): Also found an opportunity to optimize, that "else if" branch is not needed, |
Branch coverage: Before: 52/72 After: 72/72 Also found opportunity for optimization, that "else if" branch is not needed, should be replaced with an "else". JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
fee86e5
to
835b1f9
Compare
Added new test cases to improve branch coverage in Array.prototype routines. The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file. https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs. Branch coverage including pando-project#2682 and pando-project#2674: -before: 401 / 478 -after: 474 / 478 There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them. The other 14 functions are either already covered, or we could not improve the coverage of it. More information on the link below: https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e Co-authored-by: Mate Dabis [email protected] JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected] JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
Added new test cases to improve branch coverage in Array.prototype routines. The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file. https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs. Branch coverage including pando-project#2682 and pando-project#2674: -before: 401 / 478 -after: 474 / 478 There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them. The other 14 functions are either already covered, or we could not improve the coverage of it. More information about the coverage improvement and the branches not reached: https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e Co-authored-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
Added new test cases to improve branch coverage in Array.prototype routines. The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file. https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs. Branch coverage including pando-project#2682 and pando-project#2674: -before: 401 / 478 -after: 474 / 478 There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them. The other 14 functions are either already covered, or we could not improve the coverage of it. More information about the coverage improvement and the branches not reached: https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e While improving the coverage we found an unnecessary condition check, which can not be false in any cases. Co-authored-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
Added new test cases to improve branch coverage in Array.prototype routines. The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file. https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs. Branch coverage including pando-project#2682 and pando-project#2674: -before: 401 / 478 -after: 474 / 478 There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them. The other 14 functions are either already covered, or we could not improve the coverage of it. More information about the coverage improvement and the branches not reached: https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e While improving the coverage we found an unnecessary condition check, which can not be false in any cases. Co-authored-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
Added new test cases to improve branch coverage in Array.prototype routines. The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file. https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs. Branch coverage including pando-project#2682 and pando-project#2674: -before: 399 / 476 -after: 472 / 476 There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them. The other 14 functions are either already covered, or we could not improve the coverage of it. More information about the coverage improvement and the branches not reached: https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e While improving the coverage we found an unnecessary condition check, which can not be false in any cases. Co-authored-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
Closing PR because of moving into a unified PR. |
Added new test cases to improve branch coverage in Array.prototype routines. The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file. https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs. Branch coverage including pando-project#2682 and pando-project#2674: -before: 399 / 476 -after: 472 / 476 There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them. The other 14 functions are either already covered, or we could not improve the coverage of it. More information about the coverage improvement and the branches not reached: https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e While improving the coverage we found an unnecessary condition check, which can not be false in any cases. Co-authored-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
Added new test cases to improve branch coverage in Array.prototype routines. The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file. https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs. Branch coverage including pando-project#2682 and pando-project#2674: -before: 399 / 476 -after: 472 / 476 There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them. The other 14 functions are either already covered, or we could not improve the coverage of it. More information about the coverage improvement and the branches not reached: https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e While improving the coverage we found an unnecessary condition check, which can not be false in any cases. Co-authored-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
Added new test cases to improve branch coverage in Array.prototype routines. The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file. https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs. Branch coverage including pando-project#2682 and pando-project#2674: -before: 399 / 476 -after: 472 / 476 There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them. The other 14 functions are either already covered, or we could not improve the coverage of it. More information about the coverage improvement and the branches not reached: https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e While improving the coverage we found an unnecessary condition check, which can not be false in any cases. Co-authored-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
Added new test cases to improve branch coverage in Array.prototype routines. The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file. https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs. Branch coverage including pando-project#2682 and pando-project#2674: -before: 399 / 476 -after: 472 / 476 There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them. The other 14 functions are either already covered, or we could not improve the coverage of it. More information about the coverage improvement and the branches not reached: https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e While improving the coverage we found an unnecessary condition check, which can not be false in any cases. Co-authored-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
Added new test cases to improve branch coverage in Array.prototype routines. The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file. https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs. Branch coverage including pando-project#2682 and pando-project#2674: -before: 399 / 476 -after: 472 / 476 There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them. The other 14 functions are either already covered, or we could not improve the coverage of it. More information about the coverage improvement and the branches not reached: https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e While improving the coverage we found an unnecessary condition check, which can not be false in any cases. Co-authored-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected] JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
Branch coverage:
Before: 52/72
After: 72/72
Also found an opportunity to optimize, that "else if" branch is not needed,
should be replaced with an "else".
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]