Skip to content

Commit

Permalink
loop over _test.sol to run test
Browse files Browse the repository at this point in the history
move test injection in importFileCb
  • Loading branch information
yann300 committed Jun 1, 2018
1 parent 81dfe51 commit 0e96c32
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var yo = require('yo-yo')
var async = require('async')
var request = require('request')
var remixLib = require('remix-lib')
var remixTests = require('remix-tests')
var EventManager = remixLib.EventManager

var UniversalDApp = require('./universal-dapp.js')
Expand Down Expand Up @@ -253,6 +254,9 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
}

function importFileCb (url, filecb) {
if (url.indexOf('/remix_tests.sol') !== -1) {
return filecb(null, remixTests.assertLibCode)
}
var provider = fileManager.fileProviderOf(url)
if (provider) {
provider.exists(url, (error, exist) => {
Expand Down Expand Up @@ -714,6 +718,10 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
// ---------------- Righthand-panel --------------------

var rhpAPI = {
importFileCb: importFileCb,
filesFromPath: (path, cb) => {
fileManager.filesFromPath(path, cb)
},
newAccount: (pass, cb) => {
udapp.newAccount(pass, cb)
},
Expand Down
4 changes: 0 additions & 4 deletions src/app/compiler/compiler-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
var base64 = require('js-base64').Base64
var swarmgw = require('swarmgw')
var request = require('request')
var assertLibCode = require('remix-tests').assertLibCode

module.exports = class CompilerImports {
constructor () {
Expand Down Expand Up @@ -71,9 +70,6 @@ module.exports = class CompilerImports {

import (url, loadingCb, cb) {
var self = this
if (url === 'remix_tests.sol') {
return cb(null, assertLibCode, 'remix_tests.sol', 'remix_tests', 'remix_tests.sol')
}
var imported = this.previouslyHandled[url]
if (imported) {
return cb(null, imported.content, imported.cleanUrl, imported.type, url)
Expand Down
8 changes: 8 additions & 0 deletions src/app/files/fileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ class FileManager {
}
}

filesFromPath (path, cb) {
var provider = this.fileProviderOf(path)
if (provider) {
return provider.resolveDirectory(path, (error, filesTree) => { cb(error, filesTree) })
}
cb(`provider for path ${path} not found`)
}

fileProviderOf (file) {
var provider = file.match(/[^/]*/)
if (provider !== null && this.opt.filesProviders[provider[0]]) {
Expand Down
21 changes: 19 additions & 2 deletions src/app/tabs/test-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,27 @@ function testTabView (api) {
})
}

function runTest (testFilePath) {
var provider = api.fileProviderOf(testFilePath)
provider.get(testFilePath, (error, content) => {
if (!error) {
var runningTest = {}
runningTest[testFilePath] = { content }
remixTests.runTestSources(runningTest, testCallback, resultsCallback, finalCallback, api.importFileCb)
}
})
}

let runTests = function () {
let contractSources = api.getAllSources()
container.innerHTML = ''
remixTests.runTestSources(contractSources, testCallback, resultsCallback, finalCallback)
var path = api.currentPath()
api.filesFromPath(path, (error, files) => {
if (!error) {
for (var file in files) {
if (/.(_test.sol)$/.exec(file)) runTest(path + file)
}
}
})
}

return yo`
Expand Down

0 comments on commit 0e96c32

Please sign in to comment.