test file suffix check improved

pull/5370/head
aniket-engg 5 years ago committed by Aniket
parent 04334a2625
commit 6320a966da
  1. 4
      remix-tests/src/compiler.ts
  2. 2
      remix-tests/src/deployer.ts
  3. 4
      remix-tests/src/run.ts
  4. 4
      remix-tests/src/runTestFiles.ts
  5. 4
      remix-tests/src/runTestSources.ts
  6. 2
      remix-tests/tests/testRunner.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)
}
}

@ -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
}
}

@ -36,6 +36,10 @@ commander.command('help').description('output usage information').action(functio
commander
.option('-v, --verbose <level>', '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

@ -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 {

@ -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 => {

@ -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 {

Loading…
Cancel
Save