From a65ebcea467215fe4ef49b1b5440d8f444aa9686 Mon Sep 17 00:00:00 2001 From: Emery Date: Sat, 3 Aug 2019 16:12:38 -0700 Subject: [PATCH] fix: update test_conditions to beter report Offer a way to override issues Integrate into CI --- buildspec.yml | 1 + package.json | 3 ++- util/test_conditions | 35 ++++++++++++++++++++++------------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/buildspec.yml b/buildspec.yml index 5a8afd8c1..a4c3e6f3b 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -11,4 +11,5 @@ phases: build: commands: - npm test + - npm run test_conditions - npm run integration diff --git a/package.json b/package.json index ebc7b5412..3c79bf71f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/util/test_conditions b/util/test_conditions index 70982c7be..201c828b1 100755 --- a/util/test_conditions +++ b/util/test_conditions @@ -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), @@ -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) { @@ -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...