@@ -40,10 +40,23 @@ if (args._.length) {
4040 }
4141}
4242
43+ const EXPECT_ERROR_PREFIX = '// Expect error:' ;
44+
45+ // Returns an array of error strings to expect, or null if compilation should succeed.
46+ function getExpectedErrors ( filePath ) {
47+ const lines = fs . readFileSync ( filePath ) . toString ( ) . split ( '\n' ) ;
48+ const expectErrorLines = lines . filter ( line => line . startsWith ( EXPECT_ERROR_PREFIX ) ) ;
49+ if ( expectErrorLines . length === 0 ) {
50+ return null ;
51+ }
52+ return expectErrorLines . map ( line => line . slice ( EXPECT_ERROR_PREFIX . length ) . trim ( ) ) ;
53+ }
54+
4355// TODO: asc's callback is synchronous here. This might change.
4456tests . forEach ( filename => {
4557 console . log ( chalk . whiteBright ( "Testing compiler/" + filename ) + "\n" ) ;
4658
59+ const expectedErrors = getExpectedErrors ( path . join ( basedir , filename ) ) ;
4760 const basename = filename . replace ( / \. t s $ / , "" ) ;
4861
4962 const stdout = asc . createMemoryStream ( ) ;
@@ -66,6 +79,24 @@ tests.forEach(filename => {
6679 stderr : stderr
6780 } , err => {
6881 console . log ( ) ;
82+
83+ if ( expectedErrors ) {
84+ const stderrString = stderr . toString ( ) ;
85+ for ( const expectedError of expectedErrors ) {
86+ if ( ! stderrString . includes ( expectedError ) ) {
87+ console . log ( `Expected error "${ expectedError } " was not in the error output.` ) ;
88+ console . log ( "- " + chalk . red ( "error check ERROR" ) ) ;
89+ failedTests . push ( basename ) ;
90+ console . log ( ) ;
91+ return ;
92+ }
93+ }
94+ console . log ( "- " + chalk . green ( "error check OK" ) ) ;
95+ ++ successes ;
96+ console . log ( ) ;
97+ return ;
98+ }
99+
69100 if ( err )
70101 stderr . write ( err + os . EOL ) ;
71102 var actual = stdout . toString ( ) . replace ( / \r \n / g, "\n" ) ;
0 commit comments