📄 test::harness::tap.3
字号:
.IX Subsection "Bail out!"As an emergency measure a test script can decide that further testsare useless (e.g. missing dependencies) and testing should stopimmediately. In that case the test script prints the magic words.PP.Vb 1\& Bail out!.Ve.PPto standard output. Any message after these words must be displayedby the interpreter as the reason why testing must be stopped, asin.PP.Vb 1\& Bail out! MySQL is not running..Ve.Sh "Diagnostics".IX Subsection "Diagnostics"Additional information may be put into the testing output on separatelines. Diagnostic lines should begin with a \f(CW\*(C`#\*(C'\fR, which the harness mustignore, at least as far as analyzing the test results. The harness isfree, however, to display the diagnostics. Typically diagnostics areused to provide information about the environment in which test file isrunning, or to delineate a group of tests..PP.Vb 9\& ...\& ok 18 \- Closed database connection\& # End of database section.\& # This starts the network part of the test.\& # Daemon started on port 2112\& ok 19 \- Opened socket\& ...\& ok 47 \- Closed socket\& # End of network tests.Ve.Sh "Anything else".IX Subsection "Anything else"Any output line that is not a plan, a test line or a diagnostic isincorrect. How a harness handles the incorrect line is undefined.Test::Harness silently ignores incorrect lines, but will become morestringent in the future..SH "EXAMPLES".IX Header "EXAMPLES"All names, places, and events depicted in any example are whollyfictitious and bear no resemblance to, connection with, or relation to anyreal entity. Any such similarity is purely coincidental, unintentional,and unintended..Sh "Common with explanation".IX Subsection "Common with explanation"The following \s-1TAP\s0 listing declares that six tests follow as well asprovides handy feedback as to what the test is about to do. All sixtests pass..PP.Vb 11\& 1..6\& #\& # Create a new Board and Tile, then place\& # the Tile onto the board.\& #\& ok 1 \- The object isa Board\& ok 2 \- Board size is zero\& ok 3 \- The object isa Tile\& ok 4 \- Get possible places to put the Tile\& ok 5 \- Placing the tile produces no error\& ok 6 \- Board size is 1.Ve.Sh "Unknown amount and failures".IX Subsection "Unknown amount and failures"This hypothetical test program ensures that a handful of servers areonline and network-accessible. Because it retrieves the hypotheticalservers from a database, it doesn't know exactly how many servers itwill need to ping. Thus, the test count is declared at the bottom afterall the test points have run. Also, two of the tests fail..PP.Vb 9\& ok 1 \- retrieving servers from the database\& # need to ping 6 servers\& ok 2 \- pinged diamond\& ok 3 \- pinged ruby\& not ok 4 \- pinged saphire\& ok 5 \- pinged onyx\& not ok 6 \- pinged quartz\& ok 7 \- pinged gold\& 1..7.Ve.Sh "Giving up".IX Subsection "Giving up"This listing reports that a pile of tests are going to be run. However,the first test fails, reportedly because a connection to the databasecould not be established. The program decided that continuing waspointless and exited..PP.Vb 3\& 1..573\& not ok 1 \- database handle\& Bail out! Couldn\*(Aqt connect to database..Ve.Sh "Skipping a few".IX Subsection "Skipping a few"The following listing plans on running 5 tests. However, our programdecided to not run tests 2 thru 5 at all. To properly report this,the tests are marked as being skipped..PP.Vb 7\& 1..5\& ok 1 \- approved operating system\& # $^0 is solaris\& ok 2 \- # SKIP no /sys directory\& ok 3 \- # SKIP no /sys directory\& ok 4 \- # SKIP no /sys directory\& ok 5 \- # SKIP no /sys directory.Ve.Sh "Skipping everything".IX Subsection "Skipping everything"This listing shows that the entire listing is a skip. No tests were run..PP.Vb 1\& 1..0 # skip because English\-to\-French translator isn\*(Aqt installed.Ve.Sh "Got spare tuits?".IX Subsection "Got spare tuits?"The following example reports that four tests are run and the last twotests failed. However, because the failing tests are marked as thingsto do later, they are considered successes. Thus, a harness should reportthis entire listing as a success..PP.Vb 5\& 1..4\& ok 1 \- Creating test program\& ok 2 \- Test program runs, no error\& not ok 3 \- infinite loop # TODO halting problem unsolved\& not ok 4 \- infinite loop 2 # TODO halting problem unsolved.Ve.Sh "Creative liberties".IX Subsection "Creative liberties"This listing shows an alternate output where the test numbers aren'tprovided. The test also reports the state of a ficticious board game indiagnostic form. Finally, the test count is reported at the end..PP.Vb 10\& ok \- created Board\& ok\& ok\& ok\& ok\& ok\& ok\& ok\& # +\-\-\-\-\-\-+\-\-\-\-\-\-+\-\-\-\-\-\-+\-\-\-\-\-\-+\& # | |16G | |05C |\& # | |G N C | |C C G |\& # | | G | | C +|\& # +\-\-\-\-\-\-+\-\-\-\-\-\-+\-\-\-\-\-\-+\-\-\-\-\-\-+\& # |10C |01G | |03C |\& # |R N G |G A G | |C C C |\& # | R | G | | C +|\& # +\-\-\-\-\-\-+\-\-\-\-\-\-+\-\-\-\-\-\-+\-\-\-\-\-\-+\& # | |01G |17C |00C |\& # | |G A G |G N R |R N R |\& # | | G | R | G |\& # +\-\-\-\-\-\-+\-\-\-\-\-\-+\-\-\-\-\-\-+\-\-\-\-\-\-+\& ok \- board has 7 tiles + starter tile\& 1..9.Ve.SH "Non-Perl TAP".IX Header "Non-Perl TAP"In Perl, we use Test::Simple and Test::More to generate \s-1TAP\s0 output.Other languages have solutions that generate \s-1TAP\s0, so that they can takeadvantage of Test::Harness..PPThe following sections are provided by their maintainers, and may notbe up-to-date..Sh "C/\*(C+".IX Subsection "C/"libtap makes it easy to write test programs in C that produceTAP-compatible output. Modeled on the Test::More \s-1API\s0, libtap containsall the functions you need to:.IP "\(bu" 4Specify a test plan.IP "\(bu" 4Run tests.IP "\(bu" 4Skip tests in certain situations.IP "\(bu" 4Have \s-1TODO\s0 tests.IP "\(bu" 4Produce \s-1TAP\s0 compatible diagnostics.PPMore information about libtap, including download links, checksums,anonymous access to the Subersion repository, and a bug trackingsystem, can be found at:.PP.Vb 1\& http://jc.ngo.org.uk/trac\-bin/trac.cgi/wiki/LibTap.Ve.PP(Nik Clayton, April 17, 2006).Sh "Python".IX Subsection "Python"PyTap will, when it's done, provide a simple, assertive (Test::More\-like)interface for writing tests in Python. It will output \s-1TAP\s0 and willinclude the functionality found in Test::Builder and Test::More. It willtry to make it easy to add more test code (so you can write your own\&\f(CW\*(C`TAP.StringDiff\*(C'\fR, for example..PPRight now, it's got a fair bit of the basics needed to emulate Test::More,and I think it's easy to add more stuff \*(-- just like Test::Builder,there's a singleton that you can get at easily..PPI need to better identify and finish implementing the most basic tests.I am not a Python guru, I just use it from time to time, so my aim maynot be true. I need to write tests for it, which means either relyingon Perl for the tester tester, or writing one in Python..PPHere's a sample test, as found in my Subversion:.PP.Vb 1\& from TAP.Simple import *\&\& plan(15)\&\& ok(1)\& ok(1, "everything is OK!")\& ok(0, "always fails")\&\& is_ok(10, 10, "is ten ten?")\& is_ok(ok, ok, "even ok is ok!")\& ok(id(ok), "ok is not the null pointer")\& ok(True, "the Truth will set you ok")\& ok(not False, "and nothing but the truth")\& ok(False, "and we\*(Aqll know if you lie to us")\&\& isa_ok(10, int, "10")\& isa_ok(\*(Aqok\*(Aq, str, "some string")\&\& ok(0, "zero is true", todo="be more like Ruby!")\& ok(None, "none is true", skip="not possible in this universe")\&\& eq_ok("not", "equal", "two strings are not equal");.Ve.PP(Ricardo Signes, April 17, 2006).Sh "JavaScript".IX Subsection "JavaScript"Test.Simple looks and acts just like \s-1TAP\s0, although in reality it'stracking test results in an object rather than scraping them from aprint buffer..PP.Vb 1\& http://openjsan.org/doc/t/th/theory/Test/Simple/.Ve.PP(David Wheeler, April 17, 2006).Sh "\s-1PHP\s0".IX Subsection "PHP"All the big \s-1PHP\s0 players now produce \s-1TAP\s0.IP "\(bu" 4phpt.SpOutputs \s-1TAP\s0 by default as of the yet-to-be-released \s-1PEAR\s0 1.5.0.Sp.Vb 1\& http://pear.php.net/PEAR.Ve.IP "\(bu" 4PHPUnit.SpHas a \s-1TAP\s0 logger (since 2.3.4).Sp.Vb 1\& http://www.phpunit.de/wiki/Main_Page.Ve.IP "\(bu" 4SimpleTest.SpThere's a third-party \s-1TAP\s0 reporting extension for SimpleTest.Sp.Vb 1\& http://www.digitalsandwich.com/archives/51\-Updated\-Simpletest+Apache\-Test.html.Ve.IP "\(bu" 4Apache-Test.SpApache-Test's \s-1PHP\s0 writes \s-1TAP\s0 by default and includes the standalonetest\-more.php.Sp.Vb 1\& http://search.cpan.org/dist/Apache\-Test/.Ve.PP(Geoffrey Young, April 17, 2006).SH "AUTHORS".IX Header "AUTHORS"Andy Lester, based on the original Test::Harness documentation by Michael Schwern..SH "ACKNOWLEDGEMENTS".IX Header "ACKNOWLEDGEMENTS"Thanks toPete Krawczyk,Paul Johnson,Ian Langworthand Nik Claytonfor help and contributions on this document..PPThe basis for the \s-1TAP\s0 format was created by Larry Wall in theoriginal test script for Perl 1. Tim Bunce and Andreas Koenigdeveloped it further with their modifications to Test::Harness..SH "COPYRIGHT".IX Header "COPYRIGHT"Copyright 2003\-2005 byMichael G Schwern \f(CW\*(C`<schwern@pobox.com>\*(C'\fR,Andy Lester \f(CW\*(C`<andy@petdance.com>\*(C'\fR..PPThis program is free software; you can redistribute it and/ormodify it under the same terms as Perl itself..PPSee <http://www.perl.com/perl/misc/Artistic.html>.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -