@@ -35,6 +35,33 @@ function runTests (solc, versionText) {
35
35
}
36
36
}
37
37
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
+
38
65
tape ( versionText , function ( t ) {
39
66
var tape = t . test ;
40
67
@@ -532,6 +559,38 @@ function runTests (solc, versionText) {
532
559
st . ok ( L . length > 0 ) ;
533
560
st . end ( ) ;
534
561
} ) ;
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
+ } ) ;
535
594
} ) ;
536
595
} ) ;
537
596
0 commit comments