log_test.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include "source/opt/log.h"
  15. #include "gmock/gmock.h"
  16. #include "gtest/gtest.h"
  17. namespace spvtools {
  18. namespace {
  19. using ::testing::MatchesRegex;
  20. TEST(Log, Unimplemented) {
  21. int invocation = 0;
  22. auto consumer = [&invocation](spv_message_level_t level, const char* source,
  23. const spv_position_t&, const char* message) {
  24. ++invocation;
  25. EXPECT_EQ(SPV_MSG_INTERNAL_ERROR, level);
  26. EXPECT_THAT(source, MatchesRegex(".*log_test.cpp$"));
  27. EXPECT_STREQ("unimplemented: the-ultimite-feature", message);
  28. };
  29. SPIRV_UNIMPLEMENTED(consumer, "the-ultimite-feature");
  30. EXPECT_EQ(1, invocation);
  31. }
  32. TEST(Log, Unreachable) {
  33. int invocation = 0;
  34. auto consumer = [&invocation](spv_message_level_t level, const char* source,
  35. const spv_position_t&, const char* message) {
  36. ++invocation;
  37. EXPECT_EQ(SPV_MSG_INTERNAL_ERROR, level);
  38. EXPECT_THAT(source, MatchesRegex(".*log_test.cpp$"));
  39. EXPECT_STREQ("unreachable", message);
  40. };
  41. SPIRV_UNREACHABLE(consumer);
  42. EXPECT_EQ(1, invocation);
  43. }
  44. } // namespace
  45. } // namespace spvtools