Path: blob/main_old/src/tests/preprocessor_tests/error_test.cpp
1693 views
//1// Copyright 2012 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//56#include "PreprocessorTest.h"7#include "compiler/preprocessor/Token.h"89namespace angle10{1112class ErrorTest : public SimplePreprocessorTest13{};1415TEST_F(ErrorTest, Empty)16{17const char *str = "#error\n";18const char *expected = "\n";1920using testing::_;21EXPECT_CALL(mDirectiveHandler, handleError(pp::SourceLocation(0, 1), ""));22// No error or warning.23EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);2425preprocess(str, expected);26}2728TEST_F(ErrorTest, OneTokenMessage)29{30const char *str = "#error foo\n";31const char *expected = "\n";3233using testing::_;34EXPECT_CALL(mDirectiveHandler, handleError(pp::SourceLocation(0, 1), " foo"));35// No error or warning.36EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);3738preprocess(str, expected);39}4041TEST_F(ErrorTest, TwoTokenMessage)42{43const char *str = "#error foo bar\n";44const char *expected = "\n";4546using testing::_;47EXPECT_CALL(mDirectiveHandler, handleError(pp::SourceLocation(0, 1), " foo bar"));48// No error or warning.49EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);5051preprocess(str, expected);52}5354TEST_F(ErrorTest, Comments)55{56const char *str =57"/*foo*/"58"#"59"/*foo*/"60"error"61"/*foo*/"62"foo"63"/*foo*/"64"bar"65"/*foo*/"66"//foo"67"\n";68const char *expected = "\n";6970using testing::_;71EXPECT_CALL(mDirectiveHandler, handleError(pp::SourceLocation(0, 1), " foo bar"));72// No error or warning.73EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);7475preprocess(str, expected);76}7778TEST_F(ErrorTest, MissingNewline)79{80const char *str = "#error foo";81const char *expected = "";8283using testing::_;84// Directive successfully parsed.85EXPECT_CALL(mDirectiveHandler, handleError(pp::SourceLocation(0, 1), " foo"));86// Error reported about EOF.87EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_EOF_IN_DIRECTIVE, _, _));8889preprocess(str, expected);90}9192} // namespace angle939495