bazel_test_runner.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python3
  2. """Checks various LLVM tool symlinks behave as expected."""
  3. __copyright__ = """
  4. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  5. Exceptions. See /LICENSE for license information.
  6. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. """
  8. import os
  9. import sys
  10. import unittest
  11. from bazel_tools.tools.python.runfiles import runfiles
  12. from bazel_integration_test.py import test_base
  13. class BazelExampleTest(test_base.TestBase):
  14. def setUp(self) -> None:
  15. test_base.TestBase.setUp(self)
  16. self.runfiles = runfiles.Create()
  17. self.install_module = self.runfiles.Rlocation(
  18. "carbon/toolchain/install/prefix/lib/carbon"
  19. )
  20. self.startup_flags = [
  21. "--ignore_all_rc_files",
  22. "--batch",
  23. ]
  24. self.flags = [
  25. f"--override_module=carbon_toolchain={self.install_module}"
  26. ]
  27. def log_lines(self, lines: list[str]) -> None:
  28. for line in lines:
  29. print(line, file=sys.stderr)
  30. def test_compile_lib(self) -> None:
  31. # TODO: Can remove this if we can make linking a binary sufficiently
  32. # efficient.
  33. exit_code, stdout, stderr = self.RunBazel(
  34. self.startup_flags + ["build"] + self.flags + ["//:example_lib"]
  35. )
  36. self.log_lines(stderr)
  37. self.AssertExitCode(exit_code, 0, stderr)
  38. @unittest.skipUnless(
  39. "CARBON_BAZEL_TEST_FULL" in os.environ,
  40. "Skipping expensive test step for minimal testing",
  41. )
  42. def test_run(self) -> None:
  43. exit_code, stdout, stderr = self.RunBazel(
  44. self.startup_flags + ["run"] + self.flags + ["//:example"]
  45. )
  46. self.log_lines(stderr)
  47. self.AssertExitCode(exit_code, 0, stderr)
  48. self.assertEqual(stdout, ["Hello World!"])
  49. if __name__ == "__main__":
  50. unittest.main()