gtest_main.cpp 935 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "testing/base/gtest_main.h"
  5. #include <gtest/gtest.h>
  6. #include <string>
  7. #include "common/check.h"
  8. #include "common/exe_path.h"
  9. #include "common/init_llvm.h"
  10. static bool after_main = false;
  11. static llvm::StringRef exe_path;
  12. namespace Carbon::Testing {
  13. auto GetTestExePath() -> llvm::StringRef {
  14. CARBON_CHECK(after_main)
  15. << "Must not query the executable path until after `main` is entered!";
  16. return exe_path;
  17. }
  18. } // namespace Carbon::Testing
  19. auto main(int argc, char** argv) -> int {
  20. std::string exe_path_storage = Carbon::FindExecutablePath(argv[0]);
  21. exe_path = exe_path_storage;
  22. after_main = true;
  23. Carbon::InitLLVM init_llvm(argc, argv);
  24. testing::InitGoogleTest(&argc, argv);
  25. return RUN_ALL_TESTS();
  26. }