fix import, inject remix_tests.sol, use signale for logging

pull/7/head
0mkar 6 years ago
parent 9905f5fc1f
commit 853234175f
  1. 2
      remix-tests/examples/simple_storage2_test.sol
  2. 2
      remix-tests/examples/simple_storage_test.sol
  3. 1
      remix-tests/package.json
  4. 16
      remix-tests/src/compiler.js
  5. 30
      remix-tests/src/index.js
  6. 4
      remix-tests/src/run.js
  7. 2
      remix-tests/tests/examples_1/simple_storage_test.sol
  8. 2
      remix-tests/tests/examples_2/simple_storage_test.sol
  9. 1
      remix-tests/tests/examples_3/simple_string_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 {
}
}

@ -1,5 +1,4 @@
pragma solidity ^0.4.7;
import "./tests.sol";
import "./simple_storage.sol";
contract MyTest {
@ -26,4 +25,3 @@ contract MyTest {
}
}

@ -43,6 +43,7 @@
"commander": "^2.13.0",
"remix-simulator": "0.0.3",
"remix-solidity": "^0.2.6",
"signale": "^1.2.1",
"solc": "^0.4.24",
"standard": "^10.0.3",
"web3": "1.0.0-beta.27"

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

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

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

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

@ -1,5 +1,4 @@
pragma solidity ^0.4.7;
import "./tests.sol";
import "./simple_storage.sol";
contract MyTest {
@ -25,4 +24,3 @@ contract MyTest {
}
}

@ -1,5 +1,4 @@
pragma solidity ^0.4.7;
import "./tests.sol";
import "./simple_string.sol";
contract StringTest {

Loading…
Cancel
Save