Using the Power to Prove
-
Upload
kazuho-oku -
Category
Technology
-
view
796 -
download
0
description
Transcript of Using the Power to Prove
![Page 1: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/1.jpg)
Using thePower to
ProveDeNA Co., Ltd.
Kazuho Oku
![Page 2: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/2.jpg)
Do you know prove?Have you ever used it?
Sep 20 2013 Using the Power to Prove 2
![Page 3: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/3.jpg)
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…
![Page 4: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/4.jpg)
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…
![Page 5: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/5.jpg)
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
![Page 6: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/6.jpg)
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
![Page 7: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/7.jpg)
Can we write tests in other programming languages, and
aggregate the results using prove?
Sep 20 2013 Using the Power to Prove 7
![Page 8: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/8.jpg)
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
![Page 9: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/9.jpg)
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
![Page 10: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/10.jpg)
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.
![Page 11: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/11.jpg)
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
![Page 12: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/12.jpg)
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
![Page 13: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/13.jpg)
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
![Page 14: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/14.jpg)
.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
![Page 15: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/15.jpg)
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
![Page 16: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/16.jpg)
Prove is powerful! Can we run programs other than test scripts?
Sep 20 2013 Using the Power to Prove 16
![Page 17: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/17.jpg)
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.
![Page 18: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/18.jpg)
Conclusion
Sep 20 2013 Using the Power to Prove 18
![Page 19: Using the Power to Prove](https://reader036.fdocuments.us/reader036/viewer/2022082809/556ae8e6d8b42a86218b4b53/html5/thumbnails/19.jpg)
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