This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
state.js needs some assertions because it interfaces with parts of V8 debug API that are volatile across versions. However, we don't want to be running these assertions in real user code. debug-assert module allows us to run with assertions enabled in the CI. PR-URL: #272
- Loading branch information
1 parent
d3994f8
commit 9377a11
Showing
6 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright 2017 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const realAssert = require('assert'); | ||
|
||
const nop = _=>_; | ||
const fakeAssert = nop; | ||
fakeAssert.deepEqual = fakeAssert.deepStrictEqual = fakeAssert.doesNotThrow = | ||
fakeAssert.equal = fakeAssert.fail = fakeAssert.ifError = | ||
fakeAssert.notDeepEqual = fakeAssert.notDeepStrictEqual = | ||
fakeAssert.notEqual = fakeAssert.notStrictEqual = fakeAssert.ok = | ||
fakeAssert.strictEqual = fakeAssert.throws = | ||
fakeAssert.AssertionError = nop; | ||
|
||
module.exports = function debugAssert(enableAssertions) { | ||
return enableAssertions ? realAssert : fakeAssert; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright 2017 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const realAssert = require('assert'); | ||
|
||
describe('debug-assert', () => { | ||
const debugAssert = require('../src/agent/debug-assert.js'); | ||
|
||
it('should fire assertions when enabled', () => { | ||
realAssert.throws(() => { | ||
const assert = debugAssert(true); | ||
assert.equal(1, 2); | ||
}); | ||
}); | ||
|
||
describe('disabled', () => { | ||
const assert = debugAssert(false); | ||
|
||
it('should not fire assertions when disabled', () => { | ||
assert.equal(1, 2); | ||
}); | ||
|
||
it('should cover the full assert API', () => { | ||
Object.keys(realAssert).forEach((key) => { | ||
realAssert.equal(typeof assert[key], 'function'); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright 2017 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const state = require('../src/agent/state.js'); | ||
|
||
describe('state', () => { | ||
// Testing of state.js is driven through test-v8debugapi.js. There are | ||
// minimal unit tests here. | ||
|
||
it('should have assertions enabled', () => { | ||
// this test makes sure that the necessary environment variables to enable | ||
// asserts are present during testing. Use run-tests.sh, or export | ||
// CLOUD_DEBUG_ASSERTIONS=1 to make sure this test passes. | ||
if (!process.env.CLOUD_DEBUG_ASSERTIONS) { | ||
console.log('This test requires the enviornment variable ' + | ||
'CLOUD_DEBUG_ASSERTIONS to be set in order to pass'); | ||
} | ||
assert.throws(() => { | ||
state.testAssert(); | ||
}); | ||
}); | ||
}); |