1 // Copyright (c) 2016 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "source/opt/log.h"
16 #include "gmock/gmock.h"
17 #include "gtest/gtest.h"
18 
19 namespace spvtools {
20 namespace {
21 
22 using ::testing::MatchesRegex;
23 
TEST(Log,Unimplemented)24 TEST(Log, Unimplemented) {
25   int invocation = 0;
26   auto consumer = [&invocation](spv_message_level_t level, const char* source,
27                                 const spv_position_t&, const char* message) {
28     ++invocation;
29     EXPECT_EQ(SPV_MSG_INTERNAL_ERROR, level);
30     EXPECT_THAT(source, MatchesRegex(".*log_test.cpp$"));
31     EXPECT_STREQ("unimplemented: the-ultimite-feature", message);
32   };
33 
34   SPIRV_UNIMPLEMENTED(consumer, "the-ultimite-feature");
35   EXPECT_EQ(1, invocation);
36 }
37 
TEST(Log,Unreachable)38 TEST(Log, Unreachable) {
39   int invocation = 0;
40   auto consumer = [&invocation](spv_message_level_t level, const char* source,
41                                 const spv_position_t&, const char* message) {
42     ++invocation;
43     EXPECT_EQ(SPV_MSG_INTERNAL_ERROR, level);
44     EXPECT_THAT(source, MatchesRegex(".*log_test.cpp$"));
45     EXPECT_STREQ("unreachable", message);
46   };
47 
48   SPIRV_UNREACHABLE(consumer);
49   EXPECT_EQ(1, invocation);
50 }
51 
52 }  // namespace
53 }  // namespace spvtools
54