Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 7967cc9

Browse files
committed
validate breakpoint schema in tests
1 parent 0dbf25c commit 7967cc9

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

test/test-v8debugapi.js

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*1* KEEP THIS CODE AT THE TOP TO AVOID LINE NUMBER CHANGES */
22
/*2*/'use strict';
33
/*3*/function foo(n) {
4-
/*4*/ return n+42;
4+
/*4*/ var A = new Array(3); return n+42+A[0];
55
/*5*/}
66
/*6*/function getterObject() {
77
/*7*/ var hasGetter = { _a: 5, get a() { return this._a; }, b: 'hello world' };
@@ -28,6 +28,8 @@ var breakpointInFoo = {
2828
location: { path: 'test-v8debugapi.js', line: 4 }
2929
};
3030

31+
var MAX_INT = 2147483647; // Max signed int32.
32+
3133
var assert = require('assert');
3234
var v8debugapi = require('../lib/v8debugapi.js');
3335
var logModule = require('@google/cloud-diagnostics-common').logger;
@@ -43,6 +45,67 @@ function stateIsClean(api) {
4345
return true;
4446
}
4547

48+
function validateVariable(variable) {
49+
if (variable.name) {
50+
assert.equal(typeof variable.name, 'string');
51+
}
52+
if (variable.value) {
53+
assert.equal(typeof variable.value, 'string');
54+
}
55+
if (variable.type) {
56+
assert.equal(typeof variable.type, 'string');
57+
}
58+
if (variable.members) {
59+
variable.members.forEach(validateVariable);
60+
}
61+
if (variable.varTableIndex) {
62+
assert.ok(Number.isInteger(variable.varTableIndex) &&
63+
variable.varTableIndex >= 0 &&
64+
variable.varTableIndex <= MAX_INT);
65+
}
66+
}
67+
68+
function validateSourceLocation(location) {
69+
if (location.path) {
70+
assert.equal(typeof location.path, 'string');
71+
}
72+
if (location.line) {
73+
assert.ok(Number.isInteger(location.line) &&
74+
location.line >= 1 &&
75+
location.line <= MAX_INT);
76+
}
77+
}
78+
79+
function validateStackFrame(frame) {
80+
if (frame['function']) {
81+
assert.equal(typeof frame['function'], 'string');
82+
}
83+
if (frame.location) {
84+
validateSourceLocation(frame.location);
85+
}
86+
if (frame.arguments) {
87+
frame.arguments.forEach(validateVariable);
88+
}
89+
if (frame.locals) {
90+
frame.locals.forEach(validateVariable);
91+
}
92+
}
93+
94+
function validateBreakpoint(breakpoint) {
95+
if (!breakpoint) {
96+
return;
97+
}
98+
if (breakpoint.variableTable) {
99+
breakpoint.variableTable.forEach(validateVariable);
100+
}
101+
if (breakpoint.evaluatedExpressions) {
102+
breakpoint.evaluatedExpressions.forEach(validateVariable);
103+
}
104+
if (breakpoint.stackFrames) {
105+
breakpoint.stackFrames.forEach(validateStackFrame);
106+
}
107+
}
108+
46109
describe('v8debugapi', function() {
47110
config.workingDirectory = process.cwd() + '/test';
48111
var logger = logModule.create(config.logLevel);
@@ -54,6 +117,15 @@ describe('v8debugapi', function() {
54117
assert(!err);
55118
api = v8debugapi.create(logger, config, fileStats);
56119
assert.ok(api, 'should be able to create the api');
120+
121+
// monkey-patch wait to add validation of the breakpoints.
122+
var origWait = api.wait;
123+
api.wait = function(bp, callback) {
124+
origWait(bp, function(err) {
125+
validateBreakpoint(bp);
126+
callback(err);
127+
});
128+
};
57129
done();
58130
});
59131
} else {

0 commit comments

Comments
 (0)