[PATCH 1 of 2] test-drawdag: add a test for drawdag.py

Jun Wu quark at fb.com
Wed Jun 28 14:20:46 EDT 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1498545113 25200
#      Mon Jun 26 23:31:53 2017 -0700
# Node ID 4764385c53710bdb995b7b7fb8f767cfc790311f
# Parent  6ef5f0c95d643d114262f8c6689a6fc02adb0da7
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 4764385c5371
test-drawdag: add a test for drawdag.py

The drawdag script is useful but does not have a formal test. This patch
adds it.

diff --git a/tests/test-drawdag.t b/tests/test-drawdag.t
new file mode 100644
--- /dev/null
+++ b/tests/test-drawdag.t
@@ -0,0 +1,180 @@
+  $ cat >> $HGRCPATH<<EOF
+  > [extensions]
+  > drawdag=$TESTDIR/drawdag.py
+  > EOF
+
+  $ function reinit() {
+  >   rm -rf .hg && hg init
+  > }
+
+  $ hg init
+
+Test what said in drawdag.py docstring
+
+  $ hg debugdrawdag <<'EOS'
+  > c d
+  > |/
+  > b
+  > |
+  > a
+  > EOS
+
+  $ hg log -G -T '{rev} {desc} ({tags})'
+  o  3 d (d tip)
+  |
+  | o  2 c (c)
+  |/
+  o  1 b (b)
+  |
+  o  0 a (a)
+  
+  $ hg debugdrawdag <<'EOS'
+  >  foo    bar       bar  foo
+  >   |     /          |    |
+  >  ancestor(c,d)     a   baz
+  > EOS
+
+  $ hg log -G -T '{desc}'
+  o    foo
+  |\
+  +---o  bar
+  | | |
+  | o |  baz
+  |  /
+  +---o  d
+  | |
+  +---o  c
+  | |
+  o |  b
+  |/
+  o  a
+  
+  $ reinit
+
+  $ hg debugdrawdag <<'EOS'
+  > o    foo
+  > |\
+  > +---o  bar
+  > | | |
+  > | o |  baz
+  > |  /
+  > +---o  d
+  > | |
+  > +---o  c
+  > | |
+  > o |  b
+  > |/
+  > o  a
+  > EOS
+
+  $ hg log -G -T '{desc}'
+  o    foo
+  |\
+  | | o  d
+  | |/
+  | | o  c
+  | |/
+  | | o  bar
+  | |/|
+  | o |  b
+  | |/
+  o /  baz
+   /
+  o  a
+  
+  $ reinit
+
+  $ hg debugdrawdag <<'EOS'
+  > o    foo
+  > |\
+  > | | o  d
+  > | |/
+  > | | o  c
+  > | |/
+  > | | o  bar
+  > | |/|
+  > | o |  b
+  > | |/
+  > o /  baz
+  >  /
+  > o  a
+  > EOS
+
+  $ hg log -G -T '{desc}'
+  o    foo
+  |\
+  | | o  d
+  | |/
+  | | o  c
+  | |/
+  | | o  bar
+  | |/|
+  | o |  b
+  | |/
+  o /  baz
+   /
+  o  a
+  
+
+Edges existed in repo are no-ops
+
+  $ reinit
+  $ hg debugdrawdag <<'EOS'
+  > B C C
+  > | | |
+  > A A B
+  > EOS
+
+  $ hg log -G -T '{desc}'
+  o    C
+  |\
+  | o  B
+  |/
+  o  A
+  
+
+  $ hg debugdrawdag <<'EOS'
+  > C D C
+  > | | |
+  > B B A
+  > EOS
+
+  $ hg log -G -T '{desc}'
+  o  D
+  |
+  | o  C
+  |/|
+  o |  B
+  |/
+  o  A
+  
+
+Node with more than 2 parents are disallowed
+
+  $ hg debugdrawdag <<'EOS'
+  >   A
+  >  /|\
+  > D B C
+  > EOS
+  abort: A: too many parents: C D B
+  [255]
+
+Cycles are disallowed
+
+  $ hg debugdrawdag <<'EOS'
+  > A
+  > |
+  > A
+  > EOS
+  abort: the graph has cycles
+  [255]
+
+  $ hg debugdrawdag <<'EOS'
+  > A
+  > |
+  > B
+  > |
+  > A
+  > EOS
+  abort: the graph has cycles
+  [255]


More information about the Mercurial-devel mailing list