Handle newlines on Windows correctly.
authorNikola Smiljanic <popizdeh@gmail.com>
Tue, 9 Dec 2014 02:57:56 +0000 (02:57 +0000)
committerNikola Smiljanic <popizdeh@gmail.com>
Tue, 9 Dec 2014 02:57:56 +0000 (02:57 +0000)
llvm-svn: 223750

clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp.expected [new file with mode: 0644]
clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/file1.yaml [new file with mode: 0644]
clang-tools-extra/test/clang-apply-replacements/crlf.cpp [new file with mode: 0644]

index fcd1a55..607b665 100644 (file)
@@ -270,7 +270,7 @@ int main(int argc, char **argv) {
 
     // Write new file to disk
     std::error_code EC;
-    llvm::raw_fd_ostream FileStream(FileName, EC, llvm::sys::fs::F_Text);
+    llvm::raw_fd_ostream FileStream(FileName, EC, llvm::sys::fs::F_None);
     if (EC) {
       llvm::errs() << "Could not open " << FileName << " for writing\n";
       continue;
diff --git a/clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp b/clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp
new file mode 100644 (file)
index 0000000..26f7996
--- /dev/null
@@ -0,0 +1,6 @@
+\r
+// This file intentionally uses a CRLF newlines!\r
+\r
+void foo() {\r
+  int *x = 0;\r
+}\r
diff --git a/clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp.expected b/clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/crlf.cpp.expected
new file mode 100644 (file)
index 0000000..ad8e907
--- /dev/null
@@ -0,0 +1,6 @@
+\r
+// This file intentionally uses a CRLF newlines!\r
+\r
+void foo() {\r
+  int *x = nullptr;\r
+}\r
diff --git a/clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/file1.yaml b/clang-tools-extra/test/clang-apply-replacements/Inputs/crlf/file1.yaml
new file mode 100644 (file)
index 0000000..0ee548a
--- /dev/null
@@ -0,0 +1,8 @@
+---
+MainSourceFile:      source1.cpp
+Replacements:    
+  - FilePath:        $(path)/crlf.cpp
+    Offset:          79
+    Length:          1
+    ReplacementText: nullptr
+...
diff --git a/clang-tools-extra/test/clang-apply-replacements/crlf.cpp b/clang-tools-extra/test/clang-apply-replacements/crlf.cpp
new file mode 100644 (file)
index 0000000..8a8fd46
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: mkdir -p %T/Inputs/crlf
+// RUN: cp %S/Inputs/crlf/crlf.cpp %T/Inputs/crlf/crlf.cpp
+// RUN: sed "s#\$(path)#%/T/Inputs/crlf#" %S/Inputs/crlf/file1.yaml > %T/Inputs/crlf/file1.yaml
+// RUN: clang-apply-replacements %T/Inputs/crlf
+// RUN: diff %T/Inputs/crlf/crlf.cpp %S/Inputs/crlf/crlf.cpp.expected