[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Quilt-dev] [PATCH v2] Add a test case for remove-trailing-ws script
From: |
Jean Delvare |
Subject: |
[Quilt-dev] [PATCH v2] Add a test case for remove-trailing-ws script |
Date: |
Mon, 17 Dec 2012 17:58:10 +0100 |
As a bug was recently found in this script, add a test case covering
both unified and context patch formats, so that hopefully no other
bug creeps in in the future.
---
v2: Test without -n, so we can additionally check that white space
removal, not just detection, works.
test/remove-trailing-ws.test | 188 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 188 insertions(+)
--- /dev/null
+++ b/test/remove-trailing-ws.test
@@ -0,0 +1,188 @@
+# Unit test for the remove-trailing-ws script.
+
+# Prepare the working directory
+$ mkdir files.orig files
+
+$ cat > files.orig/add
+< Line 1
+< Line 2
+< Line 3
+<
+< Line 5
+< Line 6
+$ cat > files.orig/change
+< change
+< from
+< this
+$ cat > files.orig/complex
+< Line 1
+< Line 2
+<
+< Line 3
+< Line 4
+<
+< Line 5
+< Line 6
+<
+< Line 7
+< Line 8
+<
+< Line 9
+< Line 10
+$ cat > files.orig/delete
+< delete
+< an old
+< file
+$ cat > files.orig/remove
+< Line 1
+< Line 2
+<
+< Line 3
+< Line 4
+<
+< Line 5
+< Line 6
+$ cat > files.orig/remove-at-end
+< Line 1
+< Line 2
+<
+< Line 3
+< Line 4
+<
+< Line 5
+< Line 6
+<
+< Line 7
+< Line 8
+<
+< Line 9
+< Line 10
+
+$ cat > files/add
+< Line 1
+< Line 2
+<
+< Line 3
+< Line 4
+<
+< Line 5
+< Line 6
+$ cat > files/change
+< change
+< to
+< that
+$ cat > files/complex
+< Line 1
+< Line 2
+< Line 3
+< Line 4
+<
+< Line 5
+< Line 6
+<
+< Line 7
+< Line 8
+<
+< Line 9
+< Line A
+<
+< Line B
+< Line C
+<
+< Line D
+< Line E
+< Line F
+< Line 10
+$ cat > files/create
+< create
+< a new
+< file
+$ cat > files/remove
+< Line 1
+< Line 2
+< Line 3
+<
+< Line 5
+< Line 6
+$ cat > files/remove-at-end
+< Line 1
+< Line 2
+<
+< Line 3
+< Line 4
+<
+< Line 5
+< Line 6
+
+$ cp -r files files.backup
+
+# Generate the two patches
+$ diff -ruN files.orig files > unified.diff
+# For the context diff we need the files listed in a certain order to
+# cover some corner cases
+$ diff -c files.orig/add files/add > context.diff
+$ diff -C 10 files.orig/remove-at-end files/remove-at-end >> context.diff
+$ diff -cN files.orig/create files/create | sed -e '/^diff /d' >> context.diff
+$ diff -cN files.orig/delete files/delete >> context.diff
+$ diff -c files.orig/remove files/remove | sed -e '/^diff /d' >> context.diff
+$ diff -c files.orig/change files/change | sed -e '/^diff /d' >> context.diff
+$ diff -c files.orig/complex files/complex >> context.diff
+
+$ %{QUILT_DIR}/scripts/remove-trailing-ws < unified.diff > unified-wsok.diff
+> Removing trailing whitespace from line 5 of files/add
+> Removing trailing whitespace from lines 2,3 of files/change
+> Removing trailing whitespace from lines 1,2,3 of files/create
+$ wc -l files/add
+> 8 files/add
+$ wc -l files/change
+> 3 files/change
+$ wc -l files/complex
+> 21 files/complex
+$ wc -l files/create
+> 3 files/create
+$ wc -l files/remove
+> 6 files/remove
+$ wc -l files/remove-at-end
+> 8 files/remove-at-end
+$ wc -l unified.diff
+> 83 unified.diff
+$ wc -l unified-wsok.diff
+> 83 unified-wsok.diff
+$ diff -u unified.diff unified-wsok.diff | grep '^++[^+]'
+> ++Line 4
+> ++to
+> ++that
+> ++create
+> ++a new
+> ++file
+
+$ rm -rf files
+$ mv files.backup files
+$ %{QUILT_DIR}/scripts/remove-trailing-ws < context.diff > context-wsok.diff
+> Removing trailing whitespace from line 5 of files/add
+> Removing trailing whitespace from lines 2,3 of files/change
+> Removing trailing whitespace from lines 1,2,3 of files/create
+$ wc -l files/add
+> 8 files/add
+$ wc -l files/change
+> 3 files/change
+$ wc -l files/complex
+> 21 files/complex
+$ wc -l files/create
+> 3 files/create
+$ wc -l files/remove
+> 6 files/remove
+$ wc -l files/remove-at-end
+> 8 files/remove-at-end
+$ wc -l context.diff
+> 98 context.diff
+$ wc -l context-wsok.diff
+> 98 context-wsok.diff
+$ diff -u context.diff context-wsok.diff | grep '^+[+!] '
+> ++ Line 4
+> ++ create
+> ++ a new
+> ++ file
+> +! to
+> +! that
+
--
Jean Delvare
Suse L3