remix-tests CLI improvements

pull/386/head
aniket-engg 4 years ago committed by Aniket
parent bb0d7f3817
commit 3e09b6f154
  1. 12
      libs/remix-tests/src/compiler.ts
  2. 30
      libs/remix-tests/src/run.ts

@ -1,6 +1,9 @@
import fs from './fileSystem'
import async from 'async'
import path from 'path'
import Log from './logger'
const logger = new Log()
const log = logger.logger
import { Compiler as RemixCompiler } from '@remix-project/remix-solidity'
import { SrcIfc, CompilerConfiguration, CompilationErrors } from './types'
@ -100,12 +103,21 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts:
}
} else {
// walkSync only if it is a directory
let solFileCount = 0;
fs.walkSync(filepath, (foundpath: string) => {
// only process .sol files
if (foundpath.split('.').pop() === 'sol') {
solFileCount++;
processFile(foundpath, sources, true)
}
})
if(solFileCount > 0) {
log.info(`${solFileCount} Solidity files found`)
}
else {
log.error(`No Solidity files found`)
process.exit()
}
}
} catch (e) { // eslint-disable-line no-useless-catch

@ -36,34 +36,42 @@ commander.command('help').description('output usage information').action(functio
// get current version
commander
.option('-v, --verbose <level>', 'run with verbosity', mapVerbosity)
.action(async (filename) => {
if(!filename.endsWith('_test.sol')){
.action(async (testsPath) => {
// Check if path exists
if (!fs.existsSync(testsPath)) {
console.error(testsPath + ' not found')
process.exit(1)
}
// Check if path is for a directory
const isDirectory = fs.lstatSync(testsPath).isDirectory()
// If path is for a file, file name must have `_test.sol` suffix
if(!isDirectory && !testsPath.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
// Set logger verbosity
if (commander.verbose) {
logger.setVerbosity(commander.verbose)
log.info('verbosity level set to ' + commander.verbose.blue)
}
const web3 = new Web3()
const provider: any = new Provider()
await provider.init()
web3.setProvider(provider)
if (!fs.existsSync(filename)) {
console.error(filename + ' not found')
process.exit(1)
}
const isDirectory = fs.lstatSync(filename).isDirectory()
runTestFiles(path.resolve(filename), isDirectory, web3)
runTestFiles(path.resolve(testsPath), isDirectory, web3)
})
if (!process.argv.slice(2).length) {
log.error('Please specify a filename')
log.error('Please specify a file or directory path')
process.exit()
}

Loading…
Cancel
Save