Browse Source

for issue #7: merge 4f29fc8 by @yaccz, implement auto test cases w/o shunit2

Matthew Wang 11 years ago
parent
commit
ca2fa1c41b

+ 4
- 11
Makefile View File

@@ -1,24 +1,17 @@
1 1
 # Makefile for testing
2 2
 
3
-TESTS = git svn crlf strange
4 3
 TESTPYPI = http://testpypi.python.org/pypi
5 4
 
6
-.PHONY: dogfood test $(TESTS) clean dist-test dist
5
+.PHONY: dogfood test clean dist-test dist
7 6
 
8 7
 dogfood:
9 8
 	./cdiff.py -s
10 9
 	git diff | ./cdiff.py
11 10
 	git diff | ./cdiff.py -s
12 11
 
13
-test: $(TESTS)
14
-
15
-$(TESTS):
16
-	./cdiff.py tests/$@.diff
17
-	./cdiff.py tests/$@.diff -s
18
-	./cdiff.py tests/$@.diff | diff -u tests/$@.diff -
19
-	python3 ./cdiff.py tests/$@.diff
20
-	python3 ./cdiff.py tests/$@.diff -s
21
-	python3 ./cdiff.py tests/$@.diff | diff -u tests/$@.diff -
12
+test:
13
+	PYTHON=python ./tests/tests.sh
14
+	PYTHON=python3 ./tests/tests.sh
22 15
 
23 16
 clean:
24 17
 	rm -f cdiff MANIFEST

+ 4
- 2
cdiff.py View File

@@ -571,8 +571,10 @@ def main():
571 571
     parser = optparse.OptionParser(usage=usage,
572 572
             description=META_INFO['description'],
573 573
             version='%%prog %s' % META_INFO['version'])
574
+    parser.add_option('-c', '--color', default='auto', metavar='WHEN',
575
+            help='colorize mode "auto" (default), "always", or "never"')
574 576
     parser.add_option('-s', '--side-by-side', action='store_true',
575
-            help=('show in side-by-side mode'))
577
+            help='show in side-by-side mode')
576 578
     parser.add_option('-w', '--width', type='int', default=80, metavar='N',
577 579
             help='set text width (side-by-side mode only), default is 80')
578 580
     opts, args = parser.parse_args()
@@ -609,7 +611,7 @@ def main():
609 611
     if not stream:
610 612
         return 0
611 613
 
612
-    if sys.stdout.isatty():
614
+    if opts.color == 'always' or (opts.color == 'auto' and sys.stdout.isatty()):
613 615
         try:
614 616
             markup_to_pager(stream, opts)
615 617
         except IOError:

+ 4
- 0
tests/README View File

@@ -0,0 +1,4 @@
1
+# To generate expected output, use following command, then review with `less -R`
2
+../../cdiff.py -c always in.diff > out.normal 
3
+../../cdiff.py -c always -s in.diff > out.side-by-side
4
+../../cdiff.py -c always -s in.diff -w70 > out.w70

tests/crlf.diff → tests/crlf/in.diff View File


+ 31
- 0
tests/crlf/out.normal View File

@@ -0,0 +1,31 @@
1
+Index: README.md
2
+===================================================================
3
+--- README.md	(revision 41)
4
++++ README.md	(working copy)
5
+@@ -3,7 +3,6 @@
6
+ ## About
7
+ 
8
+ Coderev is a toolkit generates static side-by-side html pages for code review.
9
+-Typical use case is to generate diff pages for local modification in svn/cvs
10
+ workspace and send page link to teammates for code review.
11
+ 
12
+ See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo.
13
+@@ -18,9 +17,10 @@
14
+ 
15
+ ## Usage of coderev.sh
16
+ 
17
+-Just type `./coderev.sh -h` to see the usage.
18
++Just type `./coderev.sh --help` to see the usage.
19
+ 
20
+     Usage:
21
++
22
+         coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \
23
+                 [-F comment-file | -m 'comment...'] [file...]
24
+ 
25
+@@ -145,3 +145,5 @@
26
+                             specify column number where lines are broken and
27
+                             wrapped for sdiff, default is no line wrapping
28
+     -y, --yes             do not prompt for overwriting
29
++
30
++# EOF
31
+

+ 29
- 0
tests/crlf/out.side-by-side View File

@@ -0,0 +1,29 @@
1
+Index: README.md
2
+===================================================================
3
+--- README.md	(revision 41)
4
++++ README.md	(working copy)
5
+@@ -3,7 +3,6 @@
6
+  3 ## About                                                                           3 ## About
7
+  4                                                                                    4 
8
+  5 Coderev is a toolkit generates static side-by-side html pages for code review.     5 Coderev is a toolkit generates static side-by-side html pages for code review.
9
+  6 Typical use case is to generate diff pages for local modification in svn/cvs     
10
+  7 workspace and send page link to teammates for code review.                         6 workspace and send page link to teammates for code review.
11
+  8                                                                                    7 
12
+  9 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo.    8 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo.
13
+@@ -18,9 +17,10 @@
14
+ 18                                                                                   17 
15
+ 19 ## Usage of coderev.sh                                                            18 ## Usage of coderev.sh
16
+ 20                                                                                   19 
17
+ 21 Just type `./coderev.sh -h` to see the usage.                                     20 Just type `./coderev.sh --help` to see the usage.
18
+ 22                                                                                   21 
19
+ 23     Usage:                                                                        22     Usage:
20
+                                                                                      23 
21
+ 24         coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \          24         coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \
22
+ 25                 [-F comment-file | -m 'comment...'] [file...]                     25                 [-F comment-file | -m 'comment...'] [file...]
23
+ 26                                                                                   26 
24
+@@ -145,3 +145,5 @@
25
+145                             specify column number where lines are broken and     145                             specify column number where lines are broken and
26
+146                             wrapped for sdiff, default is no line wrapping       146                             wrapped for sdiff, default is no line wrapping
27
+147     -y, --yes             do not prompt for overwriting                          147     -y, --yes             do not prompt for overwriting
28
+                                                                                     148 
29
+                                                                                     149 # EOF

+ 29
- 0
tests/crlf/out.w70 View File

@@ -0,0 +1,29 @@
1
+Index: README.md
2
+===================================================================
3
+--- README.md	(revision 41)
4
++++ README.md	(working copy)
5
+@@ -3,7 +3,6 @@
6
+  3 ## About                                                                 3 ## About
7
+  4                                                                          4 
8
+  5 Coderev is a toolkit generates static side-by-side html pages for cod>   5 Coderev is a toolkit generates static side-by-side html pages for cod>
9
+  6 Typical use case is to generate diff pages for local modification in >     
10
+  7 workspace and send page link to teammates for code review.               6 workspace and send page link to teammates for code review.
11
+  8                                                                          7 
12
+  9 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) f>   8 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) f>
13
+@@ -18,9 +17,10 @@
14
+ 18                                                                         17 
15
+ 19 ## Usage of coderev.sh                                                  18 ## Usage of coderev.sh
16
+ 20                                                                         19 
17
+ 21 Just type `./coderev.sh -h` to see the usage.                           20 Just type `./coderev.sh --help` to see the usage.
18
+ 22                                                                         21 
19
+ 23     Usage:                                                              22     Usage:
20
+                                                                            23 
21
+ 24         coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name>  24         coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name>
22
+ 25                 [-F comment-file | -m 'comment...'] [file...]           25                 [-F comment-file | -m 'comment...'] [file...]
23
+ 26                                                                         26 
24
+@@ -145,3 +145,5 @@
25
+145                             specify column number where lines are bro> 145                             specify column number where lines are bro>
26
+146                             wrapped for sdiff, default is no line wra> 146                             wrapped for sdiff, default is no line wra>
27
+147     -y, --yes             do not prompt for overwriting                147     -y, --yes             do not prompt for overwriting
28
+                                                                           148 
29
+                                                                           149 # EOF

tests/git.diff → tests/git/in.diff View File


+ 48
- 0
tests/git/out.normal View File

@@ -0,0 +1,48 @@
1
+commit 15bfa564b9db08fb277a343a3d0a01d377800606
2
+Author: Matthew Wang <XXXXXXX@gmail.com>
3
+Date:   Thu Jan 31 15:27:17 2013 +0800
4
+
5
+    Default width is now 80
6
+
7
+diff --git a/src/cdiff.py b/src/cdiff.py
8
+index 13f725f..bf15ef1 100755
9
+--- a/src/cdiff.py
10
++++ b/src/cdiff.py
11
+@@ -128,9 +128,7 @@ class Diff(object):
12
+                     yield self._markup_common(' ' + old[1])
13
+ 
14
+     def markup_side_by_side(self, width):
15
+-        """width of 0 means infinite width, None means auto detect. Returns a
16
++        """Returns a generator"""
17
+-        generator
18
+-        """
19
+         def _normalize(line):
20
+             return line.replace('\t', ' ' * 8).replace('\n', '')
21
+ 
22
+@@ -147,7 +145,8 @@ class Diff(object):
23
+                 return markup
24
+ 
25
+         # Setup line width and number width
26
+-        if not width: width = 80
27
++        if width <= 0:
28
++            width = 80
29
+         (start, offset) = self._hunks[-1].get_old_addr()
30
+         max1 = start + offset - 1
31
+         (start, offset) = self._hunks[-1].get_new_addr()
32
+@@ -430,13 +429,10 @@ if __name__ == '__main__':
33
+     parser = optparse.OptionParser(usage)
34
+     parser.add_option('-s', '--side-by-side', action='store_true',
35
+             help=('show in side-by-side mode'))
36
+-    parser.add_option('-w', '--width', type='int', default=None,
37
++    parser.add_option('-w', '--width', type='int', default=80,
38
+-            help='set line width (side-by-side mode only)')
39
++            help='set line width (side-by-side mode only), default is 80')
40
+     opts, args = parser.parse_args()
41
+-
42
+-    if opts.width and opts.width < 0:
43
+-        opts.width = 0
44
+ 
45
+     if len(args) >= 1:
46
+         diff_hdl = open(args[0], 'r')
47
+     elif sys.stdin.isatty():
48
+

+ 43
- 0
tests/git/out.side-by-side View File

@@ -0,0 +1,43 @@
1
+commit 15bfa564b9db08fb277a343a3d0a01d377800606
2
+Author: Matthew Wang <XXXXXXX@gmail.com>
3
+Date:   Thu Jan 31 15:27:17 2013 +0800
4
+
5
+    Default width is now 80
6
+
7
+diff --git a/src/cdiff.py b/src/cdiff.py
8
+index 13f725f..bf15ef1 100755
9
+--- a/src/cdiff.py
10
++++ b/src/cdiff.py
11
+@@ -128,9 +128,7 @@ class Diff(object):
12
+128                     yield self._markup_common(' ' + old[1])                      128                     yield self._markup_common(' ' + old[1])
13
+129                                                                                  129 
14
+130     def markup_side_by_side(self, width):                                        130     def markup_side_by_side(self, width):
15
+131         """width of 0 means infinite width, None means auto detect. Returns a    131         """Returns a generator"""
16
+132         generator     
17
+133         """     
18
+134         def _normalize(line):                                                    132         def _normalize(line):
19
+135             return line.replace('\t', ' ' * 8).replace('\n', '')                 133             return line.replace('\t', ' ' * 8).replace('\n', '')
20
+136                                                                                  134 
21
+@@ -147,7 +145,8 @@ class Diff(object):
22
+147                 return markup                                                    145                 return markup
23
+148                                                                                  146 
24
+149         # Setup line width and number width                                      147         # Setup line width and number width
25
+150         if not width: width = 80                                                 148         if width <= 0:
26
+                                                                                     149             width = 80
27
+151         (start, offset) = self._hunks[-1].get_old_addr()                         150         (start, offset) = self._hunks[-1].get_old_addr()
28
+152         max1 = start + offset - 1                                                151         max1 = start + offset - 1
29
+153         (start, offset) = self._hunks[-1].get_new_addr()                         152         (start, offset) = self._hunks[-1].get_new_addr()
30
+@@ -430,13 +429,10 @@ if __name__ == '__main__':
31
+430     parser = optparse.OptionParser(usage)                                        429     parser = optparse.OptionParser(usage)
32
+431     parser.add_option('-s', '--side-by-side', action='store_true',               430     parser.add_option('-s', '--side-by-side', action='store_true',
33
+432             help=('show in side-by-side mode'))                                  431             help=('show in side-by-side mode'))
34
+433     parser.add_option('-w', '--width', type='int', default=None,                 432     parser.add_option('-w', '--width', type='int', default=80,
35
+434             help='set line width (side-by-side mode only)')                      433             help='set line width (side-by-side mode only), default is 80')
36
+435     opts, args = parser.parse_args()                                             434     opts, args = parser.parse_args()
37
+436      
38
+437     if opts.width and opts.width < 0:     
39
+438         opts.width = 0     
40
+439                                                                                  435 
41
+440     if len(args) >= 1:                                                           436     if len(args) >= 1:
42
+441         diff_hdl = open(args[0], 'r')                                            437         diff_hdl = open(args[0], 'r')
43
+442     elif sys.stdin.isatty():                                                     438     elif sys.stdin.isatty():

+ 43
- 0
tests/git/out.w70 View File

@@ -0,0 +1,43 @@
1
+commit 15bfa564b9db08fb277a343a3d0a01d377800606
2
+Author: Matthew Wang <XXXXXXX@gmail.com>
3
+Date:   Thu Jan 31 15:27:17 2013 +0800
4
+
5
+    Default width is now 80
6
+
7
+diff --git a/src/cdiff.py b/src/cdiff.py
8
+index 13f725f..bf15ef1 100755
9
+--- a/src/cdiff.py
10
++++ b/src/cdiff.py
11
+@@ -128,9 +128,7 @@ class Diff(object):
12
+128                     yield self._markup_common(' ' + old[1])            128                     yield self._markup_common(' ' + old[1])
13
+129                                                                        129 
14
+130     def markup_side_by_side(self, width):                              130     def markup_side_by_side(self, width):
15
+131         """width of 0 means infinite width, None means auto detect. R> 131         """Returns a generator"""
16
+132         generator     
17
+133         """     
18
+134         def _normalize(line):                                          132         def _normalize(line):
19
+135             return line.replace('\t', ' ' * 8).replace('\n', '')       133             return line.replace('\t', ' ' * 8).replace('\n', '')
20
+136                                                                        134 
21
+@@ -147,7 +145,8 @@ class Diff(object):
22
+147                 return markup                                          145                 return markup
23
+148                                                                        146 
24
+149         # Setup line width and number width                            147         # Setup line width and number width
25
+150         if not width: width = 80                                       148         if width <= 0:
26
+                                                                           149             width = 80
27
+151         (start, offset) = self._hunks[-1].get_old_addr()               150         (start, offset) = self._hunks[-1].get_old_addr()
28
+152         max1 = start + offset - 1                                      151         max1 = start + offset - 1
29
+153         (start, offset) = self._hunks[-1].get_new_addr()               152         (start, offset) = self._hunks[-1].get_new_addr()
30
+@@ -430,13 +429,10 @@ if __name__ == '__main__':
31
+430     parser = optparse.OptionParser(usage)                              429     parser = optparse.OptionParser(usage)
32
+431     parser.add_option('-s', '--side-by-side', action='store_true',     430     parser.add_option('-s', '--side-by-side', action='store_true',
33
+432             help=('show in side-by-side mode'))                        431             help=('show in side-by-side mode'))
34
+433     parser.add_option('-w', '--width', type='int', default=None,       432     parser.add_option('-w', '--width', type='int', default=80,
35
+434             help='set line width (side-by-side mode only)')            433             help='set line width (side-by-side mode only), default is>
36
+435     opts, args = parser.parse_args()                                   434     opts, args = parser.parse_args()
37
+436      
38
+437     if opts.width and opts.width < 0:     
39
+438         opts.width = 0     
40
+439                                                                        435 
41
+440     if len(args) >= 1:                                                 436     if len(args) >= 1:
42
+441         diff_hdl = open(args[0], 'r')                                  437         diff_hdl = open(args[0], 'r')
43
+442     elif sys.stdin.isatty():                                           438     elif sys.stdin.isatty():

tests/strange.diff → tests/strange/in.diff View File


+ 21
- 0
tests/strange/out.normal View File

@@ -0,0 +1,21 @@
1
+commit 57263369bd810ba3a2c2dfd32a905f1e7d59cc6d
2
+Author: Matthew Wang <XXXXXXX@gmail.com>
3
+Date:   Sun Jan 6 21:56:54 2013 +0800
4
+
5
+    simplify with seperate node.py
6
+
7
+diff --git a/.gitignore b/.gitignore
8
+new file mode 100644
9
+index 0000000..0d20b64
10
+--- /dev/null
11
++++ b/.gitignore
12
+@@ -0,0 +1 @@
13
++*.pyc
14
+diff --git a/README b/README
15
+index 7e70850..b5eb369 100644
16
+--- a/README
17
++++ b/README
18
+@@ -1 +1,2 @@
19
+ Sun Feb  3 13:57:05 CST 2013
20
++Sun Feb  3 13:57:15 CST 2013
21
+

+ 20
- 0
tests/strange/out.side-by-side View File

@@ -0,0 +1,20 @@
1
+commit 57263369bd810ba3a2c2dfd32a905f1e7d59cc6d
2
+Author: Matthew Wang <XXXXXXX@gmail.com>
3
+Date:   Sun Jan 6 21:56:54 2013 +0800
4
+
5
+    simplify with seperate node.py
6
+
7
+diff --git a/.gitignore b/.gitignore
8
+new file mode 100644
9
+index 0000000..0d20b64
10
+--- /dev/null
11
++++ b/.gitignore
12
+@@ -0,0 +1 @@
13
+                                                                                     1 *.pyc
14
+diff --git a/README b/README
15
+index 7e70850..b5eb369 100644
16
+--- a/README
17
++++ b/README
18
+@@ -1 +1,2 @@
19
+1 Sun Feb  3 13:57:05 CST 2013                                                     1 Sun Feb  3 13:57:05 CST 2013
20
+                                                                                   2 Sun Feb  3 13:57:15 CST 2013

+ 20
- 0
tests/strange/out.w70 View File

@@ -0,0 +1,20 @@
1
+commit 57263369bd810ba3a2c2dfd32a905f1e7d59cc6d
2
+Author: Matthew Wang <XXXXXXX@gmail.com>
3
+Date:   Sun Jan 6 21:56:54 2013 +0800
4
+
5
+    simplify with seperate node.py
6
+
7
+diff --git a/.gitignore b/.gitignore
8
+new file mode 100644
9
+index 0000000..0d20b64
10
+--- /dev/null
11
++++ b/.gitignore
12
+@@ -0,0 +1 @@
13
+                                                                           1 *.pyc
14
+diff --git a/README b/README
15
+index 7e70850..b5eb369 100644
16
+--- a/README
17
++++ b/README
18
+@@ -1 +1,2 @@
19
+1 Sun Feb  3 13:57:05 CST 2013                                           1 Sun Feb  3 13:57:05 CST 2013
20
+                                                                         2 Sun Feb  3 13:57:15 CST 2013

tests/svn.diff → tests/svn/in.diff View File


+ 31
- 0
tests/svn/out.normal View File

@@ -0,0 +1,31 @@
1
+Index: README.md
2
+===================================================================
3
+--- README.md	(revision 41)
4
++++ README.md	(working copy)
5
+@@ -3,7 +3,6 @@
6
+ ## About
7
+ 
8
+ Coderev is a toolkit generates static side-by-side html pages for code review.
9
+-Typical use case is to generate diff pages for local modification in svn/cvs
10
+ workspace and send page link to teammates for code review.
11
+ 
12
+ See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo.
13
+@@ -18,9 +17,10 @@
14
+ 
15
+ ## Usage of coderev.sh
16
+ 
17
+-Just type `./coderev.sh -h` to see the usage.
18
++Just type `./coderev.sh --help` to see the usage.
19
+ 
20
+     Usage:
21
++
22
+         coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \
23
+                 [-F comment-file | -m 'comment...'] [file...]
24
+ 
25
+@@ -145,3 +145,5 @@
26
+                             specify column number where lines are broken and
27
+                             wrapped for sdiff, default is no line wrapping
28
+     -y, --yes             do not prompt for overwriting
29
++
30
++# EOF
31
+

+ 29
- 0
tests/svn/out.side-by-side View File

@@ -0,0 +1,29 @@
1
+Index: README.md
2
+===================================================================
3
+--- README.md	(revision 41)
4
++++ README.md	(working copy)
5
+@@ -3,7 +3,6 @@
6
+  3 ## About                                                                           3 ## About
7
+  4                                                                                    4 
8
+  5 Coderev is a toolkit generates static side-by-side html pages for code review.     5 Coderev is a toolkit generates static side-by-side html pages for code review.
9
+  6 Typical use case is to generate diff pages for local modification in svn/cvs     
10
+  7 workspace and send page link to teammates for code review.                         6 workspace and send page link to teammates for code review.
11
+  8                                                                                    7 
12
+  9 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo.    8 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo.
13
+@@ -18,9 +17,10 @@
14
+ 18                                                                                   17 
15
+ 19 ## Usage of coderev.sh                                                            18 ## Usage of coderev.sh
16
+ 20                                                                                   19 
17
+ 21 Just type `./coderev.sh -h` to see the usage.                                     20 Just type `./coderev.sh --help` to see the usage.
18
+ 22                                                                                   21 
19
+ 23     Usage:                                                                        22     Usage:
20
+                                                                                      23 
21
+ 24         coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \          24         coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \
22
+ 25                 [-F comment-file | -m 'comment...'] [file...]                     25                 [-F comment-file | -m 'comment...'] [file...]
23
+ 26                                                                                   26 
24
+@@ -145,3 +145,5 @@
25
+145                             specify column number where lines are broken and     145                             specify column number where lines are broken and
26
+146                             wrapped for sdiff, default is no line wrapping       146                             wrapped for sdiff, default is no line wrapping
27
+147     -y, --yes             do not prompt for overwriting                          147     -y, --yes             do not prompt for overwriting
28
+                                                                                     148 
29
+                                                                                     149 # EOF

+ 29
- 0
tests/svn/out.w70 View File

@@ -0,0 +1,29 @@
1
+Index: README.md
2
+===================================================================
3
+--- README.md	(revision 41)
4
++++ README.md	(working copy)
5
+@@ -3,7 +3,6 @@
6
+  3 ## About                                                                 3 ## About
7
+  4                                                                          4 
8
+  5 Coderev is a toolkit generates static side-by-side html pages for cod>   5 Coderev is a toolkit generates static side-by-side html pages for cod>
9
+  6 Typical use case is to generate diff pages for local modification in >     
10
+  7 workspace and send page link to teammates for code review.               6 workspace and send page link to teammates for code review.
11
+  8                                                                          7 
12
+  9 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) f>   8 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) f>
13
+@@ -18,9 +17,10 @@
14
+ 18                                                                         17 
15
+ 19 ## Usage of coderev.sh                                                  18 ## Usage of coderev.sh
16
+ 20                                                                         19 
17
+ 21 Just type `./coderev.sh -h` to see the usage.                           20 Just type `./coderev.sh --help` to see the usage.
18
+ 22                                                                         21 
19
+ 23     Usage:                                                              22     Usage:
20
+                                                                            23 
21
+ 24         coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name>  24         coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name>
22
+ 25                 [-F comment-file | -m 'comment...'] [file...]           25                 [-F comment-file | -m 'comment...'] [file...]
23
+ 26                                                                         26 
24
+@@ -145,3 +145,5 @@
25
+145                             specify column number where lines are bro> 145                             specify column number where lines are bro>
26
+146                             wrapped for sdiff, default is no line wra> 146                             wrapped for sdiff, default is no line wra>
27
+147     -y, --yes             do not prompt for overwriting                147     -y, --yes             do not prompt for overwriting
28
+                                                                           148 
29
+                                                                           149 # EOF

+ 64
- 0
tests/tests.sh View File

@@ -0,0 +1,64 @@
1
+#!/bin/bash
2
+
3
+set -o errexit
4
+
5
+SELF_DIR=$(cd $(dirname $0) && pwd) || exit 1
6
+CDIFF=$SELF_DIR/../cdiff.py
7
+
8
+# Override this to test with python3
9
+PYTHON=${PYTHON:-python}
10
+
11
+function pass()
12
+{
13
+    if [[ -t 1 ]]; then
14
+        echo -e "\x1b[01;32mPASS\x1b[0m" "$*"
15
+    else
16
+        echo "PASS" "$*"
17
+    fi
18
+}
19
+
20
+function fail()
21
+{
22
+    if [[ -t 1 ]]; then
23
+        echo -e "\x1b[01;31mFAIL\x1b[0m" "$*"
24
+    else
25
+        echo "FAIL" "$*"
26
+    fi
27
+}
28
+
29
+function cmpOutput()
30
+{
31
+    local input=${1:?}
32
+    local expected_out=${2:?}
33
+    local cdiff_opt=${3:-""}
34
+
35
+    echo -n "Test option '$cdiff_opt' with input '$input' ... "
36
+    if $PYTHON $CDIFF $cdiff_opt $input | diff -ub $expected_out - >& /dev/null
37
+    then
38
+        pass
39
+        return 0
40
+    else
41
+        fail "(expected output: '$expected_out')"
42
+        return 1
43
+    fi
44
+}
45
+
46
+function main()
47
+{
48
+    local rc=0
49
+    local d
50
+
51
+    for d in $SELF_DIR/*/; do
52
+        cmpOutput "${d}in.diff" ${d}out.normal "-c always" || rc=1
53
+        cmpOutput "${d}in.diff" ${d}out.side-by-side "-c always -s" || rc=1
54
+        cmpOutput "${d}in.diff" ${d}out.w70 "-c always -s -w70" || rc=1
55
+        cmpOutput "${d}in.diff" "${d}in.diff" "-c auto" || rc=1
56
+        cmpOutput "${d}in.diff" "${d}in.diff" "-c auto -s" || rc=1
57
+        cmpOutput "${d}in.diff" "${d}in.diff" "-c auto -s -w70" || rc=1
58
+    done
59
+    return $rc
60
+}
61
+
62
+main "$@"
63
+
64
+# vim:set et sts=4 sw=4: