SlideShare a Scribd company logo
Using the
Power to Prove
DeNA 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 test
PERL_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.t
t/00-base.t .......... ok
t/01-new.t ........... ok
…
$ prove
t/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..14
ok 1 - use Class::Accessor::Lite;
ok 2 - call mk_accessors
ok 3
ok 4
…
History of Test::Harness and TAP
TAP exists since Perl 1
Test::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.t
1..1
ok 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..1
ok 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..1n");
printf("ok 1n");
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 '' bin
bin .. 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 $PATH
but would test scripts stop running on Windows
Sep 20 2013 Using the Power to Prove 12
$ prove --exec '' t/bin
t/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 '' bin
bin .. 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 ''
$ prove
t/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 tasks
service monitoring
Sep 20 2013 Using the Power to Prove 17
$ ls t
http.t memcached.t mysql.t ping.t
smtp.t
$ prove
t/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 runner
can run any kind of tasks and generate a report
preinstalled on most systems
uses TAP - an established protocol
Sep 20 2013 Using the Power to Prove 19

More Related Content

Using the Power to Prove

  • 1. Using the Power to Prove DeNA Co., Ltd. Kazuho Oku
  • 2. Do you know prove? Have you ever used it? Sep 20 2013 Using the Power to Prove 2
  • 3. Prove is… command-line interface of Test::Harness Test::Harness is the test runner Sep 20 2013 Using the Power to Prove 3 $ make test PERL_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.t t/00-base.t .......... ok t/01-new.t ........... ok … $ prove t/00-base.t .......... ok t/01-new.t ........... ok …
  • 4. 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..14 ok 1 - use Class::Accessor::Lite; ok 2 - call mk_accessors ok 3 ok 4 …
  • 5. History of Test::Harness and TAP TAP exists since Perl 1 Test::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
  • 6. 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
  • 7. Can we write tests in other programming languages, and aggregate the results using prove? Sep 20 2013 Using the Power to Prove 7
  • 8. 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.t 1..1 ok 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
  • 9. 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..1 ok 1
  • 10. 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..1n"); printf("ok 1n"); return 0; } $ perl bin Unrecognized character xCF; marked by <-- HERE after <-- HERE near column 1 at bin line 1.
  • 11. 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 '' bin bin .. 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
  • 12. prove --exec '' solves the problem specify the paths, or add . to $PATH but would test scripts stop running on Windows Sep 20 2013 Using the Power to Prove 12 $ prove --exec '' t/bin t/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 '' bin bin .. ok All tests successful. Files=1, Tests=1, 0 wallclock secs ( 0.02 usr + 0.01 sys = 0.03 CPU) Result: PASS
  • 13. 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
  • 14. .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
  • 15. Test scripts are searched by default from t/ Sep 20 2013 Using the Power to Prove 15 $ cat .proverc --ext '' --exec '' $ prove t/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
  • 16. Prove is powerful! Can we run programs other than test scripts? Sep 20 2013 Using the Power to Prove 16
  • 17. Running things other than test scripts cron tasks service monitoring Sep 20 2013 Using the Power to Prove 17 $ ls t http.t memcached.t mysql.t ping.t smtp.t $ prove t/http.t ....... ok t/memcached.t .. ok t/mysql.t ...... ok t/ping.t ....... ok t/smtp.t ....... ok All tests successful.
  • 18. Conclusion Sep 20 2013 Using the Power to Prove 18
  • 19. Conclusion Prove is a proven task runner can run any kind of tasks and generate a report preinstalled on most systems uses TAP - an established protocol Sep 20 2013 Using the Power to Prove 19