changeset 36707:7834927f0243

tests: add tests about diff quality These show the differences between bdiff and xdiff. Differential Revision: https://phab.mercurial-scm.org/D2604
author Jun Wu <quark@fb.com>
date Sat, 03 Mar 2018 12:39:15 -0800
parents a247a0e82e7d
children 624cbd1477a6
files tests/hghave.py tests/test-diff-antipatience.t tests/test-diff-indent-heuristic.t
diffstat 3 files changed, 439 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests/hghave.py	Sat Mar 03 12:39:14 2018 -0800
+++ b/tests/hghave.py	Sat Mar 03 12:39:15 2018 -0800
@@ -708,3 +708,12 @@
         # libfuzzer is new in clang 6
         return int(mat.group(1)) > 5
     return False
+
+@check("xdiff", "xdiff algorithm")
+def has_xdiff():
+    try:
+        from mercurial import policy
+        bdiff = policy.importmod('bdiff')
+        return bdiff.xdiffblocks('', '') == [(0, 0, 0, 0)]
+    except (ImportError, AttributeError) as ex:
+        return False
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-diff-antipatience.t	Sat Mar 03 12:39:15 2018 -0800
@@ -0,0 +1,91 @@
+#testcases bdiff xdiff
+
+#if xdiff
+#require xdiff
+  $ cat >> $HGRCPATH <<EOF
+  > [experimental]
+  > xdiff = true
+  > EOF
+#endif
+
+Test case that makes use of the weakness of patience diff algorithm
+
+  $ hg init
+  >>> open('a', 'wb').write(b'\n'.join(list(b'a' + b'x' * 10 + b'u' + b'x' * 30 + b'a\n')))
+  $ hg commit -m 1 -A a
+  >>> open('a', 'wb').write(b'\n'.join(list(b'b' + b'x' * 30 + b'u' + b'x' * 10 + b'b\n')))
+#if xdiff
+  $ hg diff
+  diff -r f0aeecb49805 a
+  --- a/a	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/a	Thu Jan 01 00:00:00 1970 +0000
+  @@ -1,4 +1,4 @@
+  -a
+  +b
+   x
+   x
+   x
+  @@ -9,7 +9,6 @@
+   x
+   x
+   x
+  -u
+   x
+   x
+   x
+  @@ -30,6 +29,7 @@
+   x
+   x
+   x
+  +u
+   x
+   x
+   x
+  @@ -40,5 +40,5 @@
+   x
+   x
+   x
+  -a
+  +b
+   
+#else
+  $ hg diff
+  diff -r f0aeecb49805 a
+  --- a/a	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/a	Thu Jan 01 00:00:00 1970 +0000
+  @@ -1,15 +1,4 @@
+  -a
+  -x
+  -x
+  -x
+  -x
+  -x
+  -x
+  -x
+  -x
+  -x
+  -x
+  -u
+  +b
+   x
+   x
+   x
+  @@ -40,5 +29,16 @@
+   x
+   x
+   x
+  -a
+  +u
+  +x
+  +x
+  +x
+  +x
+  +x
+  +x
+  +x
+  +x
+  +x
+  +x
+  +b
+   
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-diff-indent-heuristic.t	Sat Mar 03 12:39:15 2018 -0800
@@ -0,0 +1,339 @@
+#testcases bdiff xdiff
+
+#if xdiff
+#require xdiff
+  $ cat >> $HGRCPATH <<EOF
+  > [experimental]
+  > xdiff = true
+  > EOF
+#endif
+
+  $ hg init
+
+  $ cat > a.c <<'EOF'
+  > /*
+  >  * This function returns 1.
+  >  */
+  > int f() {
+  >   return 1;
+  > }
+  > /*
+  >  * This function returns 2.
+  >  */
+  > int g() {
+  >   return 2;
+  > }
+  > /*
+  >  * This function returns 3.
+  >  */
+  > int h() {
+  >   return 3;
+  > }
+  > EOF
+
+  $ cat > b.c <<'EOF'
+  > if (x) {
+  >    do_something();
+  > }
+  > 
+  > if (y) {
+  >    do_something_else();
+  > }
+  > EOF
+
+  $ cat > c.rb <<'EOF'
+  > #!ruby
+  > ["foo", "bar", "baz"].map do |i|
+  >   i.upcase
+  > end
+  > EOF
+
+  $ cat > d.py <<'EOF'
+  > try:
+  >     import foo
+  > except ImportError:
+  >     pass
+  > try:
+  >     import bar
+  > except ImportError:
+  >     pass
+  > EOF
+
+The below two files are taken from git: t/t4061-diff-indent.sh
+
+  $ cat > spaces.txt <<'EOF'
+  > 1
+  > 2
+  > a
+  > 
+  > b
+  > 3
+  > 4
+  > EOF
+
+  $ cat > functions.c <<'EOF'
+  > 1
+  > 2
+  > /* function */
+  > foo() {
+  >     foo
+  > }
+  > 
+  > 3
+  > 4
+  > EOF
+
+  $ hg commit -m 1 -A . -q
+
+  $ cat > a.c <<'EOF'
+  > /*
+  >  * This function returns 1.
+  >  */
+  > int f() {
+  >   return 1;
+  > }
+  > /*
+  >  * This function returns 3.
+  >  */
+  > int h() {
+  >   return 3;
+  > }
+  > EOF
+
+  $ cat > b.c <<'EOF'
+  > if (x) {
+  >    do_something();
+  > }
+  > 
+  > if (y) {
+  >    do_another_thing();
+  > }
+  > 
+  > if (y) {
+  >    do_something_else();
+  > }
+  > EOF
+
+  $ cat > c.rb <<'EOF'
+  > #!ruby
+  > ["foo", "bar", "baz"].map do |i|
+  >   i
+  > end
+  > ["foo", "bar", "baz"].map do |i|
+  >   i.upcase
+  > end
+  > EOF
+
+  $ cat > d.py <<'EOF'
+  > try:
+  >     import foo
+  > except ImportError:
+  >     pass
+  > try:
+  >     import baz
+  > except ImportError:
+  >     pass
+  > try:
+  >     import bar
+  > except ImportError:
+  >     pass
+  > EOF
+
+  $ cat > spaces.txt <<'EOF'
+  > 1
+  > 2
+  > a
+  > 
+  > b
+  > a
+  > 
+  > b
+  > 3
+  > 4
+  > EOF
+
+  $ cat > functions.c <<'EOF'
+  > 1
+  > 2
+  > /* function */
+  > bar() {
+  >     foo
+  > }
+  > 
+  > /* function */
+  > foo() {
+  >     foo
+  > }
+  > 
+  > 3
+  > 4
+  > EOF
+
+#if xdiff
+  $ hg diff --git
+  diff --git a/a.c b/a.c
+  --- a/a.c
+  +++ b/a.c
+  @@ -4,12 +4,6 @@
+   int f() {
+     return 1;
+   }
+  -/*
+  - * This function returns 2.
+  - */
+  -int g() {
+  -  return 2;
+  -}
+   /*
+    * This function returns 3.
+    */
+  diff --git a/b.c b/b.c
+  --- a/b.c
+  +++ b/b.c
+  @@ -2,6 +2,10 @@
+      do_something();
+   }
+   
+  +if (y) {
+  +   do_another_thing();
+  +}
+  +
+   if (y) {
+      do_something_else();
+   }
+  diff --git a/c.rb b/c.rb
+  --- a/c.rb
+  +++ b/c.rb
+  @@ -1,4 +1,7 @@
+   #!ruby
+  +["foo", "bar", "baz"].map do |i|
+  +  i
+  +end
+   ["foo", "bar", "baz"].map do |i|
+     i.upcase
+   end
+  diff --git a/d.py b/d.py
+  --- a/d.py
+  +++ b/d.py
+  @@ -2,6 +2,10 @@
+       import foo
+   except ImportError:
+       pass
+  +try:
+  +    import baz
+  +except ImportError:
+  +    pass
+   try:
+       import bar
+   except ImportError:
+  diff --git a/functions.c b/functions.c
+  --- a/functions.c
+  +++ b/functions.c
+  @@ -1,5 +1,10 @@
+   1
+   2
+  +/* function */
+  +bar() {
+  +    foo
+  +}
+  +
+   /* function */
+   foo() {
+       foo
+  diff --git a/spaces.txt b/spaces.txt
+  --- a/spaces.txt
+  +++ b/spaces.txt
+  @@ -2,6 +2,9 @@
+   2
+   a
+   
+  +b
+  +a
+  +
+   b
+   3
+   4
+#else
+  $ hg diff --git
+  diff --git a/a.c b/a.c
+  --- a/a.c
+  +++ b/a.c
+  @@ -5,12 +5,6 @@
+     return 1;
+   }
+   /*
+  - * This function returns 2.
+  - */
+  -int g() {
+  -  return 2;
+  -}
+  -/*
+    * This function returns 3.
+    */
+   int h() {
+  diff --git a/b.c b/b.c
+  --- a/b.c
+  +++ b/b.c
+  @@ -3,5 +3,9 @@
+   }
+   
+   if (y) {
+  +   do_another_thing();
+  +}
+  +
+  +if (y) {
+      do_something_else();
+   }
+  diff --git a/c.rb b/c.rb
+  --- a/c.rb
+  +++ b/c.rb
+  @@ -1,4 +1,7 @@
+   #!ruby
+   ["foo", "bar", "baz"].map do |i|
+  +  i
+  +end
+  +["foo", "bar", "baz"].map do |i|
+     i.upcase
+   end
+  diff --git a/d.py b/d.py
+  --- a/d.py
+  +++ b/d.py
+  @@ -3,6 +3,10 @@
+   except ImportError:
+       pass
+   try:
+  +    import baz
+  +except ImportError:
+  +    pass
+  +try:
+       import bar
+   except ImportError:
+       pass
+  diff --git a/functions.c b/functions.c
+  --- a/functions.c
+  +++ b/functions.c
+  @@ -1,6 +1,11 @@
+   1
+   2
+   /* function */
+  +bar() {
+  +    foo
+  +}
+  +
+  +/* function */
+   foo() {
+       foo
+   }
+  diff --git a/spaces.txt b/spaces.txt
+  --- a/spaces.txt
+  +++ b/spaces.txt
+  @@ -3,5 +3,8 @@
+   a
+   
+   b
+  +a
+  +
+  +b
+   3
+   4
+#endif