From d80eb051fe00447221fda4abb48637965d86407f Mon Sep 17 00:00:00 2001 From: cgewecke Date: Tue, 10 Sep 2019 15:39:47 -0700 Subject: [PATCH] Add --version cli flag --- README.md | 4 ++-- dist/truffle.plugin.js | 7 ++++++- lib/ui.js | 10 ++++++---- test/units/app.js | 7 +++++++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7ec29c6..cdfd1e5 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ $ npm install --save-dev solidity-coverage + Tests run more slowly while coverage is being generated. + Contracts consume more gas while coverage is being generated. + solidity-coverage launches its own in-process ganache instance. You can - set its [options] via the `providerOptions` key in your .solcover.js - config file. + set its [options](https://github.com/trufflesuite/ganache-core#options) via + the `providerOptions` key in your `.solcover.js` config file. ### Truffle >= V5: setup and run diff --git a/dist/truffle.plugin.js b/dist/truffle.plugin.js index 85d8bb0..945c1f6 100644 --- a/dist/truffle.plugin.js +++ b/dist/truffle.plugin.js @@ -26,6 +26,7 @@ */ const App = require('./../lib/app'); +const pkg = require('./../package.json'); const req = require('req-cwd'); const death = require('death'); const path = require('path'); @@ -66,7 +67,7 @@ async function plugin(truffleConfig){ // Instrument and test.. try { - death(app.cleanUp); + death(app.cleanUp); // This doesn't work... // Launch in-process provider const provider = await app.provider(truffle.ganache); @@ -77,6 +78,10 @@ async function plugin(truffleConfig){ app.ui.report('truffle-version', [truffle.version]); app.ui.report('ganache-version', [ganacheVersion]); + app.ui.report('coverage-version',[pkg.version]); + + // Bail early if user ran: --version + if (truffleConfig.version) return; // Write instrumented sources to temp folder app.instrument(); diff --git a/lib/ui.js b/lib/ui.js index 4ec4142..eae47a1 100644 --- a/lib/ui.js +++ b/lib/ui.js @@ -28,11 +28,13 @@ class UI { 'truffle-help': `Usage: truffle run coverage [options]\n\n` + `Options:\n` + - ` --file: path (or glob) to run subset of JS test files\n` + - ` --solcoverjs: relative path to .solcover.js (ex: ./../.solcover.js)\n`, + ` --file: path (or glob) to subset of JS test files. (Quote your globs)\n` + + ` --solcoverjs: relative path to .solcover.js (ex: ./../.solcover.js)\n` + + ` --version: version info\n`, - 'truffle-version': `${ct} ${c.bold('truffle')}: v${args[0]}`, - 'ganache-version': `${ct} ${c.bold('ganache-core')}: ${args[0]}`, + 'truffle-version': `${ct} ${c.bold('truffle')}: v${args[0]}`, + 'ganache-version': `${ct} ${c.bold('ganache-core')}: ${args[0]}`, + 'coverage-version': `${ct} ${c.bold('solidity-coverage')}: v${args[0]}`, 'instr-start': `\n${c.bold('Instrumenting for coverage...')}` + `\n${c.bold('=============================')}\n`, diff --git a/test/units/app.js b/test/units/app.js index 1323806..c3422f5 100644 --- a/test/units/app.js +++ b/test/units/app.js @@ -183,6 +183,13 @@ describe('app', function() { await plugin(truffleConfig); }) + it('truffle run coverage --version', async function(){ + assertCleanInitialState(); + truffleConfig.version = "true"; + mock.install('Simple', 'simple.js', solcoverConfig); + await plugin(truffleConfig); + }) + it('truffle run coverage --file test/', async function() { assertCleanInitialState();