Commit d0a08d4f authored by aniket-engg's avatar aniket-engg Committed by Aniket

test file suffix check improved

parent f820dbe1
...@@ -54,7 +54,7 @@ function processFile(filePath: string, sources: SrcIfc, isRoot: boolean = false) ...@@ -54,7 +54,7 @@ function processFile(filePath: string, sources: SrcIfc, isRoot: boolean = false)
const testFileImportRegEx: RegExp = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm 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 // 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' const includeTestLibs: string = '\nimport \'remix_tests.sol\';\n'
content = includeTestLibs.concat(content) content = includeTestLibs.concat(content)
} }
...@@ -161,7 +161,7 @@ export function compileContractSources(sources: SrcIfc, versionUrl: any, usingWo ...@@ -161,7 +161,7 @@ export function compileContractSources(sources: SrcIfc, versionUrl: any, usingWo
let includeTestLibs: string = '\nimport \'remix_tests.sol\';\n' let includeTestLibs: string = '\nimport \'remix_tests.sol\';\n'
for (let file in sources) { for (let file in sources) {
const c: string = sources[file].content 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) sources[file].content = includeTestLibs.concat(c)
} }
} }
......
...@@ -32,7 +32,7 @@ export function deployAll(compileResult: object, web3: Web3, callback) { ...@@ -32,7 +32,7 @@ export function deployAll(compileResult: object, web3: Web3, callback) {
compiledObject[className].className = className compiledObject[className].className = className
compiledObject[className].raw = contract compiledObject[className].raw = contract
if (contractFile.indexOf('_test.sol') >= 0) { if (contractFile.endsWith('_test.sol')) {
compiledObject[className].isTest = true compiledObject[className].isTest = true
} }
} }
......
...@@ -36,6 +36,10 @@ commander.command('help').description('output usage information').action(functio ...@@ -36,6 +36,10 @@ commander.command('help').description('output usage information').action(functio
commander commander
.option('-v, --verbose <level>', 'run with verbosity', mapVerbosity) .option('-v, --verbose <level>', 'run with verbosity', mapVerbosity)
.action(async (filename) => { .action(async (filename) => {
if(!filename.endsWith('_test.sol')){
log.error('Test filename should end with "_test.sol"')
process.exit()
}
// Console message // Console message
console.log(colors.white('\n\t👁\t:: Running remix-tests - Unit testing for solidity ::\t👁\n')) console.log(colors.white('\n\t👁\t:: Running remix-tests - Unit testing for solidity ::\t👁\n'))
// set logger verbosity // set logger verbosity
......
...@@ -56,7 +56,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, ...@@ -56,7 +56,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3,
function deployAllContracts (compilationResult: compilationInterface, asts: ASTInterface, next: Function) { function deployAllContracts (compilationResult: compilationInterface, asts: ASTInterface, next: Function) {
// Extract AST of test contract file source // Extract AST of test contract file source
for(const filename in asts) { for(const filename in asts) {
if(filename.includes('_test.sol')) if(filename.endsWith('_test.sol'))
sourceASTs[filename] = asts[filename].ast sourceASTs[filename] = asts[filename].ast
} }
deployAll(compilationResult, web3, (err, contracts) => { deployAll(compilationResult, web3, (err, contracts) => {
...@@ -70,7 +70,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, ...@@ -70,7 +70,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3,
let contractsToTest: string[] = [] let contractsToTest: string[] = []
let contractsToTestDetails: any[] = [] let contractsToTestDetails: any[] = []
const gatherContractsFrom = function(filename: string) { const gatherContractsFrom = function(filename: string) {
if (filename.indexOf('_test.sol') < 0) { if (!filename.endsWith('_test.sol')) {
return return
} }
try { try {
......
...@@ -46,7 +46,7 @@ export async function runTestSources(contractSources: SrcIfc, versionUrl: string ...@@ -46,7 +46,7 @@ export async function runTestSources(contractSources: SrcIfc, versionUrl: string
}, },
function deployAllContracts (compilationResult: compilationInterface, asts: ASTInterface, next) { function deployAllContracts (compilationResult: compilationInterface, asts: ASTInterface, next) {
for(const filename in asts) { for(const filename in asts) {
if(filename.includes('_test.sol')) if(filename.endsWith('_test.sol'))
sourceASTs[filename] = asts[filename].ast sourceASTs[filename] = asts[filename].ast
} }
deployAll(compilationResult, web3, (err, contracts) => { deployAll(compilationResult, web3, (err, contracts) => {
...@@ -62,7 +62,7 @@ export async function runTestSources(contractSources: SrcIfc, versionUrl: string ...@@ -62,7 +62,7 @@ export async function runTestSources(contractSources: SrcIfc, versionUrl: string
let contractsToTestDetails: any[] = [] let contractsToTestDetails: any[] = []
for (let filename in compilationResult) { for (let filename in compilationResult) {
if (filename.indexOf('_test.sol') < 0) { if (!filename.endsWith('_test.sol')) {
continue continue
} }
Object.keys(compilationResult[filename]).forEach(contractName => { Object.keys(compilationResult[filename]).forEach(contractName => {
......
...@@ -62,7 +62,7 @@ async function compileAndDeploy(filename: string, callback: Function) { ...@@ -62,7 +62,7 @@ async function compileAndDeploy(filename: string, callback: Function) {
}, },
function deployAllContracts(compilationResult: object, asts, next: Function): void { function deployAllContracts(compilationResult: object, asts, next: Function): void {
for(const filename in asts) { for(const filename in asts) {
if(filename.includes('_test.sol')) if(filename.endsWith('_test.sol'))
sourceASTs[filename] = asts[filename].ast sourceASTs[filename] = asts[filename].ast
} }
try { try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment