diff -r 58786930ea27 -r 726cfc47f17a tests/test-contrib-testparseutil.t --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-contrib-testparseutil.t Thu Aug 23 12:25:54 2018 +0900 @@ -0,0 +1,192 @@ + $ testparseutil="$TESTDIR"/../contrib/testparseutil.py + +Internal test by doctest + + $ "$PYTHON" -m doctest "$testparseutil" + +Tests for embedded python script + +Typical cases + + $ "$PYTHON" "$testparseutil" -v pyembedded < >>> for f in [1, 2, 3]: + > ... foo = 1 + > >>> foo = 2 + > $ echo "doctest is terminated by command, empty line, or comment" + > >>> foo = 31 + > expected output of doctest fragment + > >>> foo = 32 + > + > >>> foo = 33 + > + > >>> foo = 34 + > comment + > >>> foo = 35 + > + > $ "\$PYTHON" < > foo = 4 + > > + > > EOF + > $ cat > foo.py < > foo = 5 + > > EOF + > $ cat >> foo.py < > foo = 6 # appended + > > EOF + > + > NO_CHECK_EOF limit mark makes parsing ignore corresponded fragment + > (this is useful to use bad code intentionally) + > + > $ "\$PYTHON" < > foo = 7 # this should be ignored at detection + > > NO_CHECK_EOF + > $ cat > foo.py < > foo = 8 # this should be ignored at detection + > > NO_CHECK_EOF + > + > doctest fragment ended by EOF + > + > >>> foo = 9 + > NO_CHECK_EOF + :1: starts + |for f in [1, 2, 3]: + | foo = 1 + |foo = 2 + :4: ends + :5: starts + |foo = 31 + | + |foo = 32 + | + |foo = 33 + :10: ends + :11: starts + |foo = 34 + :12: ends + :13: starts + |foo = 35 + :14: ends + :16: starts + |foo = 4 + | + :18: ends + :20: foo.py starts + |foo = 5 + :21: foo.py ends + :23: foo.py starts + |foo = 6 # appended + :24: foo.py ends + :38: starts + |foo = 9 + :39: ends + +Invalid test script + +(similar test for shell script and hgrc configuration is omitted, +because this tests common base class of them) + + $ "$PYTHON" "$testparseutil" -v pyembedded < detected + > $ "\$PYTHON" < > foo = 1 + > + > $ "\$PYTHON" < > foo = 2 + > $ cat > bar.py < > bar = 2 # this fragment will be detected as expected + > > EOF + > + > $ cat > foo.py < > foo = 3 + > NO_CHECK_EOF + :3: unexpected line for "heredoc python invocation" + :6: unexpected line for "heredoc python invocation" + :11: unexpected end of file for "heredoc .py file" + [1] + $ cat detected + :7: bar.py starts + |bar = 2 # this fragment will be detected as expected + :8: bar.py ends + +Tests for embedded shell script + + $ "$PYTHON" "$testparseutil" -v shembedded < $ cat > foo.sh < > foo = 1 + > > + > > foo = 2 + > > EOF + > $ cat >> foo.sh < > foo = 3 # appended + > > EOF + > + > NO_CHECK_EOF limit mark makes parsing ignore corresponded fragment + > (this is useful to use bad code intentionally) + > + > $ cat > foo.sh < > # this should be ignored at detection + > > foo = 4 + > > NO_CHECK_EOF + > + > NO_CHECK_EOF + :2: foo.sh starts + |foo = 1 + | + |foo = 2 + :5: foo.sh ends + :7: foo.sh starts + |foo = 3 # appended + :8: foo.sh ends + +Tests for embedded hgrc configuration + + $ "$PYTHON" "$testparseutil" -v hgrcembedded < $ cat > .hg/hgrc < > [ui] + > > verbose = true + > > + > > # end of local configuration + > > EOF + > + > $ cat > \$HGRCPATH < > [extensions] + > > rebase = + > > # end of global configuration + > > EOF + > + > $ cat >> \$HGRCPATH < > # appended + > > [extensions] + > > rebase =! + > > EOF + > + > NO_CHECK_EOF limit mark makes parsing ignore corresponded fragment + > (this is useful to use bad code intentionally) + > + > $ cat > .hg/hgrc < > # this local configuration should be ignored at detection + > > [ui] + > > username = foo bar + > > NO_CHECK_EOF + > + > $ cat > \$HGRCPATH < > # this global configuration should be ignored at detection + > > [extensions] + > > foobar = + > > NO_CHECK_EOF + > NO_CHECK_EOF + :2: .hg/hgrc starts + |[ui] + |verbose = true + | + |# end of local configuration + :6: .hg/hgrc ends + :9: $HGRCPATH starts + |[extensions] + |rebase = + |# end of global configuration + :12: $HGRCPATH ends + :15: $HGRCPATH starts + |# appended + |[extensions] + |rebase =! + :18: $HGRCPATH ends