Home | History | Annotate | Download | only in preprocessor_tests
      1 //
      2 // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
      3 // Use of this source code is governed by a BSD-style license that can be
      4 // found in the LICENSE file.
      5 //
      6 
      7 #include "PreprocessorTest.h"
      8 #include "Token.h"
      9 
     10 class ErrorTest : public PreprocessorTest
     11 {
     12 };
     13 
     14 TEST_F(ErrorTest, Empty)
     15 {
     16     const char* str = "#error\n";
     17     const char* expected = "\n";
     18 
     19     using testing::_;
     20     EXPECT_CALL(mDirectiveHandler, handleError(pp::SourceLocation(0, 1), ""));
     21     // No error or warning.
     22     EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
     23 
     24     preprocess(str, expected);
     25 }
     26 
     27 TEST_F(ErrorTest, OneTokenMessage)
     28 {
     29     const char* str = "#error foo\n";
     30     const char* expected = "\n";
     31 
     32     using testing::_;
     33     EXPECT_CALL(mDirectiveHandler,
     34                 handleError(pp::SourceLocation(0, 1), " foo"));
     35     // No error or warning.
     36     EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
     37 
     38     preprocess(str, expected);
     39 }
     40 
     41 TEST_F(ErrorTest, TwoTokenMessage)
     42 {
     43     const char* str = "#error foo bar\n";
     44     const char* expected = "\n";
     45 
     46     using testing::_;
     47     EXPECT_CALL(mDirectiveHandler,
     48                 handleError(pp::SourceLocation(0, 1), " foo bar"));
     49     // No error or warning.
     50     EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
     51 
     52     preprocess(str, expected);
     53 }
     54 
     55 TEST_F(ErrorTest, Comments)
     56 {
     57     const char* str = "/*foo*/"
     58                       "#"
     59                       "/*foo*/"
     60                       "error"
     61                       "/*foo*/"
     62                       "foo"
     63                       "/*foo*/"
     64                       "bar"
     65                       "/*foo*/"
     66                       "//foo"
     67                       "\n";
     68     const char* expected = "\n";
     69 
     70     using testing::_;
     71     EXPECT_CALL(mDirectiveHandler,
     72                 handleError(pp::SourceLocation(0, 1), " foo bar"));
     73     // No error or warning.
     74     EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
     75 
     76     preprocess(str, expected);
     77 }
     78 
     79 TEST_F(ErrorTest, MissingNewline)
     80 {
     81     const char* str = "#error foo";
     82     const char* expected = "";
     83 
     84     using testing::_;
     85     // Directive successfully parsed.
     86     EXPECT_CALL(mDirectiveHandler,
     87                 handleError(pp::SourceLocation(0, 1), " foo"));
     88     // Error reported about EOF.
     89     EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::EOF_IN_DIRECTIVE, _, _));
     90 
     91     preprocess(str, expected);
     92 }
     93