开发者

"Label not found" error in code coverage with jstestdriver

开发者 https://www.devze.com 2023-04-01 14:58 出处:网络
I have some javascript开发者_运维百科 code with do while outer loop and switch inner loop, inner switch loop contains break outerloop. below is simplified version of code.

I have some javascript开发者_运维百科 code with do while outer loop and switch inner loop, inner switch loop contains break outerloop. below is simplified version of code.

While generating code coverage with jstestdriver coverage plugin, I am getting error "Label not found" at line "break loop1".

    var a = 2;
    var c = 5;
    loop1:
        do {
            switch (c) {
            case 1 :
                break;
            default :
                break loop1;
            }
            a--;
        } while (a !=0);

Any help??


This is because of a bug in the JsTestDriver coverage plugin. Until fixed, the solution would be to refactor your code to not use labels to break loops.

The code coverage plugin inserts statements on each line to record which lines have been executed, even between the label and the do statement. This detaches them from each other.

The code executed with coverage enabled would look something like this:

// ...
LCOV_1f[3]++; loop1:
    LCOV_1f[4]++; do {
        // ...
    } while (a !=0);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号