SlideShare a Scribd company logo
1 of 42
Download to read offline
Getting Testy with Perl6:
Things you wish you'd known.
Steven Lembark
Workhorse Computing
lemark@wrkhors.com
Helpful items
$ panda install p6doc;
http://doc.perl6.org/
# doc for testing:
/language/testing
Helpful items
$ panda install p6doc;
http://doc.perl6.org/
# doc for testing:
/language/testing
Core module
Core modules are documented in:
./share/perl6/doc/Language/*
Which includes "testing.pod".
Viewing source
To see the source of a module:
panda look <module name>;
This will fetch the module (even if it is 
installed).
Basic of Perl6 Testing
Pretty much what you are used to:
  “Test” module for testing.
  ok(), is() & friends.
Main differences are in Perl6 itself.
What you are used to
Test::More
ok()
use v5.22;
use Test::More;
my $x = '0';
my $y = 'asdf';
ok $x == $y, "$x == $y";
done_testing;
What you are used to
Zero            
equals         
zero.
$ prove -v Perl5.t;
Perl5 ..
ok 1 - 0 == asdf
1..1
ok
All tests successful.
Files=1, Tests=1, ...
Result: PASS
Doing it in Perl6
Module 
is 
“Test”
use v6;
use Test;
my $x = '0';
my $y = 'asdf';
ok $x == $y, "$x == $y";
done-testing;
Doing it in Perl6
Notice        
the dash!
use v6;
use Test;
my $x = '0';
my $y = 'asdf';
ok $x == $y, "$x == $y";
done-testing;
Prove is still prove
Execute    
“perl6”.
$ prove -v --exec perl6;
$ prove -v -e perl6 t/Perl6.t;
$ prove -v -e /opt/bin/perl6;
Not quite zero:
t/Perl6.t .. Cannot convert string to number:
base-10 number must begin with valid digits or
'.' in 'âasdf' (indicated by â)
in block <unit> at t/Perl6.t line 7
Actually thrown at:
in block <unit> at t/Perl6.t line 7
Lesson 1: Typing matters in Perl6
is()    
handles 
strings, 
types.
use v6;
use Test;
my $x = '0';
my $y = 'asdf';
is $x, $y, "$x eq $y";
done-testing;
Lesson 1: Typing matters in Perl6
Nice 
messages. 
t/Perl6.t ..
not ok 1 - 0 == asdf
# Failed test '0 eq asdf'
# at t/Perl6.t line 7
# expected: 'asdf'
# got: '0'
1..1
# Looks like you failed 1 test
of 1
Dubious, test returned 1 (wstat
256, 0x100)
Failed 1/1 subtests
Comparing types
WHAT 
returns a 
type.
use v6;
use Test;
my $x = 0;
is $x.WHAT, Int, "$x is Int";
done-testing;
Comparing types
WHAT 
returns a 
type.
Int is an 
object, not a 
string.
use v6;
use Test;
my $x = 0;
is $x.WHAT, Int, "$x is Int";
done-testing;
Comparing types
WHAT 
returns a 
type.
Int is an 
object, not a 
string.
use v6;
use Test;
my $x = 0;
is $x.WHAT, Int, "$x is Int";
done-testing;
Comparing types
WHAT 
returns          
 a type.
$ prove -v -e perl6 t/Perl6.t
t/Perl6.t ..
ok 1 - 0 is Int
1..1
ok
All tests successful.
Comparing objects
WHICH 
identifies an 
object.
use v6;
use Test;
my $x = 0;
is $x.WHAT, Int, "$x is Int";
note '$x is ' ~ $x.WHICH;
done-testing;
Comparing objects
No '#' 
before 
notes.
$ prove -v -e perl6 t/Perl6.t
t/Perl6.t ..
ok 1 - 0 is Int
1..1
$x is Int|0
ok
REPL
Worth using to view results, contents.
$ perl6
To exit type 'exit' or '^D'
You may want to `panda install Readline` or
`panda install Linenoise` or use rlwrap for a
line editor
Aside: Using the bear
Fairly simple.
Annoying side effect: ~/.perl6/*
$ panda install Readline;
Viewing contents
> %a = ( 'a' .. 'e' );
Odd number of elements found where hash
initializer expected in block <unit> at
<unknown file> line 1
> %a.gist;
{a => b, c => d} # human-readable, no 'e'!
> %a.perl;
{:a("b"), :c("d")} # round-trip form
> dd %a;
Hash %a = {:a("b"), :c("d")}
Testing Manually
Nil is a
Good Thing.
> use Test;
Nil
Assigning objects: new copy
Identical 
contents 
match as 
strings & 
numbers.
+> my %a = ( 'a' .. 'd' );
{a => b, c => d}
+> my %b = %a;
{a => b, c => d}
+> ok %a == %b;
ok 1 -
+> ok %a eq %b;
ok 2 -
+> is %a, %b;
ok 3 -
Assigning objects: new copy
They are 
different 
objects.
“===” is  
identity 
comparison
+> ok %a === %b;
not ok 4 -
# Failed test at <unknown
file> line 1
+> %a.WHICH, %b.WHICH;
(Hash|88201392 Hash|88204032)
Two types of tests
“Value” and “Non­value” types.
Values are compared by contents.
Non­values use WHICH.
Value comparison
Compare the contents:
   my $a = 42;
   my $b = 42;
  # compares as 42 == 42
  $a === $b
Non­value comparison
my %a = ( 'a' .. 'e' );
my @b = ( 'a' .. 'e' );
# compare %a.WHICH eq @b.WHICH.
%a === @b
Hashes don't flatten
my %a = ( 'a' .. 'e' );
my @b = %a;
my @c = ( 'a' .. 'e' );
+> dd %a, @b, @c
Hash %a = {:a("b"), :c("d")}
Array @b = [:a("b"), :c("d")]
Array @c = ["a", "b", "c", "d", “e”]
Hashes don't flatten
my %a = ( 'a' .. 'e' );
my @b = %a;
my @c = ( 'a' .. 'e' );
+> dd %a, @b, @c
Hash %a = {:a("b"), :c("d")}
Array @b = [:a("b"), :c("d")]
Array @c = ["a", "b", "c", "d", “e”]
Constant objects 
Some things like “Bag” are immutable.
These will share a WHICH value.
True with '===' (identity)
False with '=:=' (object id)
Bags are immutable
> my @a = ( 'a', 'b', 'b', 'c', 'c', 'c' );
[a b b c c c]
> my $b = @a.Bag;
bag(a, c(3), b(2))
> my $c = @a.Bag;
bag(a, c(3), b(2))
They have a common WHICH
> @a.WHICH;
Array|162386224
> $b.WHICH;
Bag|Str|a(1) Str|b(2) Str|c(3)
> $c.WHICH;
Bag|Str|a(1) Str|b(2) Str|c(3)
Equal identity, different address
> $b === $c # matching contents
True
> $b =:= $c # different objects
False
Have it your way
“eqv” used to compare objects.
This is an operator:
multi infix: <eqv> ( Foo $x, Bar $y )
Classes can supply their own.
Tests can override them. 
Multi­methods allow various comparisions
Compare to an Int:
multi infix: <eqv>
( MyClass $a, Int $b ) { ... }
Compare undefined value:
multi infix: <eqv>
(MyClass:U $a, Mu $b)
{ fail “Undefined MyClass Object” }
cmp­ok tests eqv implementation 
Is­deeply uses its own eqv.
cmp­ok uses yours:
cmp-ok $found, 'eqv', $expect;
cmp-ok $found, 'oneshot', $expect;
eqv can test whatever it wants to.
Similar control as Test2's DSL.
Compare only some of the keys...
Limit range for any values.
Multi­method simplifies tests.
is­approx
Absolute, relative tolerance to expect.
Uses eqv, requires same types.
Really nice for geo­coding, physical data:
my $abs-tol = 0.0005;
is-approx $lat, $exp, :$abs-tol;
Summary
Mostly the same: Test, ok(), is().
Testing objects requires more care:
  identity vs. address.
  value vs. WHAT.
Test module is readable.
See also
Liz deserves a hug for making this work...

More Related Content

What's hot

Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2
nottings
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
Michelangelo van Dam
 

What's hot (20)

Short Introduction To "perl -d"
Short Introduction To "perl -d"Short Introduction To "perl -d"
Short Introduction To "perl -d"
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
 
Metadata-driven Testing
Metadata-driven TestingMetadata-driven Testing
Metadata-driven Testing
 
Memory Manglement in Raku
Memory Manglement in RakuMemory Manglement in Raku
Memory Manglement in Raku
 
Findbin libs
Findbin libsFindbin libs
Findbin libs
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
Unit Testing in SilverStripe
Unit Testing in SilverStripeUnit Testing in SilverStripe
Unit Testing in SilverStripe
 
Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
 
Testing Javascript with Jasmine
Testing Javascript with JasmineTesting Javascript with Jasmine
Testing Javascript with Jasmine
 
Testing Code and Assuring Quality
Testing Code and Assuring QualityTesting Code and Assuring Quality
Testing Code and Assuring Quality
 
Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
Good karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaGood karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with Karma
 
Getting to Grips with SilverStripe Testing
Getting to Grips with SilverStripe TestingGetting to Grips with SilverStripe Testing
Getting to Grips with SilverStripe Testing
 
Jasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishy
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101
 

Similar to Getting Testy With Perl6

Similar to Getting Testy With Perl6 (20)

Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
PHP Unit Testing
PHP Unit TestingPHP Unit Testing
PHP Unit Testing
 
Chap1introppt2php(finally done)
Chap1introppt2php(finally done)Chap1introppt2php(finally done)
Chap1introppt2php(finally done)
 
Perl Teach-In (part 2)
Perl Teach-In (part 2)Perl Teach-In (part 2)
Perl Teach-In (part 2)
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
Introduction to Perl and BioPerl
Introduction to Perl and BioPerlIntroduction to Perl and BioPerl
Introduction to Perl and BioPerl
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
Testing With Test::Class
Testing With Test::ClassTesting With Test::Class
Testing With Test::Class
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
 
Testing in Laravel
Testing in LaravelTesting in Laravel
Testing in Laravel
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
 
ppopoff
ppopoffppopoff
ppopoff
 
DIG1108 Lesson 6
DIG1108 Lesson 6DIG1108 Lesson 6
DIG1108 Lesson 6
 
Chapter3
Chapter3Chapter3
Chapter3
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 

More from Workhorse Computing

More from Workhorse Computing (19)

Wheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility Modules
 
mro-every.pdf
mro-every.pdfmro-every.pdf
mro-every.pdf
 
Paranormal statistics: Counting What Doesn't Add Up
Paranormal statistics: Counting What Doesn't Add UpParanormal statistics: Counting What Doesn't Add Up
Paranormal statistics: Counting What Doesn't Add Up
 
Generating & Querying Calendar Tables in Posgresql
Generating & Querying Calendar Tables in PosgresqlGenerating & Querying Calendar Tables in Posgresql
Generating & Querying Calendar Tables in Posgresql
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
 
The W-curve and its application.
The W-curve and its application.The W-curve and its application.
The W-curve and its application.
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
 
Neatly folding-a-tree
Neatly folding-a-treeNeatly folding-a-tree
Neatly folding-a-tree
 
Light my-fuse
Light my-fuseLight my-fuse
Light my-fuse
 
Paranormal stats
Paranormal statsParanormal stats
Paranormal stats
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.
 
Putting some "logic" in LVM.
Putting some "logic" in LVM.Putting some "logic" in LVM.
Putting some "logic" in LVM.
 
Selenium sandwich-2
Selenium sandwich-2Selenium sandwich-2
Selenium sandwich-2
 
Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium
 
Docker perl build
Docker perl buildDocker perl build
Docker perl build
 
Designing net-aws-glacier
Designing net-aws-glacierDesigning net-aws-glacier
Designing net-aws-glacier
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6
 
Lies, Damn Lies, and Benchmarks
Lies, Damn Lies, and BenchmarksLies, Damn Lies, and Benchmarks
Lies, Damn Lies, and Benchmarks
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Getting Testy With Perl6