From 9f8db3effe1db2e2885dc9d5973f3f70b9aabc97 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Tue, 23 Jul 2019 16:52:45 -0700 Subject: [PATCH] Update comment tests --- .../postFunctionDeclarationComment.sol | 4 +- test/units/comments.js | 40 +++++++------------ test/util/util.js | 1 + 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/test/soliditySources/contracts/comments/postFunctionDeclarationComment.sol b/test/soliditySources/contracts/comments/postFunctionDeclarationComment.sol index 4c6fdca..b14c774 100644 --- a/test/soliditySources/contracts/comments/postFunctionDeclarationComment.sol +++ b/test/soliditySources/contracts/comments/postFunctionDeclarationComment.sol @@ -3,5 +3,7 @@ pragma solidity ^0.5.0; contract Test { function a(bool test) public {//Comment immediately after function declaration } - function b(bool test) public {uint8 x=1;}//Comment immediately after function closes + function b(bool test) public { + uint8 x=1; + }//Comment immediately after function closes } diff --git a/test/units/comments.js b/test/units/comments.js index 3aeceb4..d1e6e3e 100644 --- a/test/units/comments.js +++ b/test/units/comments.js @@ -1,38 +1,26 @@ -/* eslint-env node, mocha */ - -/*const path = require('path'); -const getInstrumentedVersion = require('./../lib/instrumentSolidity.js'); -const util = require('./util/util.js'); -const solc = require('solc'); const assert = require('assert'); +const util = require('./../util/util.js'); describe('comments', () => { - const filePath = path.resolve('./test.sol'); - const pathPrefix = './'; it('should cover functions even if comments are present immediately after the opening {', () => { - const contract = util.getCode('comments/postFunctionDeclarationComment.sol'); - const info = getInstrumentedVersion(contract, filePath); - const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract))); - util.report(output.errors); + const info = util.instrumentAndCompile('comments/postFunctionDeclarationComment'); + util.report(info.solcOutput.errors); }); + it('should cover lines even if comments are present', () => { - const contract = util.getCode('comments/postLineComment.sol'); - const info = getInstrumentedVersion(contract, filePath); - const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract))); - assert.deepEqual([6, 5], info.runnableLines); - util.report(output.errors); + const info = util.instrumentAndCompile('comments/postLineComment'); + assert.deepEqual([6, 5], info.instrumented.runnableLines); + util.report(info.solcOutput.errors); }); + it('should cover contracts even if comments are present', () => { - const contract = util.getCode('comments/postContractComment.sol'); - const info = getInstrumentedVersion(contract, filePath); - const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract))); - util.report(output.errors); + const info = util.instrumentAndCompile('comments/postContractComment'); + util.report(info.solcOutput.errors); }); + it('should cover if statements even if comments are present immediately after opening { ', () => { - const contract = util.getCode('comments/postIfStatementComment.sol'); - const info = getInstrumentedVersion(contract, filePath); - const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract))); - util.report(output.errors); + const info = util.instrumentAndCompile('comments/postIfStatementComment'); + util.report(info.solcOutput.errors); }); -});*/ +}); diff --git a/test/util/util.js b/test/util/util.js index d9dcf3a..1faa8d4 100644 --- a/test/util/util.js +++ b/test/util/util.js @@ -59,6 +59,7 @@ function instrumentAndCompile(sourceName) { const contract = getCode(`${sourceName}.sol`) const instrumenter = new Instrumenter(); const instrumented = instrumenter.instrument(contract, filePath); + return { contract: contract, instrumented: instrumented,