[PATCH 2 of 4] solaris: test cases shouldn't use diff -u when no output is expected

Augie Fackler raf at durin42.com
Mon Aug 26 14:55:23 CDT 2013


On Mon, Aug 26, 2013 at 10:28:35AM -0700, Danek Duvall wrote:
> # HG changeset patch
> # User Danek Duvall <danek.duvall at oracle.com>
> # Date 1377295468 25200
> # Node ID bd488d5b5763ef8c4bc7b4a69e4073861e2487a1
> # Parent  549b0ea402e74559210c95aaf217749965887f22
> solaris: test cases shouldn't use diff -u when no output is expected
>
> When using Solaris diff, the -u option emits "No differences encountered"
> when the two files are the same, leading to extraneous test failures.  In
> such cases, we can easily remove the -u option, since that has no output
> with either Solaris or GNU diff, and we can remove the various mechanisms
> that have been used to handle the difference.
>
> In order to write a test for check-code.py, though, all uses of diff -u
> need to be eliminated.  The one case where a simple output is expected, we
> can just cat the two (one-line) files and confirm the output.  In the other
> cases, we switch to regular diffs, but we need to teach run-tests.py how to
> handle command output which has lines starting with "> ".

Can I convince you that this is two patches? One to educate run-tests about output starting with > and one to fix uses of `diff -u`?

>
> diff --git a/contrib/check-code.py b/contrib/check-code.py
> --- a/contrib/check-code.py
> +++ b/contrib/check-code.py
> @@ -62,6 +62,7 @@ testpats = [
>      (r'\W\$?\(\([^\)\n]*\)\)', "don't use (()) or $(()), use 'expr'"),
>      (r'grep.*-q', "don't use 'grep -q', redirect to /dev/null"),
>      (r'(?<!hg )grep.*-a', "don't use 'grep -a', use in-line python"),
> +    (r'diff\s+-\w*u', "don't use 'diff -u'"),
>      (r'sed.*-i', "don't use 'sed -i', use a temporary file"),
>      (r'\becho\b.*\\n', "don't use 'echo \\n', use printf"),
>      (r'echo -n', "don't use 'echo -n', use printf"),
> diff --git a/tests/run-tests.py b/tests/run-tests.py
> --- a/tests/run-tests.py
> +++ b/tests/run-tests.py
> @@ -738,6 +738,8 @@ def tsttest(test, wd, options, replaceme
>              if len(cmd) == 2 and cmd[0] == 'cd':
>                  l = '  $ cd %s || exit 1\n' % cmd[1]
>              script.append(l[4:])
> +        elif l.startswith('  \\> '): # output line starts with ">"
> +            expected.setdefault(pos, []).append(l[3:])
>          elif l.startswith('  > '): # continuations
>              after.setdefault(prepos, []).append(l)
>              script.append(l[4:])
> @@ -787,6 +789,8 @@ def tsttest(test, wd, options, replaceme
>          if lout:
>              if not lout.endswith('\n'):
>                  lout += ' (no-eol)\n'
> +            if lout.startswith('> '):
> +                lout = '\\' + lout
>
>              # find the expected output at the current position
>              el = None
> diff --git a/tests/test-command-template.t b/tests/test-command-template.t
> --- a/tests/test-command-template.t
> +++ b/tests/test-command-template.t
> @@ -67,15 +67,15 @@ Default style is like normal output:
>
>    $ hg log > log.out
>    $ hg log --style default > style.out
> -  $ cmp log.out style.out || diff -u log.out style.out
> +  $ diff log.out style.out
>
>    $ hg log -v > log.out
>    $ hg log -v --style default > style.out
> -  $ cmp log.out style.out || diff -u log.out style.out
> +  $ diff log.out style.out
>
>    $ hg log --debug > log.out
>    $ hg log --debug --style default > style.out
> -  $ cmp log.out style.out || diff -u log.out style.out
> +  $ diff log.out style.out
>
>  Revision with no copies (used to print a traceback):
>
> diff --git a/tests/test-convert-bzr.t b/tests/test-convert-bzr.t
> --- a/tests/test-convert-bzr.t
> +++ b/tests/test-convert-bzr.t
> @@ -102,7 +102,7 @@ compare timestamps
>    >   > ../bzr-timestamps
>    $ cd ..
>    $ hg -R source-hg log --template "{date|isodate}\n" > hg-timestamps
> -  $ diff -u bzr-timestamps hg-timestamps
> +  $ diff bzr-timestamps hg-timestamps
>    $ cd ..
>
>  merge
> diff --git a/tests/test-glog.t b/tests/test-glog.t
> --- a/tests/test-glog.t
> +++ b/tests/test-glog.t
> @@ -1430,7 +1430,7 @@ Test log -G options
>    >     | sed 's/.*nodetag/nodetag/' > log.nodes
>    >   hg log -G --template 'nodetag {rev}\n' "$@" | grep nodetag \
>    >     | sed 's/.*nodetag/nodetag/' > glog.nodes
> -  >   diff -u log.nodes glog.nodes | grep '^[-+@ ]' || :
> +  >   diff log.nodes glog.nodes
>    > }
>
>  glog always reorders nodes which explains the difference with log
> @@ -1438,18 +1438,15 @@ glog always reorders nodes which explain
>    $ testlog -r 27 -r 25 -r 21 -r 34 -r 32 -r 31
>    ['27', '25', '21', '34', '32', '31']
>    []
> -  --- log.nodes	* (glob)
> -  +++ glog.nodes	* (glob)
> -  @@ -1,6 +1,6 @@
> -  -nodetag 27
> -  -nodetag 25
> -  -nodetag 21
> -   nodetag 34
> -   nodetag 32
> -   nodetag 31
> -  +nodetag 27
> -  +nodetag 25
> -  +nodetag 21
> +  1,3d0
> +  < nodetag 27
> +  < nodetag 25
> +  < nodetag 21
> +  6a4,6
> +  \> nodetag 27
> +  \> nodetag 25
> +  \> nodetag 21
> +  [1]
>    $ testlog -u test -u not-a-user
>    []
>    (group
> @@ -1969,13 +1966,11 @@ Test --follow and forward --rev
>      (func
>        ('symbol', 'descendants')
>        ('symbol', '6')))
> -  --- log.nodes	* (glob)
> -  +++ glog.nodes	* (glob)
> -  @@ -1,3 +1,3 @@
> -  -nodetag 6
> -   nodetag 8
> -   nodetag 7
> -  +nodetag 6
> +  1d0
> +  < nodetag 6
> +  3a3
> +  \> nodetag 6
> +  [1]
>
>  Test --follow-first and forward --rev
>
> @@ -1985,13 +1980,11 @@ Test --follow-first and forward --rev
>      (func
>        ('symbol', '_firstdescendants')
>        ('symbol', '6')))
> -  --- log.nodes	* (glob)
> -  +++ glog.nodes	* (glob)
> -  @@ -1,3 +1,3 @@
> -  -nodetag 6
> -   nodetag 8
> -   nodetag 7
> -  +nodetag 6
> +  1d0
> +  < nodetag 6
> +  3a3
> +  \> nodetag 6
> +  [1]
>
>  Test --follow and backward --rev
>
> diff --git a/tests/test-highlight.t b/tests/test-highlight.t
> --- a/tests/test-highlight.t
> +++ b/tests/test-highlight.t
> @@ -522,7 +522,7 @@ hgweb fileannotate, raw
>    $ echo "" >> b
>    $ echo "" >> b
>    $ echo "" >> b
> -  $ diff -u b a
> +  $ diff b a
>
>  hgweb filerevision, raw
>
> @@ -531,7 +531,7 @@ hgweb filerevision, raw
>    $ echo "200 Script output follows" > b
>    $ echo "" >> b
>    $ hg cat primes.py >> b
> -  $ diff -u b a
> +  $ diff b a
>
>  hgweb highlightcss friendly
>
> diff --git a/tests/test-rename.t b/tests/test-rename.t
> --- a/tests/test-rename.t
> +++ b/tests/test-rename.t
> @@ -276,13 +276,9 @@ overwrite existing files (d2/b)
>    R d1/a
>    R d1/ba
>    R d1/d11/a1
> -  $ diff -u d1/b d2/b
> -  --- d1/b	* (glob)
> -  +++ d2/b	* (glob)
> -  @@ * (glob)
> -  -d1/b
> -  +d2/b
> -  [1]
> +  $ cat d1/b d2/b
> +  d1/b
> +  d2/b
>    $ hg update -C
>    3 files updated, 0 files merged, 0 files removed, 0 files unresolved
>    $ rm d2/a d2/ba d2/d11/a1
>
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list