inject import statement only if not present

pull/5370/head
0mkar 6 years ago
parent ac099ce2f7
commit 88ecfc587f
  1. 1
      remix-tests/examples/simple_storage2_test.sol
  2. 10
      remix-tests/src/compiler.js

@ -1,4 +1,5 @@
pragma solidity ^0.4.7;
import "remix_test.sol";
import "./simple_storage.sol";
contract MyTest2 {

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

Loading…
Cancel
Save