1 //
2 // Copyright 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 "compiler/preprocessor/Token.h"
9
10 namespace angle
11 {
12
13 class ErrorTest : public SimplePreprocessorTest
14 {};
15
TEST_F(ErrorTest,Empty)16 TEST_F(ErrorTest, Empty)
17 {
18 const char *str = "#error\n";
19 const char *expected = "\n";
20
21 using testing::_;
22 EXPECT_CALL(mDirectiveHandler, handleError(pp::SourceLocation(0, 1), ""));
23 // No error or warning.
24 EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
25
26 preprocess(str, expected);
27 }
28
TEST_F(ErrorTest,OneTokenMessage)29 TEST_F(ErrorTest, OneTokenMessage)
30 {
31 const char *str = "#error foo\n";
32 const char *expected = "\n";
33
34 using testing::_;
35 EXPECT_CALL(mDirectiveHandler, handleError(pp::SourceLocation(0, 1), " foo"));
36 // No error or warning.
37 EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
38
39 preprocess(str, expected);
40 }
41
TEST_F(ErrorTest,TwoTokenMessage)42 TEST_F(ErrorTest, TwoTokenMessage)
43 {
44 const char *str = "#error foo bar\n";
45 const char *expected = "\n";
46
47 using testing::_;
48 EXPECT_CALL(mDirectiveHandler, 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
TEST_F(ErrorTest,Comments)55 TEST_F(ErrorTest, Comments)
56 {
57 const char *str =
58 "/*foo*/"
59 "#"
60 "/*foo*/"
61 "error"
62 "/*foo*/"
63 "foo"
64 "/*foo*/"
65 "bar"
66 "/*foo*/"
67 "//foo"
68 "\n";
69 const char *expected = "\n";
70
71 using testing::_;
72 EXPECT_CALL(mDirectiveHandler, 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
TEST_F(ErrorTest,MissingNewline)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, handleError(pp::SourceLocation(0, 1), " foo"));
87 // Error reported about EOF.
88 EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_EOF_IN_DIRECTIVE, _, _));
89
90 preprocess(str, expected);
91 }
92
93 } // namespace angle
94