Skip to content

fix: update test_conditions to beter report #184

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

Merged
merged 1 commit into from
Aug 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ phases:
build:
commands:
- npm test
- npm run test_conditions
- npm run integration
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"integration-node-decrypt": "npm run build; lerna run integration_node --stream --no-prefix -- -- decrypt -v $npm_package_config_localTestVectors",
"integration-node-encrypt": "npm run build; lerna run integration_node --stream --no-prefix -- -- encrypt -m $npm_package_config_encryptManifestList -k $npm_package_config_encryptKeyManifest -o $npm_package_config_decryptOracle",
"integration-node": "run-s integration-node-*",
"integration": "run-s integration-*"
"integration": "run-s integration-*",
"test_conditions": "./util/bootstrap_tsconfig 23"
},
"config": {
"localTestVectors": "../../aws-encryption-sdk-test-vectors/vectors/awses-decrypt/python-1.3.8.zip",
Expand Down
35 changes: 22 additions & 13 deletions util/test_conditions
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
*/

/* This file is to help line up the formal conditions listed in source with tests.
* I look for `sourceGrep` and `testGrep` make make sure that the conditions found,
* are in both sets.
*/
* I look for `sourceGrep` and `testGrep` make make sure that the conditions found,
* are in both sets.
*/

const { exec } = require('child_process')
const { promisify } = require('util')
const execAsync = promisify(exec)

const sourceGrep = 'grep -E \'Precondition|Postcondition\' modules/**/src/*.ts'
const testGrep = 'grep -E \'Precondition|Postcondition\' modules/**/test/*.ts'
const ignoreIssueCount = parseInt(process.argv[2] || 0, 10)

const sourceGrep = 'grep -E \'Precondition:|Postcondition(:|\\):)\' modules/**/src/*.ts'
const testGrep = 'grep -E \'Precondition:|Postcondition(:|\\):)\' modules/**/test/*.ts'

Promise.all([
execAsync(sourceGrep).then(clean),
Expand All @@ -36,12 +38,15 @@ Promise.all([
const testSet = new Set(flatMapForTests(tests))

if (source.length > sourceSet.size) {
console.log('Duplicate source conditions', getDuplicates(source))
issues += 1
const duplicateSources = getDuplicates(source)
console.log('Duplicate source conditions', duplicateSources)
issues += duplicateSources.length
}
if (tests.length > testSet.size) {
console.log('Duplicate test conditions', getDuplicates(tests))
issues += 1
// A single test _may_ be multiple conditions.
const duplicateTests = getDuplicates(tests)
if (duplicateTests.length) {
console.log('Duplicate test conditions', duplicateTests)
issues += duplicateTests.length
}

for (const sourceCondition of sourceSet) {
Expand All @@ -58,12 +63,16 @@ Promise.all([
}
}

process.exit(issues)
if (issues) {
console.error(`Issue count found: ${issues}`)
}

process.exit(Math.max(0, issues - ignoreIssueCount))
})

const remove = /(\*\/)|(\/\*)|(it\(')|(', \(\) => \{)|(', async \(\) => \{)/g
const remove = /(\*\/)|(\/\*)|(it\([`'])|([`'], \(\) => \{)|([`'], async \(\) => \{)/g

function clean ({ stdout, stderr }) {
function clean ({ stdout }) {
return stdout.split('\n')
.map(l => l.replace(remove, ''))
// Do not try and clean up ' and things like that...
Expand Down