diff --git a/remix-tests/examples/simple_storage2_test.sol b/remix-tests/examples/simple_storage2_test.sol index 814570aae7..3f0bc511c6 100644 --- a/remix-tests/examples/simple_storage2_test.sol +++ b/remix-tests/examples/simple_storage2_test.sol @@ -1,4 +1,5 @@ pragma solidity ^0.4.7; +import "remix_test.sol"; import "./simple_storage.sol"; contract MyTest2 { diff --git a/remix-tests/src/compiler.js b/remix-tests/src/compiler.js index 2fc3e2e52d..5b31cb70b2 100644 --- a/remix-tests/src/compiler.js +++ b/remix-tests/src/compiler.js @@ -1,11 +1,16 @@ +/* eslint no-extend-native: "warn" */ 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 +String.prototype.regexIndexOf = function (regex, startpos) { + var indexOf = this.substring(startpos || 0).search(regex) + return (indexOf >= 0) ? (indexOf + (startpos || 0)) : indexOf +} +// TODO: replace this with remix's own compiler code function compileFileOrFiles (filename, isDirectory, cb) { let compiler, filepath @@ -23,7 +28,8 @@ function compileFileOrFiles (filename, isDirectory, cb) { // only process .sol files if (file.split('.').pop() === 'sol') { let c = fs.readFileSync(path.join(filepath, file)).toString() - if (file.indexOf('_test.sol') > 0) { + const s = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm + if (file.indexOf('_test.sol') > 0 && c.regexIndexOf(s) < 0) { c = c.replace(/(pragma solidity \^\d+\.\d+\.\d+;)/, '$1\nimport \'remix_tests.sol\';') } sources[file] = { content: c } @@ -58,7 +64,7 @@ function compileContractSources (sources, importFileCb, cb) { let compiler, filepath if (!sources['remix_tests.sol']) { - sources['remix_tests.sol'] = {content: require('../sol/tests.sol.js')} + sources['remix_tests.sol'] = { content: require('../sol/tests.sol.js') } } async.waterfall([