Skip to content

Commit 54aa139

Browse files
committed
simplify
1 parent 74d94f5 commit 54aa139

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

toolchain/install/llvm_symlinks_test.py

+15-18
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ def get_link_cmd(self, clang: Path) -> list[str | Path]:
3838
self.test_o_file,
3939
]
4040

41+
def unsupported(self, stderr: str) -> None:
42+
self.fail(f"Unsupported platform '{platform.uname()}':\n{stderr}")
43+
4144
# Note that we can't test `clang` vs. `clang++` portably. The only commands
4245
# with useful differences are _link_ commands, and those need to build
4346
# 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]:
4750
# test expectations.
4851
def test_clang(self) -> None:
4952
bin = self.install_root / "lib/carbon/llvm/bin/clang"
53+
# Most errors are caught by ensuring the command succeeds.
5054
run = subprocess.run(
5155
self.get_link_cmd(bin), check=True, capture_output=True, text=True
5256
)
5357

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.
5959
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.
6960
self.assertNotRegex(run.stderr, r'"-lstdc\+\+"')
7061
elif platform.system() == "Darwin":
71-
unsupported()
62+
self.assertNotRegex(run.stderr, r'"-lc\+\+"')
7263
else:
73-
unsupported()
64+
self.unsupported(run.stderr)
7465

7566
# Note that we can't test `clang` vs. `clang++` portably. See the comment on
7667
# `test_clang` for details.
@@ -79,8 +70,14 @@ def test_clangplusplus(self) -> None:
7970
run = subprocess.run(
8071
self.get_link_cmd(bin), check=True, capture_output=True, text=True
8172
)
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)
8481

8582
def test_clang_cl(self) -> None:
8683
bin = self.install_root / "lib/carbon/llvm/bin/clang-cl"

0 commit comments

Comments
 (0)