This repository has been archived by the owner on Apr 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Instrumentation Design
tntim96 edited this page Sep 10, 2014
·
5 revisions
function fn(x) {
var y;
switch(x) {
case 1: y = "one"; break;
case 2:
case 3: y = "two or three"; break;
default: y = "unknown";
}
if (y === "one") {
return y;
}
return "not one";
}
fn(1)
//Create the coverage object (var name is configurable)
if (!jscover) var jscover = {
//beF=boolean expression function to record true/false path
// result - boolean result
// u - URI path
// n - count (i.e. n'th boolean expression)
beF: function (result, u, n) {
if (result)this[u].be['' + n][0]++;else this[u].be['' + n][1]++;
return result
}
}
/*
s = statement. Property is the statement number, integer id the hits
sM = statement map. Property is the statement number, and record the code position
b = branch with varying number of paths (i.e switch cases)
bM = branch map data
be = boolean expression (NB: "br": "true" if this is used for determining a branch path)
beM = boolean expression map data
f = records function hits
fM = function map data
*/
if (!jscover['test.js']) {
jscover['test.js'] = {
"s": {"1": 0, "2": 0, "3": 0, "4": 0
, "5": 0, "6": 0, "7": 0, "8": 0, "9": 0},
"sM": {"1": {"pos": {"line": 1, "col": 0, "len": 212}},
"2": {"pos": {"line": 2, "col": 2, "len": 6}},
"3": {"pos": {"line": 4, "col": 12, "len": 10}},
"4": {"pos": {"line": 6, "col": 12, "len": 19}},
"5": {"pos": {"line": 7, "col": 13, "len": 14}},
"6": {"pos": {"line": 9, "col": 2, "len": 35}},
"7": {"pos": {"line": 10, "col": 4, "len": 9}},
"8": {"pos": {"line": 12, "col": 2, "len": 17}},
"9": {"pos": {"line": 14, "col": 0, "len": 5}}},
"b": {"1": [0, 0, 0, 0]},
"bM": {"1": [
{"pos": {"line": 4, "col": 4, "len": 25}},
{"pos": {"line": 5, "col": 4, "len": 7}},
{"pos": {"line": 6, "col": 4, "len": 34}},
{"pos": {"line": 7, "col": 4, "len": 8}}
]
},
"be": {"1": [0, 0]},
"beM": {"1": {"pos": {"line": 9, "col": 6, "len": 10}, "br": "true"}},
"f": {"1": 0},
"fM": {"1": {"pos": {"line": 1, "col": 0, "len": 212}}}
}
}
jscover["test.js"].s["1"]++;
function fn(x) {
jscover["test.js"].f["1"]++;
jscover["test.js"].s["2"]++;
var y;
switch (x) {
case 1:
jscover["test.js"].b["1"][0]++;
jscover["test.js"].s["3"]++;
y = "one";
jscover["test.js"].s["4"]++;
break;
case 2:
jscover["test.js"].b["1"][1]++;
case 3:
jscover["test.js"].b["1"][2]++;
jscover["test.js"].s["5"]++;
y = "two or three";
jscover["test.js"].s["6"]++;
break;
default:
jscover["test.js"].b["1"][3]++;
jscover["test.js"].s["7"]++;
y = "unknown"
}
jscover["test.js"].s["8"]++;
if (jscover.beF(y === "one", "test.js", 1)) {
jscover["test.js"].s["9"]++;
return y
}
jscover["test.js"].s["10"]++;
return"not one"
}
jscover["test.js"].s["11"]++;
fn(1)