Using the Power to Prove

1,794 views

Published on

Prove is a program to run test suites, but it can be also used as a general purpose task runner.

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,794
On SlideShare
0
From Embeds
0
Number of Embeds
82
Actions
Shares
0
Downloads
3
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Using the Power to Prove

  1. 1. Using the Power to Prove DeNA Co., Ltd. Kazuho Oku
  2. 2. Do you know prove? Have you ever used it? Sep 20 2013 Using the Power to Prove 2
  3. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 16. Prove is powerful! Can we run programs other than test scripts? Sep 20 2013 Using the Power to Prove 16
  17. 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. 18. Conclusion Sep 20 2013 Using the Power to Prove 18
  19. 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

×