Skip to content

Commit ec9a55e

Browse files
author
Leonardo
authored
Merge pull request #403 from ethereum/tests-errors
Add tests for error cases in StandardCompiler
2 parents 1d95d3f + 99df4ae commit ec9a55e

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

test/compiler.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,33 @@ function runTests (solc, versionText) {
3535
}
3636
}
3737

38+
function expectError (output, errorType, message) {
39+
if (output.errors) {
40+
for (var error in output.errors) {
41+
error = output.errors[error];
42+
if (error.type === errorType) {
43+
if (message) {
44+
return error.message.match(message) !== null;
45+
}
46+
return true;
47+
}
48+
}
49+
}
50+
return false;
51+
}
52+
53+
function expectNoError (output) {
54+
if (output.errors) {
55+
for (var error in output.errors) {
56+
error = output.errors[error];
57+
if (error.severity === 'error') {
58+
return false;
59+
}
60+
}
61+
}
62+
return true;
63+
}
64+
3865
tape(versionText, function (t) {
3966
var tape = t.test;
4067

@@ -532,6 +559,38 @@ function runTests (solc, versionText) {
532559
st.ok(L.length > 0);
533560
st.end();
534561
});
562+
563+
t.test('compiling standard JSON (invalid JSON)', function (st) {
564+
var output = JSON.parse(solc.compile('{invalid'));
565+
// TODO: change wrapper to output matching error
566+
st.ok(expectError(output, 'JSONError', 'Line 1, Column 2\n Missing \'}\' or object member name') || expectError(output, 'SOLCError', 'Invalid JSON supplied'));
567+
st.end();
568+
});
569+
570+
t.test('compiling standard JSON (invalid language)', function (st) {
571+
var output = JSON.parse(solc.compile('{"language":"InvalidSolidity","sources":{"cont.sol":{"content":""}}}'));
572+
// TODO: change wrapper to output matching error
573+
st.ok(expectError(output, 'JSONError', 'supported as a language.') || expectError(output, 'SOLCError', 'Only Solidity sources are supported'));
574+
st.end();
575+
});
576+
577+
t.test('compiling standard JSON (no sources)', function (st) {
578+
var output = JSON.parse(solc.compile('{"language":"Solidity"}'));
579+
// TODO: change wrapper to output matching error
580+
st.ok(expectError(output, 'JSONError', 'No input sources specified.') || expectError(output, 'SOLCError', 'No input specified'));
581+
st.end();
582+
});
583+
584+
t.test('compiling standard JSON (multiple sources on old compiler)', function (st) {
585+
var output = JSON.parse(solc.compile('{"language":"Solidity","sources":{"cont.sol":{"content":"import \\"lib.sol\\";"},"lib.sol":{"content":""}}}'));
586+
console.log(output);
587+
if (solc.features.multipleInputs) {
588+
st.ok(expectNoError(output));
589+
} else {
590+
st.ok(expectError(output, 'SOLCError', 'Multiple sources provided, but compiler only supports single input') || expectError(output, 'Parser error', 'Parser error: Source not found.'));
591+
}
592+
st.end();
593+
});
535594
});
536595
});
537596

wrapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function setupMethods (soljson) {
156156
}
157157

158158
function librariesSupplied (input) {
159-
if (input['settings'] !== null) {
159+
if (input['settings']) {
160160
return input['settings']['libraries'];
161161
}
162162
}

0 commit comments

Comments
 (0)