From eb22e6841cbdcf09fc886f84d4700d53be10a6b7 Mon Sep 17 00:00:00 2001 From: 0mkar <0mkar@protonmail.com> Date: Sat, 25 Aug 2018 01:40:56 +0530 Subject: [PATCH] fix import, inject remix_tests.sol, use signale for logging --- remix-tests/examples/simple_storage2_test.sol | 2 -- remix-tests/examples/simple_storage_test.sol | 2 -- remix-tests/package.json | 1 + remix-tests/src/compiler.js | 16 +++++++--- remix-tests/src/index.js | 30 +++++++++++++++++-- remix-tests/src/run.js | 4 ++- .../tests/examples_1/simple_storage_test.sol | 2 -- .../tests/examples_2/simple_storage_test.sol | 2 -- .../tests/examples_3/simple_string_test.sol | 1 - 9 files changed, 43 insertions(+), 17 deletions(-) diff --git a/remix-tests/examples/simple_storage2_test.sol b/remix-tests/examples/simple_storage2_test.sol index 0c199f9b03..814570aae7 100644 --- a/remix-tests/examples/simple_storage2_test.sol +++ b/remix-tests/examples/simple_storage2_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "./tests.sol"; import "./simple_storage.sol"; contract MyTest2 { @@ -26,4 +25,3 @@ contract MyTest2 { } } - diff --git a/remix-tests/examples/simple_storage_test.sol b/remix-tests/examples/simple_storage_test.sol index ec780ae85d..09392087e3 100644 --- a/remix-tests/examples/simple_storage_test.sol +++ b/remix-tests/examples/simple_storage_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "./tests.sol"; import "./simple_storage.sol"; contract MyTest { @@ -26,4 +25,3 @@ contract MyTest { } } - diff --git a/remix-tests/package.json b/remix-tests/package.json index 5036e7c6b1..52187f47f9 100644 --- a/remix-tests/package.json +++ b/remix-tests/package.json @@ -43,6 +43,7 @@ "commander": "^2.13.0", "remix-simulator": "0.0.3", "remix-solidity": "^0.2.5", + "signale": "^1.2.1", "solc": "^0.4.24", "standard": "^10.0.3", "web3": "1.0.0-beta.27" diff --git a/remix-tests/src/compiler.js b/remix-tests/src/compiler.js index e7de72c36f..2fc3e2e52d 100644 --- a/remix-tests/src/compiler.js +++ b/remix-tests/src/compiler.js @@ -1,7 +1,7 @@ let fs = require('fs') var async = require('async') var path = require('path') - +const signale = require('signale') let RemixCompiler = require('remix-solidity').Compiler // TODO: replace this with remix's own compiler code @@ -13,13 +13,21 @@ function compileFileOrFiles (filename, isDirectory, cb) { 'tests.sol': { content: require('../sol/tests.sol.js') }, 'remix_tests.sol': { content: require('../sol/tests.sol.js') } } + // signale.debug(sources) // TODO: for now assumes filepath dir contains all tests, later all this // should be replaced with remix's & browser solidity compiler code filepath = (isDirectory ? filename : path.dirname(filename)) fs.readdirSync(filepath).forEach(file => { - sources[file] = {content: fs.readFileSync(path.join(filepath, file)).toString()} + // only process .sol files + if (file.split('.').pop() === 'sol') { + let c = fs.readFileSync(path.join(filepath, file)).toString() + if (file.indexOf('_test.sol') > 0) { + c = c.replace(/(pragma solidity \^\d+\.\d+\.\d+;)/, '$1\nimport \'remix_tests.sol\';') + } + sources[file] = { content: c } + } }) async.waterfall([ @@ -39,7 +47,7 @@ function compileFileOrFiles (filename, isDirectory, cb) { ], function (err, result) { let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') if (errors.length > 0) { - console.dir(errors) + signale.fatal(errors) return cb(new Error('errors compiling')) } cb(err, result.contracts) @@ -70,7 +78,7 @@ function compileContractSources (sources, importFileCb, cb) { ], function (err, result) { let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') if (errors.length > 0) { - console.dir(errors) + signale.fatal(errors) return cb(new Error('errors compiling')) } cb(err, result.contracts) diff --git a/remix-tests/src/index.js b/remix-tests/src/index.js index f8019f1dfa..d5e86afc6c 100644 --- a/remix-tests/src/index.js +++ b/remix-tests/src/index.js @@ -1,6 +1,7 @@ const async = require('async') const path = require('path') const fs = require('fs') +const { Signale } = require('signale') require('colors') let Compiler = require('./compiler.js') @@ -11,11 +12,34 @@ const Web3 = require('web3') const Provider = require('remix-simulator').Provider var createWeb3Provider = function () { + signale.info('Creating providers') let web3 = new Web3() web3.setProvider(new Provider()) return web3 } +// signale configuration +const options = { + types: { + result: { + badge: '\t✓', + label: '', + color: 'greenBright' + }, + name: { + badge: '\n\t◼', + label: '', + color: 'white' + }, + error: { + badge: '\t✘', + label: '', + color: 'redBright' + } + } +} +const signale = new Signale(options) + var runTestSources = function (contractSources, testCallback, resultCallback, finalCallback, importFileCb) { async.waterfall([ function compile (next) { @@ -134,11 +158,11 @@ var runTestFiles = function (filepath, isDirectory, web3) { var testCallback = function (result) { if (result.type === 'contract') { - console.log('\n ' + result.value) + signale.name(result.value.white) } else if (result.type === 'testPass') { - console.log('\t✓ '.green.bold + result.value.grey) + signale.result(result.value) } else if (result.type === 'testFailure') { - console.log('\t✘ '.bold.red + result.value.red) + signale.result(result.value.red) errors.push(result) } } diff --git a/remix-tests/src/run.js b/remix-tests/src/run.js index 6eb4aa2655..6a3815f007 100644 --- a/remix-tests/src/run.js +++ b/remix-tests/src/run.js @@ -2,6 +2,7 @@ const commander = require('commander') const Web3 = require('web3') const RemixTests = require('./index.js') const fs = require('fs') +const signale = require('signale') const Provider = require('remix-simulator').Provider @@ -16,7 +17,8 @@ commander.action(function (filename) { }) if (!process.argv.slice(2).length) { - console.log('please specify filename') + signale.fatal('Please specify a filename') + process.exit() } commander.parse(process.argv) diff --git a/remix-tests/tests/examples_1/simple_storage_test.sol b/remix-tests/tests/examples_1/simple_storage_test.sol index 896970933f..6c4b35942f 100644 --- a/remix-tests/tests/examples_1/simple_storage_test.sol +++ b/remix-tests/tests/examples_1/simple_storage_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "remix_tests.sol"; import "./simple_storage.sol"; contract MyTest { @@ -29,4 +28,3 @@ contract MyTest { } } - diff --git a/remix-tests/tests/examples_2/simple_storage_test.sol b/remix-tests/tests/examples_2/simple_storage_test.sol index 016b3c7f5d..b794095f5c 100644 --- a/remix-tests/tests/examples_2/simple_storage_test.sol +++ b/remix-tests/tests/examples_2/simple_storage_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "./tests.sol"; import "./simple_storage.sol"; contract MyTest { @@ -25,4 +24,3 @@ contract MyTest { } } - diff --git a/remix-tests/tests/examples_3/simple_string_test.sol b/remix-tests/tests/examples_3/simple_string_test.sol index 270c2719b8..918c97c88e 100644 --- a/remix-tests/tests/examples_3/simple_string_test.sol +++ b/remix-tests/tests/examples_3/simple_string_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "./tests.sol"; import "./simple_string.sol"; contract StringTest {