File: Test.html

package info (click to toggle)
perl-doc-html 5.26.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 39,400 kB
  • sloc: xml: 36; makefile: 7
file content (791 lines) | stat: -rw-r--r-- 58,103 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>Test - perldoc.perl.org</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta http-equiv="Content-Language" content="en-gb">
  <link rel="search" type="application/opensearchdescription+xml" title="Search perldoc.perl.org" href="/static/search.xml"/>
  <link href="static/css-20100830.css" rel="stylesheet" rev="stylesheet" type="text/css" media="screen">
  <link href="static/exploreperl.css" rel="stylesheet" rev="stylesheet" type="text/css">
</head>

<body onLoad="perldoc.startup();" onPageShow="if (event.persisted) perldoc.startup();">
    <div id="page">
      
      <div id="header">
	<div id="homepage_link">
	  <a href="index.html"></a>
	</div>
	<div id="strapline">
	  Perl Programming Documentation
	</div>
	<div id="download_link" class="download">
	  <a href="http://www.perl.org/get.html">Download Perl</a>
	</div>
	<div id="explore_link" class="download">
	  <a id="explore_anchor" href="#">Explore</a>
	</div>
      </div>
      
      <div id="body">
        <div id="left_column">
          <div class="side_group">
            
	    <div class="side_panel doc_panel">
              <p>Manual</p>
              <ul>
                <li><a href="index-overview.html">Overview</a>
                <li><a href="index-tutorials.html">Tutorials</a>
                <li><a href="index-faq.html">FAQs</a>
                <li><a href="index-history.html">History / Changes</a>
                <li><a href="index-licence.html">License</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Reference</p>
              <ul>
                <li><a href="index-language.html">Language</a>
                <li><a href="index-functions.html">Functions</a>
                <li><a href="perlop.html">Operators</a>
                <li><a href="perlvar.html">Special Variables</a>
                <li><a href="index-pragmas.html">Pragmas</a>
                <li><a href="index-utilities.html">Utilities</a>
                <li><a href="index-internals.html">Internals</a>
                <li><a href="index-platforms.html">Platform Specific</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Modules</p>
              <ul>
		<li>
		
                
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		
                  
		
		
                    <a href="index-modules-A.html">A</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-B.html">B</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-C.html">C</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-D.html">D</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-E.html">E</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-F.html">F</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-G.html">G</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-H.html">H</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-I.html">I</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-L.html">L</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-M.html">M</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-N.html">N</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-O.html">O</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-P.html">P</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-S.html">S</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-T.html">T</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-U.html">U</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-X.html">X</a>
                    
                
              </ul>
            </div>
            
	      <div class="side_panel doc_panel">
		<p>Tools</p>
		<ul>
		  <li><a href="preferences.html">Preferences</a>
		</ul>
	      </div>
            
          </div>
        </div>
        <div id="centre_column">
          <div id="content_header">
            <div id="title_bar">
              <div id="page_name">
                <h1>Test</h1>
              </div>
              <div id="perl_version">
                Perl 5 version 26.0 documentation
              </div>
              <div class="page_links" id="page_links_top">
                <a href="#" onClick="toolbar.goToTop();return false;">Go to top</a>
		
              </div>
	      <div class="page_links" id="page_links_bottom">
		
                  <a href="#" id="page_index_toggle">Show page index</a> &bull;
		
                <a href="#" id="recent_pages_toggle">Show recent pages</a>		
	      </div>
	      <div id="search_form">
		<form action="search.html" method="GET" id="search">
		  <input type="text" name="q" id="search_box" alt="Search">
		</form>
	      </div>
            </div>
            <div id="breadcrumbs">
                
    <a href="index.html">Home</a> &gt;
    
      
        <a href="index-modules-T.html">Core modules (T)</a> &gt;
      
    
    Test
  

            </div>
          </div>
          <div id="content_body">
	    <!--[if lt IE 7]>
 <div class="noscript">
   <p>
     <strong>It looks like you're using Internet Explorer 6. This is a very old
     browser which does not offer full support for modern websites.</strong>
   </p>
   <p>
     Unfortunately this means that this website will not work on
     your computer.
   </p>
   <p>
     Don't miss out though! To view the site (and get a better experience from
     many other websites), simply upgrade to
     <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet
Explorer 8</a>
     or download an alternative browser such as
     <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>,
     <a href="http://www.apple.com/safari/download/">Safari</a>, or
     <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
   </p>
   <p>
     All of these browsers are free. If you're using a PC at work, you may
     need to contact your IT administrator.
   </p>
 </div>
<![endif]-->
	    <noscript>
	      <div class="noscript">
	      <p>
                <strong>Please note: Many features of this site require JavaScript. You appear to have JavaScript disabled,
	        or are running a non-JavaScript capable web browser.</strong>
	      </p>
	      <p>
		To get the best experience, please enable JavaScript or download a modern web browser such as <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet Explorer 8</a>, <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>, <a href="http://www.apple.com/safari/download/">Safari</a>, or <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
              </p>
	      </div>
	    </noscript>

	    <div id="recent_pages" class="hud_container">
	      <div id="recent_pages_header" class="hud_header">
		<div id="recent_pages_close" class="hud_close"><a href="#" onClick="recentPages.hide();return false;"></a></div>
		<div id="recent_pages_title" class="hud_title"><span class="hud_span_top">Recently read</span></div>
		<div id="recent_pages_topright" class="hud_topright"></div>
	      </div>
	      <div id="recent_pages_content" class="hud_content">
	      </div>
	      <div id="recent_pages_footer" class="hud_footer">
		<div id="recent_pages_bottomleft" class="hud_bottomleft"></div>
		<div id="recent_pages_bottom" class="hud_bottom"><span class="hud_span_bottom"></span></div>
		<div id="recent_pages_resize" class="hud_resize"></div>
	      </div>
	    </div>
  
	    <div id="from_search"></div>
            <h1>Test</h1>


  <!--    -->
<ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><li><a href="#QUICK-START-GUIDE">QUICK START GUIDE</a><ul><li><a href="#Functions">Functions</a></ul><li><a href="#TEST-TYPES">TEST TYPES</a><li><a href="#ONFAIL">ONFAIL</a><li><a href="#BUGS-and-CAVEATS">BUGS and CAVEATS</a><li><a href="#ENVIRONMENT">ENVIRONMENT</a><li><a href="#NOTE">NOTE</a><li><a href="#SEE-ALSO">SEE ALSO</a><li><a href="#AUTHOR">AUTHOR</a></ul><a name="NAME"></a><h1>NAME</h1>
<p>Test - provides a simple framework for writing test scripts</p>
<a name="SYNOPSIS"></a><h1>SYNOPSIS</h1>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">strict</span><span class="sc">;</span></li><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">Test</span><span class="sc">;</span></li><li></li><li>  <span class="c"># use a BEGIN block so we print our plan before MyModule is loaded</span></li><li>  BEGIN <span class="s">{</span> <span class="w">plan</span> <span class="w">tests</span> <span class="cm">=&gt;</span> <span class="n">14</span><span class="cm">,</span> <span class="w">todo</span> <span class="cm">=&gt;</span> <span class="s">[</span><span class="n">3</span><span class="cm">,</span><span class="n">4</span><span class="s">]</span> <span class="s">}</span></li><li></li><li>  <span class="c"># load your module...</span></li><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">MyModule</span><span class="sc">;</span></li><li></li><li>  <span class="c"># Helpful notes.  All note-lines must start with a &quot;#&quot;.</span></li><li>  <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;# I&#39;m testing MyModule version $MyModule::VERSION\n&quot;</span><span class="sc">;</span></li><li></li><li>  <span class="i">ok</span><span class="s">(</span><span class="n">0</span><span class="s">)</span><span class="sc">;</span> <span class="c"># failure</span></li><li>  <span class="i">ok</span><span class="s">(</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span> <span class="c"># success</span></li><li></li><li>  <span class="i">ok</span><span class="s">(</span><span class="n">0</span><span class="s">)</span><span class="sc">;</span> <span class="c"># ok, expected failure (see todo list, above)</span></li><li>  <span class="i">ok</span><span class="s">(</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span> <span class="c"># surprise success!</span></li><li></li><li>  <span class="i">ok</span><span class="s">(</span><span class="n">0</span><span class="cm">,</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span>             <span class="c"># failure: &#39;0&#39; ne &#39;1&#39;</span></li><li>  <span class="i">ok</span><span class="s">(</span><span class="q">&#39;broke&#39;</span><span class="cm">,</span><span class="q">&#39;fixed&#39;</span><span class="s">)</span><span class="sc">;</span> <span class="c"># failure: &#39;broke&#39; ne &#39;fixed&#39;</span></li><li>  <span class="i">ok</span><span class="s">(</span><span class="q">&#39;fixed&#39;</span><span class="cm">,</span><span class="q">&#39;fixed&#39;</span><span class="s">)</span><span class="sc">;</span> <span class="c"># success: &#39;fixed&#39; eq &#39;fixed&#39;</span></li><li>  <span class="i">ok</span><span class="s">(</span><span class="q">&#39;fixed&#39;</span><span class="cm">,</span><span class="q">qr/x/</span><span class="s">)</span><span class="sc">;</span>   <span class="c"># success: &#39;fixed&#39; =~ qr/x/</span></li><li></li><li>  <span class="i">ok</span><span class="s">(</span><a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span> <span class="n">1</span>+<span class="n">1</span> <span class="s">}</span><span class="cm">,</span> <span class="n">2</span><span class="s">)</span><span class="sc">;</span>  <span class="c"># success: &#39;2&#39; eq &#39;2&#39;</span></li><li>  <span class="i">ok</span><span class="s">(</span><a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span> <span class="n">1</span>+<span class="n">1</span> <span class="s">}</span><span class="cm">,</span> <span class="n">3</span><span class="s">)</span><span class="sc">;</span>  <span class="c"># failure: &#39;2&#39; ne &#39;3&#39;</span></li><li></li><li>  <a class="l_k" href="functions/my.html">my</a> <span class="i">@list</span> = <span class="s">(</span><span class="n">0</span><span class="cm">,</span><span class="n">0</span><span class="s">)</span><span class="sc">;</span></li><li>  <span class="w">ok</span> <span class="i">@list</span><span class="cm">,</span> <span class="n">3</span><span class="cm">,</span> <span class="q">&quot;\@list=&quot;</span>.<a class="l_k" href="functions/join.html">join</a><span class="s">(</span><span class="q">&#39;,&#39;</span><span class="cm">,</span><span class="i">@list</span><span class="s">)</span><span class="sc">;</span>      <span class="c">#extra notes</span></li><li>  <span class="w">ok</span> <span class="q">&#39;segmentation fault&#39;</span><span class="cm">,</span> <span class="q">&#39;/(?i)success/&#39;</span><span class="sc">;</span>    <span class="c">#regex match</span></li><li></li><li>  <span class="i">skip</span><span class="s">(</span></li><li>    <span class="i">$^O</span> =~ <span class="q">m/MSWin/</span> ? <span class="q">&quot;Skip if MSWin&quot;</span> <span class="co">:</span> <span class="n">0</span><span class="cm">,</span>  <span class="c"># whether to skip</span></li><li>    <span class="i">$foo</span><span class="cm">,</span> <span class="i">$bar</span>  <span class="c"># arguments just like for ok(...)</span></li><li>  <span class="s">)</span><span class="sc">;</span></li><li>  <span class="i">skip</span><span class="s">(</span></li><li>    <span class="i">$^O</span> =~ <span class="q">m/MSWin/</span> ? <span class="n">0</span> <span class="co">:</span> <span class="q">&quot;Skip unless MSWin&quot;</span><span class="cm">,</span>  <span class="c"># whether to skip</span></li><li>    <span class="i">$foo</span><span class="cm">,</span> <span class="i">$bar</span>  <span class="c"># arguments just like for ok(...)</span></li><li>  <span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="DESCRIPTION"></a><h1>DESCRIPTION</h1>
<p>This module simplifies the task of writing test files for Perl modules,
such that their output is in the format that
<a href="Test/Harness.html">Test::Harness</a> expects to see.</p>
<a name="QUICK-START-GUIDE"></a><h1>QUICK START GUIDE</h1>
<p>To write a test for your new (and probably not even done) module, create
a new file called <i>t/test.t</i> (in a new <i>t</i> directory). If you have
multiple test files, to test the "foo", "bar", and "baz" feature sets,
then feel free to call your files <i>t/foo.t</i>, <i>t/bar.t</i>, and
<i>t/baz.t</i></p>
<a name="Functions"></a><h2>Functions</h2>
<p>This module defines three public functions, <code class="inline"><span class="i">plan</span><span class="s">(</span>...<span class="s">)</span></code>
, <code class="inline"><span class="i">ok</span><span class="s">(</span>...<span class="s">)</span></code>
,
and <code class="inline"><span class="i">skip</span><span class="s">(</span>...<span class="s">)</span></code>
.  By default, all three are exported by
the <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">Test</span><span class="sc">;</span></code>
 statement.</p>
<ul>
<li><a name="plan(...)"></a><b><code class="inline"><span class="i">plan</span><span class="s">(</span>...<span class="s">)</span></code>
</b>
<pre class="verbatim"><ol><li>     BEGIN <span class="s">{</span> <span class="w">plan</span> <span class="i">%theplan</span><span class="sc">;</span> <span class="s">}</span></li></ol></pre><p>This should be the first thing you call in your test script.  It
declares your testing plan, how many there will be, if any of them
should be allowed to fail, and so on.</p>
<p>Typical usage is just:</p>
<pre class="verbatim"><ol><li>     <a class="l_k" href="functions/use.html">use</a> <span class="w">Test</span><span class="sc">;</span></li><li>     BEGIN <span class="s">{</span> <span class="w">plan</span> <span class="w">tests</span> <span class="cm">=&gt;</span> <span class="n">23</span> <span class="s">}</span></li></ol></pre><p>These are the things that you can put in the parameters to plan:</p>
<ul>
<li><a name="tests-%3d%3e-_number_"></a><b><code class="inline">tests =&gt; <i>number</i></code></b>
<p>The number of tests in your script.
This means all ok() and skip() calls.</p>
</li>
<li><a name="todo-%3d%3e-%5b_1%2c5%2c14_%5d"></a><b><code class="inline">todo =&gt; [<i>1,5,14</i>]</code></b>
<p>A reference to a list of tests which are allowed to fail.
See <a href="#TODO-TESTS">TODO TESTS</a>.</p>
</li>
<li><a name="onfail-%3d%3e-sub-%7b-...-%7d"></a><b><code class="inline"><span class="w">onfail</span> <span class="cm">=&gt;</span> <a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span> ... <span class="s">}</span></code>
</b>
</li>
<li><a name="onfail-%3d%3e-%5c%26some_sub"></a><b><code class="inline"><span class="w">onfail</span> <span class="cm">=&gt;</span> \<span class="i">&amp;some_sub</span></code>
</b>
<p>A subroutine reference to be run at the end of the test script, if
any of the tests fail.  See <a href="#ONFAIL">ONFAIL</a>.</p>
</li>
</ul>
<p>You must call <code class="inline"><span class="i">plan</span><span class="s">(</span>...<span class="s">)</span></code>
 once and only once.  You should call it
in a <code class="inline">BEGIN <span class="s">{</span>...<span class="s">}</span></code>
 block, like so:</p>
<pre class="verbatim"><ol><li>     BEGIN <span class="s">{</span> <span class="w">plan</span> <span class="w">tests</span> <span class="cm">=&gt;</span> <span class="n">23</span> <span class="s">}</span></li></ol></pre></li>
<li><a name="ok(...)"></a><b><code class="inline"><span class="i">ok</span><span class="s">(</span>...<span class="s">)</span></code>
</b>
<pre class="verbatim"><ol><li>  <span class="i">ok</span><span class="s">(</span><span class="n">1</span> + <span class="n">1</span> == <span class="n">2</span><span class="s">)</span><span class="sc">;</span></li><li>  <span class="i">ok</span><span class="s">(</span><span class="i">$have</span><span class="cm">,</span> <span class="i">$expect</span><span class="s">)</span><span class="sc">;</span></li><li>  <span class="i">ok</span><span class="s">(</span><span class="i">$have</span><span class="cm">,</span> <span class="i">$expect</span><span class="cm">,</span> <span class="i">$diagnostics</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>This function is the reason for <code class="inline"><span class="w">Test</span></code>
's existence.  It's
the basic function that
handles printing "<code class="inline"><span class="w">ok</span></code>
" or "<code class="inline">not <span class="w">ok</span></code>
", along with the
current test number.  (That's what <code class="inline"><span class="w">Test::Harness</span></code>
 wants to see.)</p>
<p>In its most basic usage, <code class="inline"><span class="i">ok</span><span class="s">(</span>...<span class="s">)</span></code>
 simply takes a single scalar
expression.  If its value is true, the test passes; if false,
the test fails.  Examples:</p>
<pre class="verbatim"><ol><li>    <span class="c"># Examples of ok(scalar)</span></li><li></li><li>    <span class="i">ok</span><span class="s">(</span> <span class="n">1</span> + <span class="n">1</span> == <span class="n">2</span> <span class="s">)</span><span class="sc">;</span>           <span class="c"># ok if 1 + 1 == 2</span></li><li>    <span class="i">ok</span><span class="s">(</span> <span class="i">$foo</span> =~ <span class="q">/bar/</span> <span class="s">)</span><span class="sc">;</span>        <span class="c"># ok if $foo contains &#39;bar&#39;</span></li><li>    <span class="i">ok</span><span class="s">(</span> <span class="i">baz</span><span class="s">(</span><span class="i">$x</span> + <span class="i">$y</span><span class="s">)</span> <a class="l_k" href="functions/eq.html">eq</a> <span class="q">&#39;Armondo&#39;</span> <span class="s">)</span><span class="sc">;</span>    <span class="c"># ok if baz($x + $y) returns</span></li><li>                                        <span class="c"># &#39;Armondo&#39;</span></li><li>    <span class="i">ok</span><span class="s">(</span> <span class="i">@a</span> == <span class="i">@b</span> <span class="s">)</span><span class="sc">;</span>             <span class="c"># ok if @a and @b are the same</span></li><li>                                <span class="c"># length</span></li></ol></pre><p>The expression is evaluated in scalar context.  So the following will
work:</p>
<pre class="verbatim"><ol><li>    <span class="i">ok</span><span class="s">(</span> <span class="i">@stuff</span> <span class="s">)</span><span class="sc">;</span>                       <span class="c"># ok if @stuff has any</span></li><li>                                        <span class="c"># elements</span></li><li>    <span class="i">ok</span><span class="s">(</span> !<a class="l_k" href="functions/grep.html">grep</a> !<a class="l_k" href="functions/defined.html">defined</a> <span class="i">$_</span><span class="cm">,</span> <span class="i">@stuff</span> <span class="s">)</span><span class="sc">;</span>    <span class="c"># ok if everything in @stuff</span></li><li>                                        <span class="c"># is defined.</span></li></ol></pre><p>A special case is if the expression is a subroutine reference (in either
<code class="inline"><a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span>...<span class="s">}</span></code>
 syntax or <code class="inline">\<span class="i">&amp;foo</span></code>
 syntax).  In
that case, it is executed and its value (true or false) determines if
the test passes or fails.  For example,</p>
<pre class="verbatim"><ol><li>    <span class="i">ok</span><span class="s">(</span> <a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span>   <span class="c"># See whether sleep works at least passably</span></li><li>      <a class="l_k" href="functions/my.html">my</a> <span class="i">$start_time</span> = <a class="l_k" href="functions/time.html">time</a><span class="sc">;</span></li><li>      <a class="l_k" href="functions/sleep.html">sleep</a> <span class="n">5</span><span class="sc">;</span></li><li>      <a class="l_k" href="functions/time.html">time</a><span class="s">(</span><span class="s">)</span> - <span class="i">$start_time</span>  &gt;= <span class="n">4</span></li><li>    <span class="s">}</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>In its two-argument form, <code class="inline">ok(<i>arg1</i>, <i>arg2</i>)</code> compares the two
scalar values to see if they match.  They match if both are undefined,
or if <i>arg2</i> is a regex that matches <i>arg1</i>, or if they compare equal
with <code class="inline">eq</code>
.</p>
<pre class="verbatim"><ol><li>    <span class="c"># Example of ok(scalar, scalar)</span></li><li></li><li>    <span class="i">ok</span><span class="s">(</span> <span class="q">&quot;this&quot;</span><span class="cm">,</span> <span class="q">&quot;that&quot;</span> <span class="s">)</span><span class="sc">;</span>               <span class="c"># not ok, &#39;this&#39; ne &#39;that&#39;</span></li><li>    <span class="i">ok</span><span class="s">(</span> <span class="q">&quot;&quot;</span><span class="cm">,</span> <a class="l_k" href="functions/undef.html">undef</a> <span class="s">)</span><span class="sc">;</span>                    <span class="c"># not ok, &quot;&quot; is defined</span></li></ol></pre><p>The second argument is considered a regex if it is either a regex
object or a string that looks like a regex.  Regex objects are
constructed with the qr// operator in recent versions of perl.  A
string is considered to look like a regex if its first and last
characters are "/", or if the first character is "m"
and its second and last characters are both the
same non-alphanumeric non-whitespace character.  These regexp</p>
<p>Regex examples:</p>
<pre class="verbatim"><ol><li>    ok( 'JaffO', '/Jaff/' );    # ok, 'JaffO' =~ /Jaff/</li><li>    ok( 'JaffO', 'm|Jaff|' );   # ok, 'JaffO' =~ m|Jaff|</li><li>    ok( 'JaffO', qr/Jaff/ );    # ok, 'JaffO' =~ qr/Jaff/;</li><li>    ok( 'JaffO', '/(?i)jaff/ ); # ok, 'JaffO' =~ /jaff/i;</li></ol></pre><p>If either (or both!) is a subroutine reference, it is run and used
as the value for comparing.  For example:</p>
<pre class="verbatim"><ol><li>    <span class="w">ok</span> <a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span></li><li>        <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">OUT</span><span class="cm">,</span> <span class="q">&#39;&gt;&#39;</span><span class="cm">,</span> <span class="q">&#39;x.dat&#39;</span><span class="s">)</span> || <a class="l_k" href="functions/die.html">die</a> <span class="i">$!</span><span class="sc">;</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <span class="i">OUT</span> <span class="q">&quot;\x{e000}&quot;</span><span class="sc">;</span></li><li>        <a class="l_k" href="functions/close.html">close</a> <span class="w">OUT</span><span class="sc">;</span></li><li>        <a class="l_k" href="functions/my.html">my</a> <span class="i">$bytecount</span> = -s <span class="q">&#39;x.dat&#39;</span><span class="sc">;</span></li><li>        <a class="l_k" href="functions/unlink.html">unlink</a> <span class="q">&#39;x.dat&#39;</span> <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/warn.html">warn</a> <span class="q">&quot;Can&#39;t unlink : $!&quot;</span><span class="sc">;</span></li><li>        <a class="l_k" href="functions/return.html">return</a> <span class="i">$bytecount</span><span class="sc">;</span></li><li>      <span class="s">}</span><span class="cm">,</span></li><li>      <span class="n">4</span></li><li>    <span class="sc">;</span></li></ol></pre><p>The above test passes two values to <code class="inline"><span class="i">ok</span><span class="s">(</span><span class="w">arg1</span><span class="cm">,</span> <span class="w">arg2</span><span class="s">)</span></code>
 -- the first 
a coderef, and the second is the number 4.  Before <code class="inline"><span class="w">ok</span></code>
 compares them,
it calls the coderef, and uses its return value as the real value of
this parameter. Assuming that <code class="inline"><span class="i">$bytecount</span></code>
 returns 4, <code class="inline"><span class="w">ok</span></code>
 ends up
testing <code class="inline"><span class="n">4</span> eq <span class="n">4</span></code>
.  Since that's true, this test passes.</p>
<p>Finally, you can append an optional third argument, in
<code class="inline">ok(<i>arg1</i>,<i>arg2</i>, <i>note</i>)</code>, where <i>note</i> is a string value that
will be printed if the test fails.  This should be some useful
information about the test, pertaining to why it failed, and/or
a description of the test.  For example:</p>
<pre class="verbatim"><ol><li>    <span class="i">ok</span><span class="s">(</span> <a class="l_k" href="functions/grep.html">grep</a><span class="s">(</span><span class="i">$_</span> eq <span class="q">&#39;something unique&#39;</span><span class="cm">,</span> <span class="i">@stuff</span><span class="s">)</span><span class="cm">,</span> <span class="n">1</span><span class="cm">,</span></li><li>        <span class="q">&quot;Something that should be unique isn&#39;t!\n&quot;</span>.</li><li>        <span class="q">&#39;@stuff = &#39;</span>.<a class="l_k" href="functions/join.html">join</a> <span class="q">&#39;, &#39;</span><span class="cm">,</span> <span class="i">@stuff</span></li><li>      <span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Unfortunately, a note cannot be used with the single argument
style of <code class="inline"><span class="i">ok</span><span class="s">(</span><span class="s">)</span></code>
.  That is, if you try <code class="inline">ok(<i>arg1</i>, <i>note</i>)</code>, then
<code class="inline"><span class="w">Test</span></code>
 will interpret this as <code class="inline">ok(<i>arg1</i>, <i>arg2</i>)</code>, and probably
end up testing <code class="inline"><i>arg1</i> eq <i>arg2</i></code> -- and that's not what you want!</p>
<p>All of the above special cases can occasionally cause some
problems.  See <a href="#BUGS-and-CAVEATS">BUGS and CAVEATS</a>.</p>
</li>
<li><a name="skip(_skip_if_true_%2c-_args..._)"></a><b><code class="inline">skip(<i>skip_if_true</i>, <i>args...</i>)</code></b>
<p>This is used for tests that under some conditions can be skipped.  It's
basically equivalent to:</p>
<pre class="verbatim"><ol><li>  if<span class="s">(</span> <span class="i">$skip_if_true</span> <span class="s">)</span> <span class="s">{</span></li><li>    <span class="i">ok</span><span class="s">(</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span></li><li>  <span class="s">}</span> else <span class="s">{</span></li><li>    <span class="i">ok</span><span class="s">(</span> <span class="w">args</span>... <span class="s">)</span><span class="sc">;</span></li><li>  <span class="s">}</span></li></ol></pre><p>...except that the <code class="inline"><span class="i">ok</span><span class="s">(</span><span class="n">1</span><span class="s">)</span></code>
 emits not just "<code class="inline">ok <i>testnum</i></code>" but
actually "<code class="inline">ok <i>testnum</i> # <i>skip_if_true_value</i></code>".</p>
<p>The arguments after the <i>skip_if_true</i> are what is fed to <code class="inline"><span class="i">ok</span><span class="s">(</span>...<span class="s">)</span></code>
 if
this test isn't skipped.</p>
<p>Example usage:</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/my.html">my</a> <span class="i">$if_MSWin</span> =</li><li>    <span class="i">$^O</span> =~ <span class="q">m/MSWin/</span> ? <span class="q">&#39;Skip if under MSWin&#39;</span> <span class="co">:</span> <span class="q">&#39;&#39;</span><span class="sc">;</span></li><li></li><li>  <span class="c"># A test to be skipped if under MSWin (i.e., run except under</span></li><li>  <span class="c"># MSWin)</span></li><li>  <span class="i">skip</span><span class="s">(</span><span class="i">$if_MSWin</span><span class="cm">,</span> <span class="i">thing</span><span class="s">(</span><span class="i">$foo</span><span class="s">)</span><span class="cm">,</span> <span class="i">thing</span><span class="s">(</span><span class="i">$bar</span><span class="s">)</span> <span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Or, going the other way:</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/my.html">my</a> <span class="i">$unless_MSWin</span> =</li><li>    <span class="i">$^O</span> =~ <span class="q">m/MSWin/</span> ? <span class="q">&#39;&#39;</span> <span class="co">:</span> <span class="q">&#39;Skip unless under MSWin&#39;</span><span class="sc">;</span></li><li></li><li>  <span class="c"># A test to be skipped unless under MSWin (i.e., run only under</span></li><li>  <span class="c"># MSWin)</span></li><li>  <span class="i">skip</span><span class="s">(</span><span class="i">$unless_MSWin</span><span class="cm">,</span> <span class="i">thing</span><span class="s">(</span><span class="i">$foo</span><span class="s">)</span><span class="cm">,</span> <span class="i">thing</span><span class="s">(</span><span class="i">$bar</span><span class="s">)</span> <span class="s">)</span><span class="sc">;</span></li></ol></pre><p>The tricky thing to remember is that the first parameter is true if
you want to <i>skip</i> the test, not <i>run</i> it; and it also doubles as a
note about why it's being skipped. So in the first codeblock above, read
the code as "skip if MSWin -- (otherwise) test whether <code class="inline"><span class="i">thing</span><span class="s">(</span><span class="i">$foo</span><span class="s">)</span></code>
 is
<code class="inline"><span class="i">thing</span><span class="s">(</span><span class="i">$bar</span><span class="s">)</span></code>
" or for the second case, "skip unless MSWin...".</p>
<p>Also, when your <i>skip_if_reason</i> string is true, it really should (for
backwards compatibility with older Test.pm versions) start with the
string "Skip", as shown in the above examples.</p>
<p>Note that in the above cases, <code class="inline"><span class="i">thing</span><span class="s">(</span><span class="i">$foo</span><span class="s">)</span></code>
 and <code class="inline"><span class="i">thing</span><span class="s">(</span><span class="i">$bar</span><span class="s">)</span></code>

<i>are</i> evaluated -- but as long as the <code class="inline"><span class="w">skip_if_true</span></code>
 is true,
then we <code class="inline"><span class="i">skip</span><span class="s">(</span>...<span class="s">)</span></code>
 just tosses out their value (i.e., not
bothering to treat them like values to <code class="inline"><span class="i">ok</span><span class="s">(</span>...<span class="s">)</span></code>
.  But if
you need to <i>not</i> eval the arguments when skipping the
test, use
this format:</p>
<pre class="verbatim"><ol><li>  <span class="i">skip</span><span class="s">(</span> <span class="i">$unless_MSWin</span><span class="cm">,</span></li><li>    <a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span></li><li>      <span class="c"># This code returns true if the test passes.</span></li><li>      <span class="c"># (But it doesn&#39;t even get called if the test is skipped.)</span></li><li>      <span class="i">thing</span><span class="s">(</span><span class="i">$foo</span><span class="s">)</span> eq <span class="i">thing</span><span class="s">(</span><span class="i">$bar</span><span class="s">)</span></li><li>    <span class="s">}</span></li><li>  <span class="s">)</span><span class="sc">;</span></li></ol></pre><p>or even this, which is basically equivalent:</p>
<pre class="verbatim"><ol><li>  <span class="i">skip</span><span class="s">(</span> <span class="i">$unless_MSWin</span><span class="cm">,</span></li><li>    <a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span> <span class="i">thing</span><span class="s">(</span><span class="i">$foo</span><span class="s">)</span> <span class="s">}</span><span class="cm">,</span> <a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span> <span class="i">thing</span><span class="s">(</span><span class="i">$bar</span><span class="s">)</span> <span class="s">}</span></li><li>  <span class="s">)</span><span class="sc">;</span></li></ol></pre><p>That is, both are like this:</p>
<pre class="verbatim"><ol><li>  if<span class="s">(</span> <span class="i">$unless_MSWin</span> <span class="s">)</span> <span class="s">{</span></li><li>    <span class="i">ok</span><span class="s">(</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span>  <span class="c"># but it actually appends &quot;# $unless_MSWin&quot;</span></li><li>            <span class="c">#  so that Test::Harness can tell it&#39;s a skip</span></li><li>  <span class="s">}</span> else <span class="s">{</span></li><li>    <span class="c"># Not skipping, so actually call and evaluate...</span></li><li>    <span class="i">ok</span><span class="s">(</span> <a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span> <span class="i">thing</span><span class="s">(</span><span class="i">$foo</span><span class="s">)</span> <span class="s">}</span><span class="cm">,</span> <a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span> <span class="i">thing</span><span class="s">(</span><span class="i">$bar</span><span class="s">)</span> <span class="s">}</span> <span class="s">)</span><span class="sc">;</span></li><li>  <span class="s">}</span></li></ol></pre></li>
</ul>
<a name="TEST-TYPES"></a><h1>TEST TYPES</h1>
<ul>
<li><a name="*-NORMAL-TESTS"></a><b>NORMAL TESTS</b>
<p>These tests are expected to succeed.  Usually, most or all of your tests
are in this category.  If a normal test doesn't succeed, then that
means that something is <i>wrong</i>.</p>
</li>
<li><a name="*-SKIPPED-TESTS"></a><b>SKIPPED TESTS</b>
<p>The <code class="inline"><span class="i">skip</span><span class="s">(</span>...<span class="s">)</span></code>
 function is for tests that might or might not be
possible to run, depending
on the availability of platform-specific features.  The first argument
should evaluate to true (think "yes, please skip") if the required
feature is <i>not</i> available.  After the first argument, <code class="inline"><span class="i">skip</span><span class="s">(</span>...<span class="s">)</span></code>
 works
exactly the same way as <code class="inline"><span class="i">ok</span><span class="s">(</span>...<span class="s">)</span></code>
 does.</p>
</li>
<li><a name="*-TODO-TESTS"></a><b>TODO TESTS</b>
<p>TODO tests are designed for maintaining an <b>executable TODO list</b>.
These tests are <i>expected to fail.</i>  If a TODO test does succeed,
then the feature in question shouldn't be on the TODO list, now
should it?</p>
<p>Packages should NOT be released with succeeding TODO tests.  As soon
as a TODO test starts working, it should be promoted to a normal test,
and the newly working feature should be documented in the release
notes or in the change log.</p>
</li>
</ul>
<a name="ONFAIL"></a><h1>ONFAIL</h1>
<pre class="verbatim"><ol><li>  BEGIN <span class="s">{</span> <span class="w">plan</span> <span class="w">test</span> <span class="cm">=&gt;</span> <span class="n">4</span><span class="cm">,</span> <span class="w">onfail</span> <span class="cm">=&gt;</span> <a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span> <a class="l_k" href="functions/warn.html">warn</a> <span class="q">&quot;CALL 911!&quot;</span> <span class="s">}</span> <span class="s">}</span></li></ol></pre><p>Although test failures should be enough, extra diagnostics can be
triggered at the end of a test run.  <code class="inline"><span class="w">onfail</span></code>
 is passed an array ref
of hash refs that describe each test failure.  Each hash will contain
at least the following fields: <code class="inline"><a class="l_k" href="functions/package.html">package</a></code>, <code class="inline"><span class="w">repetition</span></code>
, and
<code class="inline"><span class="w">result</span></code>
.  (You shouldn't rely on any other fields being present.)  If the test
had an expected value or a diagnostic (or "note") string, these will also be
included.</p>
<p>The <i>optional</i> <code class="inline"><span class="w">onfail</span></code>
 hook might be used simply to print out the
version of your package and/or how to report problems.  It might also
be used to generate extremely sophisticated diagnostics for a
particularly bizarre test failure.  However it's not a panacea.  Core
dumps or other unrecoverable errors prevent the <code class="inline"><span class="w">onfail</span></code>
 hook from
running.  (It is run inside an <code class="inline">END</code>
 block.)  Besides, <code class="inline"><span class="w">onfail</span></code>
 is
probably over-kill in most cases.  (Your test code should be simpler
than the code it is testing, yes?)</p>
<a name="BUGS-and-CAVEATS"></a><h1>BUGS and CAVEATS</h1>
<ul>
<li>
<p><code class="inline"><span class="i">ok</span><span class="s">(</span>...<span class="s">)</span></code>
's special handing of strings which look like they might be
regexes can also cause unexpected behavior.  An innocent:</p>
<pre class="verbatim"><ol><li>    <span class="i">ok</span><span class="s">(</span> <span class="i">$fileglob</span><span class="cm">,</span> <span class="q">&#39;/path/to/some/*stuff/&#39;</span> <span class="s">)</span><span class="sc">;</span></li></ol></pre><p>will fail, since Test.pm considers the second argument to be a regex!
The best bet is to use the one-argument form:</p>
<pre class="verbatim"><ol><li>    <span class="i">ok</span><span class="s">(</span> <span class="i">$fileglob</span> eq <span class="q">&#39;/path/to/some/*stuff/&#39;</span> <span class="s">)</span><span class="sc">;</span></li></ol></pre></li>
<li>
<p><code class="inline"><span class="i">ok</span><span class="s">(</span>...<span class="s">)</span></code>
's use of string <code class="inline">eq</code>
 can sometimes cause odd problems
when comparing
numbers, especially if you're casting a string to a number:</p>
<pre class="verbatim"><ol><li>    <span class="i">$foo</span> = <span class="q">&quot;1.0&quot;</span><span class="sc">;</span></li><li>    <span class="i">ok</span><span class="s">(</span> <span class="i">$foo</span><span class="cm">,</span> <span class="n">1</span> <span class="s">)</span><span class="sc">;</span>      <span class="c"># not ok, &quot;1.0&quot; ne 1</span></li></ol></pre><p>Your best bet is to use the single argument form:</p>
<pre class="verbatim"><ol><li>    <span class="i">ok</span><span class="s">(</span> <span class="i">$foo</span> == <span class="n">1</span> <span class="s">)</span><span class="sc">;</span>    <span class="c"># ok &quot;1.0&quot; == 1</span></li></ol></pre></li>
<li>
<p>As you may have inferred from the above documentation and examples,
<code class="inline"><span class="w">ok</span></code>
's prototype is <code class="inline">($;$$)</code> (and, incidentally, <code class="inline"><span class="w">skip</span></code>
's is
<code class="inline">($;$$$)</code>). This means, for example, that you can do <code class="inline"><span class="w">ok</span> <span class="i">@foo</span><span class="cm">,</span> <span class="i">@bar</span></code>

to compare the <i>size</i> of the two arrays. But don't be fooled into
thinking that <code class="inline"><span class="w">ok</span> <span class="i">@foo</span><span class="cm">,</span> <span class="i">@bar</span></code>
 means a comparison of the contents of two
arrays -- you're comparing <i>just</i> the number of elements of each. It's
so easy to make that mistake in reading <code class="inline"><span class="w">ok</span> <span class="i">@foo</span><span class="cm">,</span> <span class="i">@bar</span></code>
 that you might
want to be very explicit about it, and instead write <code class="inline"><span class="w">ok</span> <a class="l_k" href="functions/scalar.html">scalar</a><span class="s">(</span><span class="i">@foo</span><span class="s">)</span><span class="cm">,</span>
<a class="l_k" href="functions/scalar.html">scalar</a><span class="s">(</span><span class="i">@bar</span><span class="s">)</span></code>
.</p>
</li>
<li>
<p>This almost definitely doesn't do what you expect:</p>
<pre class="verbatim"><ol><li>     <span class="w">ok</span> <span class="i">$thingy</span><span class="i">-&gt;can</span><span class="s">(</span><span class="q">&#39;some_method&#39;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Why?  Because <code class="inline"><span class="w">can</span></code>
 returns a coderef to mean "yes it can (and the
method is this...)", and then <code class="inline"><span class="w">ok</span></code>
 sees a coderef and thinks you're
passing a function that you want it to call and consider the truth of
the result of!  I.e., just like:</p>
<pre class="verbatim"><ol><li>     <span class="w">ok</span> <span class="i">$thingy</span><span class="i">-&gt;can</span><span class="s">(</span><span class="q">&#39;some_method&#39;</span><span class="s">)</span>-&gt;<span class="s">(</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>What you probably want instead is this:</p>
<pre class="verbatim"><ol><li>     <span class="w">ok</span> <span class="i">$thingy</span><span class="i">-&gt;can</span><span class="s">(</span><span class="q">&#39;some_method&#39;</span><span class="s">)</span> &amp;&amp; <span class="n">1</span><span class="sc">;</span></li></ol></pre><p>If the <code class="inline"><span class="w">can</span></code>
 returns false, then that is passed to <code class="inline"><span class="w">ok</span></code>
.  If it
returns true, then the larger expression <code class="inline"><span class="i">$thingy</span><span class="i">-&gt;can</span><span class="s">(</span><span class="q">&#39;some_method&#39;</span><span class="s">)</span> &amp;&amp; <span class="n">1</span></code>
 returns 1, which <code class="inline"><span class="w">ok</span></code>
 sees as
a simple signal of success, as you would expect.</p>
</li>
<li>
<p>The syntax for <code class="inline"><span class="w">skip</span></code>
 is about the only way it can be, but it's still
quite confusing.  Just start with the above examples and you'll
be okay.</p>
<p>Moreover, users may expect this:</p>
<pre class="verbatim"><ol><li>  <span class="w">skip</span> <span class="i">$unless_mswin</span><span class="cm">,</span> <span class="i">foo</span><span class="s">(</span><span class="i">$bar</span><span class="s">)</span><span class="cm">,</span> <span class="i">baz</span><span class="s">(</span><span class="i">$quux</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>to not evaluate <code class="inline"><span class="i">foo</span><span class="s">(</span><span class="i">$bar</span><span class="s">)</span></code>
 and <code class="inline"><span class="i">baz</span><span class="s">(</span><span class="i">$quux</span><span class="s">)</span></code>
 when the test is being
skipped.  But in reality, they <i>are</i> evaluated, but <code class="inline"><span class="w">skip</span></code>
 just won't
bother comparing them if <code class="inline"><span class="i">$unless_mswin</span></code>
 is true.</p>
<p>You could do this:</p>
<pre class="verbatim"><ol><li>  <span class="w">skip</span> <span class="i">$unless_mswin</span><span class="cm">,</span> <a class="l_k" href="functions/sub.html">sub</a><span class="s">{</span><span class="i">foo</span><span class="s">(</span><span class="i">$bar</span><span class="s">)</span><span class="s">}</span><span class="cm">,</span> <a class="l_k" href="functions/sub.html">sub</a><span class="s">{</span><span class="i">baz</span><span class="s">(</span><span class="i">$quux</span><span class="s">)</span><span class="s">}</span><span class="sc">;</span></li></ol></pre><p>But that's not terribly pretty.  You may find it simpler or clearer in
the long run to just do things like this:</p>
<pre class="verbatim"><ol><li>  if<span class="s">(</span> <span class="i">$^O</span> =~ <span class="q">m/MSWin/</span> <span class="s">)</span> <span class="s">{</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;# Yay, we&#39;re under $^O\n&quot;</span><span class="sc">;</span></li><li>    <span class="w">ok</span> <span class="i">foo</span><span class="s">(</span><span class="i">$bar</span><span class="s">)</span><span class="cm">,</span> <span class="i">baz</span><span class="s">(</span><span class="i">$quux</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="w">ok</span> <span class="i">thing</span><span class="s">(</span><span class="i">$whatever</span><span class="s">)</span><span class="cm">,</span> <span class="i">baz</span><span class="s">(</span><span class="i">$stuff</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="w">ok</span> <span class="i">blorp</span><span class="s">(</span><span class="i">$quux</span><span class="cm">,</span> <span class="i">$whatever</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="w">ok</span> <span class="i">foo</span><span class="s">(</span><span class="i">$barzbarz</span><span class="s">)</span><span class="cm">,</span> <span class="i">thang</span><span class="s">(</span><span class="i">$quux</span><span class="s">)</span><span class="sc">;</span></li><li>  <span class="s">}</span> else <span class="s">{</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;# Feh, we&#39;re under $^O.  Watch me skip some tests...\n&quot;</span><span class="sc">;</span></li><li>    for<span class="s">(</span><span class="n">1</span> .. <span class="n">4</span><span class="s">)</span> <span class="s">{</span> <span class="w">skip</span> <span class="q">&quot;Skip unless under MSWin&quot;</span> <span class="s">}</span></li><li>  <span class="s">}</span></li></ol></pre><p>But be quite sure that <code class="inline"><span class="w">ok</span></code>
 is called exactly as many times in the
first block as <code class="inline"><span class="w">skip</span></code>
 is called in the second block.</p>
</li>
</ul>
<a name="ENVIRONMENT"></a><h1>ENVIRONMENT</h1>
<p>If <code class="inline"><span class="w">PERL_TEST_DIFF</span></code>
 environment variable is set, it will be used as a
command for comparing unexpected multiline results.  If you have GNU
diff installed, you might want to set <code class="inline"><span class="w">PERL_TEST_DIFF</span></code>
 to <code class="inline"><span class="w">diff</span> -u</code>
.
If you don't have a suitable program, you might install the
<code class="inline"><span class="w">Text::Diff</span></code>
 module and then set <code class="inline"><span class="w">PERL_TEST_DIFF</span></code>
 to be <code class="inline"><span class="w">perl</span>
-<span class="w">MText::Diff</span> -e <span class="q">&#39;print diff(@ARGV)&#39;</span></code>
.  If <code class="inline"><span class="w">PERL_TEST_DIFF</span></code>
 isn't set
but the <code class="inline"><span class="w">Algorithm::Diff</span></code>
 module is available, then it will be used
to show the differences in multiline results.</p>
<a name="NOTE"></a><h1>NOTE</h1>
<p>A past developer of this module once said that it was no longer being
actively developed.  However, rumors of its demise were greatly
exaggerated.  Feedback and suggestions are quite welcome.</p>
<p>Be aware that the main value of this module is its simplicity.  Note
that there are already more ambitious modules out there, such as
<a href="Test/More.html">Test::More</a> and <a href="http://search.cpan.org/perldoc/Test::Unit">Test::Unit</a>.</p>
<p>Some earlier versions of this module had docs with some confusing
typos in the description of <code class="inline"><span class="i">skip</span><span class="s">(</span>...<span class="s">)</span></code>
.</p>
<a name="SEE-ALSO"></a><h1>SEE ALSO</h1>
<p><a href="Test/Harness.html">Test::Harness</a></p>
<p><a href="Test/Simple.html">Test::Simple</a>, <a href="Test/More.html">Test::More</a>, <a href="http://search.cpan.org/perldoc/Devel::Cover">Devel::Cover</a></p>
<p><a href="Test/Builder.html">Test::Builder</a> for building your own testing library.</p>
<p><a href="http://search.cpan.org/perldoc/Test::Unit">Test::Unit</a> is an interesting XUnit-style testing library.</p>
<p><a href="http://search.cpan.org/perldoc/Test::Inline">Test::Inline</a> lets you embed tests in code.</p>
<a name="AUTHOR"></a><h1>AUTHOR</h1>
<p>Copyright (c) 1998-2000 Joshua Nathaniel Pritikin.</p>
<p>Copyright (c) 2001-2002 Michael G. Schwern.</p>
<p>Copyright (c) 2002-2004 Sean M. Burke.</p>
<p>Current maintainer: Jesse Vincent. &lt;jesse@bestpractical.com&gt;</p>
<p>This package is free software and is provided "as is" without express
or implied warranty.  It may be used, redistributed and/or modified
under the same terms as Perl itself.</p>




  <div id="page_index" class="hud_container">
    <div id="page_index_header" class="hud_header">
      <div id="page_index_close" class="hud_close"><a href="#" onClick="pageIndex.hide();return false;"></a></div>
      <div id="page_index_title" class="hud_title"><span class="hud_span_top">Page index</span></div>
      <div id="page_index_topright" class="hud_topright"></div>
    </div>
    <div id="page_index_content" class="hud_content">
      <ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><li><a href="#QUICK-START-GUIDE">QUICK START GUIDE</a><ul><li><a href="#Functions">Functions</a></ul><li><a href="#TEST-TYPES">TEST TYPES</a><li><a href="#ONFAIL">ONFAIL</a><li><a href="#BUGS-and-CAVEATS">BUGS and CAVEATS</a><li><a href="#ENVIRONMENT">ENVIRONMENT</a><li><a href="#NOTE">NOTE</a><li><a href="#SEE-ALSO">SEE ALSO</a><li><a href="#AUTHOR">AUTHOR</a></ul>
    </div>
    <div id="page_index_footer" class="hud_footer">
      <div id="page_index_bottomleft" class="hud_bottomleft"></div>
      <div id="page_index_bottom" class="hud_bottom"><span class="hud_span_bottom"></span></div>
      <div id="page_index_resize" class="hud_resize"></div>
    </div>
  </div>


	    &nbsp;
          </div>
          <div id="content_footer">
          </div>
        </div>
        <div class="clear"></div>
      </div>
      
    <div id="footer">
      <div id="footer_content">
        <div id="footer_strapline">
          perldoc.perl.org - Official documentation for the Perl programming language
        </div>
        <div id="footer_links">
          <div id="address">
            <p class="name">Contact details</p>
            <p class="address">
	      Site maintained by <a href="mailto:jj@jonallen.info">Jon Allen (JJ)</a><br>
	    </p>
            <p class="contact">
              Documentation maintained by the <a href="http://lists.cpan.org/showlist.cgi?name=perl5-porters">Perl 5 Porters</a>
            </p>
          </div>
          <ul class="f1">
            <li>Manual
              <ul class="f2">
                <li><a href="index-overview.html">Overview</a>
                <li><a href="index-tutorials.html">Tutorials</a>
                <li><a href="index-faq.html">FAQs</a>
                <li><a href="index-history.html">Changes</a>
              </ul>
            <li>Reference
              <ul class="f2">
                <li><a href="index-language.html">Language</a>
                <li><a href="index-functions.html">Functions</a>
                <li><a href="perlop.html">Operators</a>
                <li><a href="perlvar.html">Variables</a>
              </ul>
            <li>Modules
              <ul class="f2">
                <li><a href="index-modules-A.html">Modules</a>
                <li><a href="index-pragmas.html">Pragmas</a>
                <li><a href="index-utilities.html">Utilities</a>
              </ul>
            <li>Misc
              <ul class="f2">
                <li><a href="index-licence.html">License</a>
                <li><a href="index-internals.html">Internals</a>
                <li><a href="index-platforms.html">Platforms</a>
              </ul>          </ul>
          <div class="clear"></div>
        </div>
      </div>
      <div id="footer_end">
      </div>
    </div>
      
    </div>
      <script language="JavaScript" type="text/javascript" src="static/exploreperl.js"></script>
      <script language="JavaScript" src="static/combined-20100403.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
  perldoc.setPath(0);
  perldoc.pageName    = 'Test';
  perldoc.pageAddress = 'Test.html';
  perldoc.contentPage = 1;
  explorePerl.render();
  explorePerl.addEvents('explore_anchor');
</script>
    
  </body>
</html>