@@ -38,6 +38,9 @@ def get_link_cmd(self, clang: Path) -> list[str | Path]:
38
38
self .test_o_file ,
39
39
]
40
40
41
+ def unsupported (self , stderr : str ) -> None :
42
+ self .fail (f"Unsupported platform '{ platform .uname ()} ':\n { stderr } " )
43
+
41
44
# Note that we can't test `clang` vs. `clang++` portably. The only commands
42
45
# with useful differences are _link_ commands, and those need to build
43
46
# runtime libraries on demand, which requires the host to be able to compile
@@ -47,30 +50,18 @@ def get_link_cmd(self, clang: Path) -> list[str | Path]:
47
50
# test expectations.
48
51
def test_clang (self ) -> None :
49
52
bin = self .install_root / "lib/carbon/llvm/bin/clang"
53
+ # Most errors are caught by ensuring the command succeeds.
50
54
run = subprocess .run (
51
55
self .get_link_cmd (bin ), check = True , capture_output = True , text = True
52
56
)
53
57
54
- def unsupported () -> None :
55
- self .fail (
56
- f"Unsupported platform '{ platform .uname ()} ':\n { run .stderr } "
57
- )
58
-
58
+ # Also ensure that it correctly didn't imply a C++ link.
59
59
if platform .system () == "Linux" :
60
- # Check that we do have a plausible link command.
61
- if platform .machine () == "x86_64" :
62
- self .assertRegex (run .stderr , r'"-m" "elf_x86_64"' )
63
- elif platform .machine () == "AArch64" :
64
- self .assertRegex (run .stderr , r'"-m" "aarch64linux"' )
65
- else :
66
- unsupported ()
67
-
68
- # Ensure it doesn't contain the C++ standard library.
69
60
self .assertNotRegex (run .stderr , r'"-lstdc\+\+"' )
70
61
elif platform .system () == "Darwin" :
71
- unsupported ( )
62
+ self . assertNotRegex ( run . stderr , r'"-lc\+\+"' )
72
63
else :
73
- unsupported ()
64
+ self . unsupported (run . stderr )
74
65
75
66
# Note that we can't test `clang` vs. `clang++` portably. See the comment on
76
67
# `test_clang` for details.
@@ -79,8 +70,14 @@ def test_clangplusplus(self) -> None:
79
70
run = subprocess .run (
80
71
self .get_link_cmd (bin ), check = True , capture_output = True , text = True
81
72
)
82
- # Ensure it does contain the C++ standard library.
83
- self .assertRegex (run .stderr , r'"-lstdc\+\+"' )
73
+
74
+ # Ensure that this binary _does_ imply a C++ link.
75
+ if platform .system () == "Linux" :
76
+ self .assertRegex (run .stderr , r'"-lstdc\+\+"' )
77
+ elif platform .system () == "Darwin" :
78
+ self .assertRegex (run .stderr , r'"-lc\+\+"' )
79
+ else :
80
+ self .unsupported (run .stderr )
84
81
85
82
def test_clang_cl (self ) -> None :
86
83
bin = self .install_root / "lib/carbon/llvm/bin/clang-cl"
0 commit comments