From 6320a966da5b1e0c19cae4da7c7a9ae2561a28e9 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 27 Nov 2019 13:49:06 +0530 Subject: [PATCH] test file suffix check improved --- remix-tests/src/compiler.ts | 4 ++-- remix-tests/src/deployer.ts | 2 +- remix-tests/src/run.ts | 4 ++++ remix-tests/src/runTestFiles.ts | 4 ++-- remix-tests/src/runTestSources.ts | 4 ++-- remix-tests/tests/testRunner.ts | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/remix-tests/src/compiler.ts b/remix-tests/src/compiler.ts index 28f768f260..55fdc80a94 100644 --- a/remix-tests/src/compiler.ts +++ b/remix-tests/src/compiler.ts @@ -54,7 +54,7 @@ function processFile(filePath: string, sources: SrcIfc, isRoot: boolean = false) const testFileImportRegEx: RegExp = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm // import 'remix_tests.sol', if file is a root test contract file and doesn't already have it - if (isRoot && filePath.includes('_test.sol') && regexIndexOf(content, testFileImportRegEx) < 0) { + if (isRoot && filePath.endsWith('_test.sol') && regexIndexOf(content, testFileImportRegEx) < 0) { const includeTestLibs: string = '\nimport \'remix_tests.sol\';\n' content = includeTestLibs.concat(content) } @@ -161,7 +161,7 @@ export function compileContractSources(sources: SrcIfc, versionUrl: any, usingWo let includeTestLibs: string = '\nimport \'remix_tests.sol\';\n' for (let file in sources) { const c: string = sources[file].content - if (file.includes('_test.sol') && c && regexIndexOf(c, testFileImportRegEx) < 0) { + if (file.endsWith('_test.sol') && c && regexIndexOf(c, testFileImportRegEx) < 0) { sources[file].content = includeTestLibs.concat(c) } } diff --git a/remix-tests/src/deployer.ts b/remix-tests/src/deployer.ts index d0dfcf9d67..33d4fa6747 100644 --- a/remix-tests/src/deployer.ts +++ b/remix-tests/src/deployer.ts @@ -32,7 +32,7 @@ export function deployAll(compileResult: object, web3: Web3, callback) { compiledObject[className].className = className compiledObject[className].raw = contract - if (contractFile.indexOf('_test.sol') >= 0) { + if (contractFile.endsWith('_test.sol')) { compiledObject[className].isTest = true } } diff --git a/remix-tests/src/run.ts b/remix-tests/src/run.ts index 60bf46997c..f22bcdd427 100644 --- a/remix-tests/src/run.ts +++ b/remix-tests/src/run.ts @@ -36,6 +36,10 @@ commander.command('help').description('output usage information').action(functio commander .option('-v, --verbose ', 'run with verbosity', mapVerbosity) .action(async (filename) => { + if(!filename.endsWith('_test.sol')){ + log.error('Test filename should end with "_test.sol"') + process.exit() + } // Console message console.log(colors.white('\n\tšŸ‘\t:: Running remix-tests - Unit testing for solidity ::\tšŸ‘\n')) // set logger verbosity diff --git a/remix-tests/src/runTestFiles.ts b/remix-tests/src/runTestFiles.ts index a14888bf6e..9216d62983 100644 --- a/remix-tests/src/runTestFiles.ts +++ b/remix-tests/src/runTestFiles.ts @@ -56,7 +56,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, function deployAllContracts (compilationResult: compilationInterface, asts: ASTInterface, next: Function) { // Extract AST of test contract file source for(const filename in asts) { - if(filename.includes('_test.sol')) + if(filename.endsWith('_test.sol')) sourceASTs[filename] = asts[filename].ast } deployAll(compilationResult, web3, (err, contracts) => { @@ -70,7 +70,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, let contractsToTest: string[] = [] let contractsToTestDetails: any[] = [] const gatherContractsFrom = function(filename: string) { - if (filename.indexOf('_test.sol') < 0) { + if (!filename.endsWith('_test.sol')) { return } try { diff --git a/remix-tests/src/runTestSources.ts b/remix-tests/src/runTestSources.ts index f5394e57f8..f6aa3ff4bb 100644 --- a/remix-tests/src/runTestSources.ts +++ b/remix-tests/src/runTestSources.ts @@ -46,7 +46,7 @@ export async function runTestSources(contractSources: SrcIfc, versionUrl: string }, function deployAllContracts (compilationResult: compilationInterface, asts: ASTInterface, next) { for(const filename in asts) { - if(filename.includes('_test.sol')) + if(filename.endsWith('_test.sol')) sourceASTs[filename] = asts[filename].ast } deployAll(compilationResult, web3, (err, contracts) => { @@ -62,7 +62,7 @@ export async function runTestSources(contractSources: SrcIfc, versionUrl: string let contractsToTestDetails: any[] = [] for (let filename in compilationResult) { - if (filename.indexOf('_test.sol') < 0) { + if (!filename.endsWith('_test.sol')) { continue } Object.keys(compilationResult[filename]).forEach(contractName => { diff --git a/remix-tests/tests/testRunner.ts b/remix-tests/tests/testRunner.ts index 743894d000..11023c9aa6 100644 --- a/remix-tests/tests/testRunner.ts +++ b/remix-tests/tests/testRunner.ts @@ -62,7 +62,7 @@ async function compileAndDeploy(filename: string, callback: Function) { }, function deployAllContracts(compilationResult: object, asts, next: Function): void { for(const filename in asts) { - if(filename.includes('_test.sol')) + if(filename.endsWith('_test.sol')) sourceASTs[filename] = asts[filename].ast } try {