Fix "typesef" typo in a test.
The test wasn't failing because we weren't checking the return value of
runOnCodeWithLifetimeHandlers(). This CL fixes that and also adds a test to
check that compile errors are caught.
PiperOrigin-RevId: 431629822
diff --git a/lifetime_annotations/lifetime_annotations_test.cc b/lifetime_annotations/lifetime_annotations_test.cc
index 4a4ed22..040cd05 100644
--- a/lifetime_annotations/lifetime_annotations_test.cc
+++ b/lifetime_annotations/lifetime_annotations_test.cc
@@ -44,7 +44,7 @@
const clang::tooling::FileContentMappings& file_contents =
clang::tooling::FileContentMappings()) {
absl::StatusOr<NamedFuncLifetimes> result;
- runOnCodeWithLifetimeHandlers(
+ bool success = runOnCodeWithLifetimeHandlers(
llvm::StringRef(code.data(), code.size()),
[&result](clang::ASTContext& ast_context,
const LifetimeAnnotationContext& lifetime_context) {
@@ -92,6 +92,11 @@
},
{}, file_contents);
+ if (!success) {
+ return absl::UnknownError(
+ "Error extracting lifetimes. (Compilation error?)");
+ }
+
return result;
}
};
@@ -103,6 +108,15 @@
IsOkAndHolds(LifetimesAre({{"f", "()"}})));
}
+TEST_F(LifetimeAnnotationsTest, Failure_CompileError) {
+ EXPECT_THAT(
+ GetNamedLifetimeAnnotations(R"(
+ undefined f(undefined);
+ )"),
+ StatusIs(absl::StatusCode::kUnknown,
+ StartsWith("Error extracting lifetimes. (Compilation error?)")));
+}
+
TEST_F(LifetimeAnnotationsTest, Failure_NoAnnotationsNoLifetimeElision) {
EXPECT_THAT(GetNamedLifetimeAnnotations(R"(
int** f(int*);
@@ -202,7 +216,7 @@
TEST_F(LifetimeAnnotationsTest, LifetimeElision_ArrayParamAsTypedefLifetimes) {
EXPECT_THAT(GetNamedLifetimeAnnotations(R"(
#pragma clang lifetime_elision
- typesef int Arr[2];
+ typedef int Arr[2];
void f(Arr);
)"),
IsOkAndHolds(LifetimesAre({{"f", "a"}})));