[PATCH] Added testing to test migration of files in a compilation database

Ariel Bernal ariel.j.bernal at intel.com
Wed Sep 18 09:09:37 PDT 2013


Hi revane, tareqsiraj, Sarcasm,

Tests include 
- A compilation database is detected form build path specified by -p.
- A compilation database is detected from source0.
- A fixed compilation database is provided.
- Uses of -include/exclude along with a compilation database.

http://llvm-reviews.chandlerc.com/D1710

Files:
  clang-modernize/tool/ClangModernize.cpp
  test/clang-modernize/Compilations/compilations.cpp
  test/clang-modernize/Compilations/compilations_expected.cpp
  test/clang-modernize/Compilations/compile_commands.json
  test/clang-modernize/Compilations/main.cpp

Index: clang-modernize/tool/ClangModernize.cpp
===================================================================
--- clang-modernize/tool/ClangModernize.cpp
+++ clang-modernize/tool/ClangModernize.cpp
@@ -292,6 +292,9 @@
             CompilationDatabase::autoDetectFromSource(SourcePaths[0],
                                                       ErrorMessage))
       return Compilations;
+    // Reset ErrorMessage since a fix compilation database will be created if
+    // it fails to detect one from source.
+    ErrorMessage = "";
     // If no compilation database can be detected from source then we create a
     // fixed compilation database with c++11 support.
     std::string CommandLine[] = { "-std=c++11" };
Index: test/clang-modernize/Compilations/compilations.cpp
===================================================================
--- /dev/null
+++ test/clang-modernize/Compilations/compilations.cpp
@@ -0,0 +1,6 @@
+// This is just a dummy run command to keep lit happy. Tests for this file are
+// in main.cpp
+// RUN: true
+void foo() {
+  int *p = 0;
+}
Index: test/clang-modernize/Compilations/compilations_expected.cpp
===================================================================
--- /dev/null
+++ test/clang-modernize/Compilations/compilations_expected.cpp
@@ -0,0 +1,6 @@
+// This is just a dummy run command to keep lit happy. Tests for this file are
+// in main.cpp
+// RUN: true
+void foo() {
+  int *p = nullptr;
+}
Index: test/clang-modernize/Compilations/compile_commands.json
===================================================================
--- /dev/null
+++ test/clang-modernize/Compilations/compile_commands.json
@@ -0,0 +1,17 @@
+[
+{
+  "directory": "$(path)/a1/",
+  "command": "clang++ -o compilations.o -c $(path)/a1/compilations.cpp -std=c++11",
+  "file": "$(path)/a1/compilations.cpp"
+},
+{
+  "directory": "$(path)/a2/",
+  "command": "clang++ -o compilations.o -c $(path)/a2/compilations.cpp -std=c++11",
+  "file": "$(path)/a2/compilations.cpp"
+},
+{
+  "directory": "$(path)/a3/",
+  "command": "clang++ -o compilations.o -c $(path)/a3/compilations.cpp -std=c++11",
+  "file": "$(path)/a3/compilations.cpp"
+}
+]
Index: test/clang-modernize/Compilations/main.cpp
===================================================================
--- /dev/null
+++ test/clang-modernize/Compilations/main.cpp
@@ -0,0 +1,54 @@
+// The following block tests:
+//   - A compilation database is detected from build path specified by -p.
+//   - A compilation database is detected from source0.
+//   - A fixed compilation database is provided.
+//   - Uses of -include/exclude.
+
+// RUN: rm -rf %T/SourcesTest
+// RUN: mkdir -p %T/SourcesTest
+// RUN: mkdir -p %T/SourcesTest/a1
+// RUN: mkdir -p %T/SourcesTest/a2
+// RUN: mkdir -p %T/SourcesTest/a3
+
+// Check that files are transformed when -- is specified.
+// RUN: echo %T/SourcesTest/a1 %T/SourcesTest/a2 %T/SourcesTest/a3 | xargs -n 1 cp %S/compilations.cpp
+// RUN: cp %S/compilations_expected.cpp %T
+// RUN: clang-modernize -use-nullptr %T/SourcesTest/a1/compilations.cpp %T/SourcesTest/a3/compilations.cpp --
+// RUN: diff -b %T/compilations_expected.cpp %T/SourcesTest/a1/compilations.cpp
+// RUN: not diff -b %T/compilations_expected.cpp %T/SourcesTest/a2/compilations.cpp
+// RUN: diff -b %T/compilations_expected.cpp %T/SourcesTest/a3/compilations.cpp
+
+// Check that only files not explicitly excluded are transformed.
+// RUN: echo %T/SourcesTest/a1 %T/SourcesTest/a2 %T/SourcesTest/a3 | xargs -n 1 cp %S/compilations.cpp
+// RUN: cp %S/compilations_expected.cpp %T/SourcesTest
+// RUN: clang-modernize -use-nullptr %T/SourcesTest/a1/compilations.cpp %T/SourcesTest/a2/compilations.cpp %T/SourcesTest/a3/compilations.cpp -exclude=%T/SourcesTest/a2 --
+// RUN: diff -b %T/compilations_expected.cpp %T/SourcesTest/a1/compilations.cpp
+// RUN: not diff -b %T/compilations_expected.cpp %T/SourcesTest/a2/compilations.cpp
+// RUN: diff -b %T/compilations_expected.cpp %T/SourcesTest/a3/compilations.cpp
+
+// The following test will make use of a compilation database
+// RUN: sed -e 's#$(path)#%/T/SourcesTest#g' %S/compile_commands.json > %T/compile_commands.json
+
+// Check that a compilation database can be detected from source0
+// RUN: echo %T/SourcesTest/a1 %T/SourcesTest/a2 %T/SourcesTest/a3 | xargs -n 1 cp %S/compilations.cpp
+// RUN: cp %S/compilations_expected.cpp %T
+// RUN: clang-modernize -use-nullptr %T/SourcesTest/a1/compilations.cpp %T/SourcesTest/a3/compilations.cpp
+// RUN: diff -b %T/compilations_expected.cpp %T/SourcesTest/a1/compilations.cpp
+// RUN: not diff -b %T/compilations_expected.cpp %T/SourcesTest/a2/compilations.cpp
+// RUN: diff -b %T/compilations_expected.cpp %T/SourcesTest/a3/compilations.cpp
+
+// Check that files are tranformed when -p is provided and files are specified.
+// RUN: echo %T/SourcesTest/a1 %T/SourcesTest/a2 %T/SourcesTest/a3 | xargs -n 1 cp %S/compilations.cpp
+// RUN: cp %S/compilations_expected.cpp %T
+// RUN: clang-modernize -use-nullptr -p=%T %T/SourcesTest/a1/compilations.cpp %T/SourcesTest/a3/compilations.cpp
+// RUN: diff -b %T/compilations_expected.cpp %T/SourcesTest/a1/compilations.cpp
+// RUN: not diff -b %T/compilations_expected.cpp %T/SourcesTest/a2/compilations.cpp
+// RUN: diff -b %T/compilations_expected.cpp %T/SourcesTest/a3/compilations.cpp
+
+// Check that files are tranformed when -p and -include are specified.
+// RUN: echo %T/SourcesTest/a1 %T/SourcesTest/a2 %T/SourcesTest/a3 | xargs -n 1 cp %S/compilations.cpp
+// RUN: cp %S/compilations_expected.cpp %T
+// RUN: clang-modernize -use-nullptr -p=%T -include=%T/SourcesTest/a1,%T/SourcesTest/a3
+// RUN: diff -b %T/compilations_expected.cpp %T/SourcesTest/a1/compilations.cpp
+// RUN: not diff -b %T/compilations_expected.cpp %T/SourcesTest/a2/compilations.cpp
+// RUN: diff -b %T/compilations_expected.cpp %T/SourcesTest/a3/compilations.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1710.1.patch
Type: text/x-patch
Size: 5893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130918/cc2a9be6/attachment.bin>


More information about the cfe-commits mailing list