summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Tooling/CompilationDatabase.h9
-rw-r--r--clang/unittests/Tooling/CompilationDatabaseTest.cpp28
2 files changed, 37 insertions, 0 deletions
diff --git a/clang/include/clang/Tooling/CompilationDatabase.h b/clang/include/clang/Tooling/CompilationDatabase.h
index 185e4968797..37e515fdc09 100644
--- a/clang/include/clang/Tooling/CompilationDatabase.h
+++ b/clang/include/clang/Tooling/CompilationDatabase.h
@@ -59,6 +59,15 @@ struct CompileCommand {
/// The output file associated with the command.
std::string Output;
+
+ friend bool operator==(const CompileCommand &LHS, const CompileCommand &RHS) {
+ return LHS.Directory == RHS.Directory && LHS.Filename == RHS.Filename &&
+ LHS.CommandLine == RHS.CommandLine && LHS.Output == RHS.Output;
+ }
+
+ friend bool operator!=(const CompileCommand &LHS, const CompileCommand &RHS) {
+ return !(LHS == RHS);
+ }
};
/// Interface for compilation databases.
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 42497f70698..ffc1d5b3a4a 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -736,5 +736,33 @@ TEST_F(InterpolateTest, Case) {
EXPECT_EQ(getCommand("foo/bar/baz/shout.C"), "clang -D FOO/BAR/BAZ/SHOUT.cc");
}
+TEST(CompileCommandTest, EqualityOperator) {
+ CompileCommand CCRef("/foo/bar", "hello.c", {"a", "b"}, "hello.o");
+ CompileCommand CCTest = CCRef;
+
+ EXPECT_TRUE(CCRef == CCTest);
+ EXPECT_FALSE(CCRef != CCTest);
+
+ CCTest = CCRef;
+ CCTest.Directory = "/foo/baz";
+ EXPECT_FALSE(CCRef == CCTest);
+ EXPECT_TRUE(CCRef != CCTest);
+
+ CCTest = CCRef;
+ CCTest.Filename = "bonjour.c";
+ EXPECT_FALSE(CCRef == CCTest);
+ EXPECT_TRUE(CCRef != CCTest);
+
+ CCTest = CCRef;
+ CCTest.CommandLine.push_back("c");
+ EXPECT_FALSE(CCRef == CCTest);
+ EXPECT_TRUE(CCRef != CCTest);
+
+ CCTest = CCRef;
+ CCTest.Output = "bonjour.o";
+ EXPECT_FALSE(CCRef == CCTest);
+ EXPECT_TRUE(CCRef != CCTest);
+}
+
} // end namespace tooling
} // end namespace clang
OpenPOWER on IntegriCloud