Using thePower to
ProveDeNA Co., Ltd.
Kazuho Oku
Do you know prove?Have you ever used it?
Sep 20 2013 Using the Power to Prove 2
Prove is…
command-line interface of Test::Harness
Test::Harness is the test runner
Sep 20 2013 Using the Power to Prove 3
$ make testPERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'inc', 'blib/lib', 'blib/arch')" t/00-base.t t/01-new.t t/02-use.t t/03-use-error.t t/04-use-defaults.tt/00-base.t .......... ok t/01-new.t ........... ok …
$ provet/00-base.t .......... ok t/01-new.t ........... ok…
Test Anything Protocol (TAP)
Test::Harness runs the scripts and aggregates the results
test scripts return the data using TAP
Sep 20 2013 Using the Power to Prove 4
$ perl t/00-base.t 1..14ok 1 - use Class::Accessor::Lite;ok 2 - call mk_accessorsok 3ok 4…
History of Test::Harness and TAP
TAP exists since Perl 1Test::Harness is part of Perl core
and is part of Linux Standards Base
bindings exist for many programming languages http://en.wikipedia.org/wiki/Test_Anything_Protocol
Sep 20 2013 Using the Power to Prove 5
Prove has many powerful options
Sep 20 2013 Using the Power to Prove 6
$ prove -j 8 --state hot,fast,save
- runs 8 tests in parallel - run the tests that failed first - run the fast tests first, and then others that takes time - update the test stats
Can we write tests in other programming languages, and
aggregate the results using prove?
Sep 20 2013 Using the Power to Prove 7
Prove runs scripts written in any language
but how?
Sep 20 2013 Using the Power to Prove 8
$ cat bf.t #! /usr/local/bin/yabi-[----->+<]>--.---..+++.>++++++++++.-[------->+<]>.----.-[++>---<]>+.[-->+++<]>+.>++++++++++.
$ yabi bf.t1..1ok 1
$ prove bf.t bf.t .. ok All tests successful.Files=1, Tests=1, 0 wallclock secs ( 0.02 usr + 0.00 sys = 0.02 CPU)Result: PASS
PerlProve runs scripts written in any language
Perl understands the shebang
Sep 20 2013 Using the Power to Prove 9
$ cat bf.t #! /usr/local/bin/yabi-[----->+<]>--.---..+++.>++++++++++.-[------->+<]>.----.-[++>---<]>+.[-->+++<]>+.>++++++++++.
$ perl bf.t 1..1ok 1
PerlProve runs scripts written in any language
but not binary executables…
Sep 20 2013 Using the Power to Prove 10
$ cat bin.c #include <stdio.h>int main(int argc, char** argv){ printf("1..1\n"); printf("ok 1\n"); return 0;}
$ perl bin Unrecognized character \xCF; marked by <-- HERE after <-- HERE near column 1 at bin line 1.
prove --exec '' solves the problem
why?
Sep 20 2013 Using the Power to Prove 11
$ prove –h… -e, --exec Interpreter to run the tests ('' for compiled tests.)…
$ prove --exec '' binbin .. open3: exec of bin failed at /System/Library/Perl/5.12/TAP/Parser/Iterator/Process.pm line 163.bin .. Dubious, test returned 255 (wstat 65280, 0xff00)No subtests run
prove --exec '' solves the problem
specify the paths, or add . to $PATHbut would test scripts stop running on
Windows
Sep 20 2013 Using the Power to Prove 12
$ prove --exec '' t/bint/bin .. ok All tests successful.Files=1, Tests=1, 1 wallclock secs ( 0.02 usr + 0.01 sys = 0.03 CPU)Result: PASS
$ PATH=".:$PATH" prove --exec '' binbin .. ok All tests successful.Files=1, Tests=1, 0 wallclock secs ( 0.02 usr + 0.01 sys = 0.03 CPU)Result: PASS
Extensions can be other than .t
use: --ext ""
Sep 20 2013 Using the Power to Prove 13
$ prove --ext '' --exec '' ../test.bf ... ok ./test.out .. ok ./test.sh ... ok All tests successful.Files=3, Tests=3, 0 wallclock secs ( 0.02 usr + 0.01 sys = 0.03 CPU)Result: PASS
.proverc
Save the prove options for the project
Sep 20 2013 Using the Power to Prove 14
$ cat .proverc--ext '' --exec ''
$ prove ../test.bf ... ok ./test.out .. ok ./test.sh ... ok All tests successful.Files=3, Tests=3, 0 wallclock secs ( 0.02 usr + 0.01 sys = 0.03 CPU)Result: PASS
Test scripts are searched by default from t/
Sep 20 2013 Using the Power to Prove 15
$ cat .proverc--ext '' --exec ''
$ provet/test.bf ... ok t/test.out .. ok t/test.sh ... ok All tests successful.Files=3, Tests=3, 0 wallclock secs ( 0.02 usr + 0.01 sys = 0.03 CPU)Result: PASS
Prove is powerful! Can we run programs other than test scripts?
Sep 20 2013 Using the Power to Prove 16
Running things other than test scripts
cron tasksservice monitoring
Sep 20 2013 Using the Power to Prove 17
$ ls thttp.t memcached.t mysql.t ping.tsmtp.t$ provet/http.t ....... ok t/memcached.t .. ok t/mysql.t ...... ok t/ping.t ....... ok t/smtp.t ....... ok All tests successful.
Conclusion
Sep 20 2013 Using the Power to Prove 18
Conclusion
Prove is a proven task runnercan run any kind of tasks and generate a
reportpreinstalled on most systemsuses TAP - an established protocol
Sep 20 2013 Using the Power to Prove 19