Skip to content

Commit 9d98f3f

Browse files
authored
Add error test suites for Buidler plugin (#428)
1 parent 5924706 commit 9d98f3f

File tree

2 files changed

+180
-1
lines changed

2 files changed

+180
-1
lines changed

test/units/buidler/errors.js

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
const assert = require('assert');
2+
const fs = require('fs');
3+
const path = require('path')
4+
const pify = require('pify')
5+
const shell = require('shelljs');
6+
const ganache = require('ganache-core-sc');
7+
8+
const verify = require('../../util/verifiers')
9+
const mock = require('../../util/integration');
10+
const plugin = require('../../../dist/buidler.plugin');
11+
12+
// =======
13+
// Errors
14+
// =======
15+
16+
describe('Buidler Plugin: error cases', function() {
17+
let buidlerConfig;
18+
let solcoverConfig;
19+
20+
beforeEach(() => {
21+
mock.clean();
22+
23+
mock.loggerOutput.val = '';
24+
solcoverConfig = { skipFiles: ['Migrations.sol']};
25+
buidlerConfig = mock.getDefaultBuidlerConfig();
26+
verify.cleanInitialState();
27+
})
28+
29+
afterEach(() => {
30+
mock.buidlerTearDownEnv();
31+
mock.clean();
32+
});
33+
34+
it('project contains no contract sources folder', async function() {
35+
mock.installFullProject('no-sources');
36+
mock.buidlerSetupEnv(this);
37+
38+
try {
39+
await this.env.run("coverage");
40+
assert.fail()
41+
} catch(err){
42+
assert(
43+
err.message.includes('Cannot locate expected contract sources folder'),
44+
`Should error when contract sources cannot be found:: ${err.message}`
45+
);
46+
47+
assert(
48+
err.message.includes('sc_temp/contracts'),
49+
`Error message should contain path:: ${err.message}`
50+
);
51+
}
52+
53+
verify.coverageNotGenerated(buidlerConfig);
54+
});
55+
56+
it('.solcover.js has syntax error', async function(){
57+
mock.installFullProject('bad-solcoverjs');
58+
mock.buidlerSetupEnv(this);
59+
60+
try {
61+
await this.env.run("coverage");
62+
assert.fail()
63+
} catch(err){
64+
assert(
65+
err.message.includes('Could not load .solcover.js config file.'),
66+
`Should notify when solcoverjs has syntax error:: ${err.message}`
67+
);
68+
}
69+
70+
verify.coverageNotGenerated(buidlerConfig);
71+
})
72+
73+
it('.solcover.js has incorrectly formatted option', async function(){
74+
solcoverConfig.port = "Antwerpen";
75+
76+
mock.install('Simple', 'simple.js', solcoverConfig);
77+
mock.buidlerSetupEnv(this);
78+
79+
try {
80+
await this.env.run("coverage");
81+
assert.fail()
82+
} catch (err) {
83+
assert(
84+
err.message.includes('config option'),
85+
`Should error on incorrect config options: ${err.message}`
86+
);
87+
}
88+
});
89+
90+
it('tries to launch with a port already in use', async function(){
91+
const server = ganache.server();
92+
93+
mock.install('Simple', 'simple.js', solcoverConfig);
94+
mock.buidlerSetupEnv(this);
95+
96+
await pify(server.listen)(8555);
97+
98+
try {
99+
await this.env.run("coverage");
100+
assert.fail();
101+
} catch(err){
102+
assert(
103+
err.message.includes('is already in use') &&
104+
err.message.includes('lsof'),
105+
`Should error on port-in-use with advice: ${err.message}`
106+
)
107+
}
108+
109+
await pify(server.close)();
110+
});
111+
112+
it('uses an invalid istanbul reporter', async function() {
113+
solcoverConfig = {
114+
silent: process.env.SILENT ? true : false,
115+
istanbulReporter: ['does-not-exist']
116+
};
117+
118+
mock.install('Simple', 'simple.js', solcoverConfig);
119+
mock.buidlerSetupEnv(this);
120+
121+
try {
122+
await this.env.run("coverage");
123+
assert.fail();
124+
} catch(err){
125+
assert(
126+
err.message.includes('does-not-exist') &&
127+
err.message.includes('coverage reports could not be generated'),
128+
`Should error on invalid reporter: ${err.message}`
129+
)
130+
}
131+
132+
});
133+
134+
// Truffle test contains syntax error
135+
it('truffle crashes', async function() {
136+
mock.install('Simple', 'truffle-crash.js', solcoverConfig);
137+
mock.buidlerSetupEnv(this);
138+
139+
try {
140+
await this.env.run("coverage");
141+
assert.fail()
142+
} catch(err){
143+
assert(err.toString().includes('SyntaxError'));
144+
}
145+
});
146+
147+
// Solidity syntax errors
148+
it('compilation failure', async function(){
149+
mock.install('SimpleError', 'simple.js', solcoverConfig);
150+
mock.buidlerSetupEnv(this);
151+
152+
try {
153+
await this.env.run("coverage");
154+
assert.fail()
155+
} catch(err){
156+
assert(err.message.includes('Compilation failed'));
157+
}
158+
159+
verify.coverageNotGenerated(buidlerConfig);
160+
});
161+
162+
it('instrumentation failure', async function(){
163+
mock.install('Unparseable', 'simple.js', solcoverConfig);
164+
mock.buidlerSetupEnv(this);
165+
166+
try {
167+
await this.env.run("coverage");
168+
assert.fail()
169+
} catch(err){
170+
assert(
171+
err.message.includes('Unparseable.sol.'),
172+
`Should throw instrumentation errors with file name: ${err.toString()}`
173+
);
174+
175+
assert(err.stack !== undefined, 'Should have error trace')
176+
}
177+
178+
verify.coverageNotGenerated(buidlerConfig);
179+
});
180+
})

test/units/truffle/errors.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ describe('Truffle Plugin: error cases', function() {
120120
}
121121
});
122122

123-
// This case *does* throw an error, but it's uncatch-able;
124123
it('tries to launch with a port already in use', async function(){
125124
const server = ganache.server();
126125

0 commit comments

Comments
 (0)