/
More.pod
2308 lines (1433 loc) · 54.2 KB
/
More.pod
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
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
=encoding euc-jp
=head1 NAME
=begin original
Test::More - yet another framework for writing test scripts
=end original
Test::More - テストを書くためのもう一つのフレームワーク
=head1 SYNOPSIS
use Test::More tests => 23;
# or
use Test::More skip_all => $reason;
# or
use Test::More; # see done_testing()
BEGIN { use_ok( 'Some::Module' ); }
require_ok( 'Some::Module' );
=begin original
# Various ways to say "ok"
ok($got eq $expected, $test_name);
=end original
# 「ok」と示すためのさまざまな方法
ok($got eq $expected, $test_name);
is ($got, $expected, $test_name);
isnt($got, $expected, $test_name);
=begin original
# Rather than print STDERR "# here's what went wrong\n"
diag("here's what went wrong");
=end original
# print STDERR "# here's what went wrong\n" とするよりも
diag("here's what went wrong");
like ($got, qr/expected/, $test_name);
unlike($got, qr/expected/, $test_name);
cmp_ok($got, '==', $expected, $test_name);
is_deeply($got_complex_structure, $expected_complex_structure, $test_name);
SKIP: {
skip $why, $how_many unless $have_some_feature;
ok( foo(), $test_name );
is( foo(42), 23, $test_name );
};
TODO: {
local $TODO = $why;
ok( foo(), $test_name );
is( foo(42), 23, $test_name );
};
can_ok($module, @methods);
isa_ok($object, $class);
pass($test_name);
fail($test_name);
BAIL_OUT($why);
# UNIMPLEMENTED!!!
my @status = Test::More::status;
=head1 DESCRIPTION
=begin original
B<STOP!> If you're just getting started writing tests, have a look at
L<Test::Simple> first. This is a drop in replacement for Test::Simple
which you can switch to once you get the hang of basic testing.
=end original
B<待った!>
もし、今初めて、テストを書こうとしているのなら、L<Test::Simple> をまず
見てください。
これは、一旦基本的なテストのコツを得れば、置き換え可能な
Test::Simple の差込式の置換物です。
=begin original
The purpose of this module is to provide a wide range of testing
utilities. Various ways to say "ok" with better diagnostics,
facilities to skip tests, test future features and compare complicated
data structures. While you can do almost anything with a simple
C<ok()> function, it doesn't provide good diagnostic output.
=end original
このモジュールの目的は、幅広いテストユーティリティを提供することです。
よりよい診断で「ok」と示す方法を用意したり、テストを簡単にスキップしたり、
将来的な実装をテストしたり、複雑なデータ構造を比較したりする様々な機能が
あります。
単純な C<ok()> 関数でほとんど全てのことが出来ますが、C<ok()> 関数は、良い
診断出力を提供しません。
=head2 I love it when a plan comes together
(計画が一緒に来るなら、それを大事にする)
=begin original
Before anything else, you need a testing plan. This basically declares
how many tests your script is going to run to protect against premature
failure.
=end original
他の何より前に、テストの計画が必要です。
スクリプトが行おうとしているテストがいくつであるかというこの基本的な宣言は、
時期尚早な失敗に対する保護になります。
=begin original
The preferred way to do this is to declare a plan when you C<use Test::More>.
=end original
この保護を行う好ましい方法は、C<use Test::More> を書く時に、計画を
宣言することです。
use Test::More tests => 23;
=begin original
There are cases when you will not know beforehand how many tests your
script is going to run. In this case, you can declare your tests at
the end.
=end original
スクリプトが行おうとしているテストがいくつあるかを事前に知らないような、まれな
ケースがあります。
こういうケースでは、最後にテストを宣言することができます。
use Test::More;
... run your tests ...
done_testing( $number_of_tests_run );
=begin original
Sometimes you really don't know how many tests were run, or it's too
difficult to calculate. In which case you can leave off
$number_of_tests_run.
=end original
いくつのテストが実行されるか本当に分からない時や、計算するのが大変な時に
使えます。
そのようなケースでは、$number_of_tests_run を省くこともできます。
=begin original
In some cases, you'll want to completely skip an entire testing script.
=end original
いくつかのケースでは、あるテストスクリプト全てを完全にスキップしたいでしょう。
use Test::More skip_all => $skip_reason;
=begin original
Your script will declare a skip with the reason why you skipped and
exit immediately with a zero (success). See L<Test::Harness> for
details.
=end original
スクリプトが、なぜスキップするのかの理由を宣言すると、即座に0(成功)で終了します。
詳細については L<Test::Harness> を参照してください。
=begin original
If you want to control what functions Test::More will export, you
have to use the 'import' option. For example, to import everything
but 'fail', you'd do:
=end original
Test::More がエクスポートする関数をコントロールしたければ、
'import' オプションを使う必要があります。
たとえば、'fail' を除いて、全てをインポートしたいなら、次のようにします:
use Test::More tests => 23, import => ['!fail'];
=begin original
Alternatively, you can use the plan() function. Useful for when you
have to calculate the number of tests.
=end original
代わりに、plan() 関数を使うことが出来ます。
テストの数を計算する必要があるときに有用です。
use Test::More;
plan tests => keys %Stuff * 3;
=begin original
or for deciding between running the tests at all:
=end original
または、テストを走らせている間に決めるためには:
use Test::More;
if( $^O eq 'MacOS' ) {
plan skip_all => 'Test irrelevant on MacOS';
}
else {
plan tests => 42;
}
=cut
=over 4
=item B<done_testing>
done_testing();
done_testing($number_of_tests);
=begin original
If you don't know how many tests you're going to run, you can issue
the plan when you're done running tests.
=end original
実行しようとしているテストがいくつかわからない場合、
テストの実行を終えたときに計画を発表することができます。
=begin original
$number_of_tests is the same as plan(), it's the number of tests you
expected to run. You can omit this, in which case the number of tests
you ran doesn't matter, just the fact that your tests ran to
conclusion.
=end original
$number_of_tests は、plan() と同じです; 実行しようとしているテストの数です。
これを省略することもできます; その場合、テストの数は問題にしません;
最後までテストが実行されたかを問題にします。
=begin original
This is safer than and replaces the "no_plan" plan.
=end original
"no_plan" な計画より安全で、"no_plan" を置き換えるものです。
=back
=cut
=head2 Test names
(テストの名前)
=begin original
By convention, each test is assigned a number in order. This is
largely done automatically for you. However, it's often very useful to
assign a name to each test. Which would you rather see:
=end original
便宜のために、それぞれのテストは、順番に番号が割り振られています。
これは、主に自動的に行われます。
ですが、テストに名前を割り当てると、とても有益なことがよくあります。
どちらがよいでしょうか:
ok 4
not ok 5
ok 6
=begin original
or
=end original
というのと、
ok 4 - basic multi-variable
not ok 5 - simple exponential
ok 6 - force == mass * acceleration
=begin original
The later gives you some idea of what failed. It also makes it easier
to find the test in your script, simply search for "simple
exponential".
=end original
後者は、何が失敗したかの手がかりを与えてくれます。
また、単に "simple exponential" を探すことで、
スクリプト中のテストを見つけやすくなります。
=begin original
All test functions take a name argument. It's optional, but highly
suggested that you use it.
=end original
全てのテストの関数は、名前を引数にとります。
これはオプションではありますが、使うことが強く推奨されています。
=head2 I'm ok, you're not ok.
(わたしは、OK 、あなたは、だめ)
=begin original
The basic purpose of this module is to print out either "ok #" or "not
ok #" depending on if a given test succeeded or failed. Everything
else is just gravy.
=end original
このモジュールの基本的な目的は、与えたテストが、成功したか、失敗したかで、
「ok 番号」か、「not ok 番号」のどちらかを出力することです。
他の全ては、ただのおまけです。
=begin original
All of the following print "ok" or "not ok" depending on if the test
succeeded or failed. They all also return true or false,
respectively.
=end original
この下に書いているものは全て、テストが成功したか失敗したかどうかによって、
「ok」か「not ok」を表示します。
それら全てはまた、それぞれ真か偽を返します。
=over 4
=item B<ok>
ok($got eq $expected, $test_name);
=begin original
This simply evaluates any expression (C<$got eq $expected> is just a
simple example) and uses that to determine if the test succeeded or
failed. A true expression passes, a false one fails. Very simple.
=end original
これは単純に、どんな式も評価します(C<$got eq $expected> は
ただの簡単な例です);
そして、それをテストが成功したかどうかを決めるのに使います。
真の式は合格し、偽の式は失敗です。
とても単純です。
=begin original
For example:
=end original
例えば:
ok( $exp{9} == 81, 'simple exponential' );
ok( Film->can('db_Main'), 'set_db()' );
ok( $p->tests == 4, 'saw tests' );
ok( !grep !defined $_, @items, 'items populated' );
=begin original
(Mnemonic: "This is ok.")
=end original
(覚えかた: "This is ok.")
=begin original
$test_name is a very short description of the test that will be printed
out. It makes it very easy to find a test in your script when it fails
and gives others an idea of your intentions. $test_name is optional,
but we B<very> strongly encourage its use.
=end original
$test_name は、実行時に出力される、とても短いテストの説明です。
これは、テストが失敗した場合に、スクリプト中のテストをとても
見つけやすくします;
そして、他の人に、あなたの意図する考えを伝えます。
$test_name はオプションですが、使うことが B<とても> 強く勧められています。
=begin original
Should an ok() fail, it will produce some diagnostics:
=end original
万一、ok() が失敗した場合、ちょっとした診断を提供します:
not ok 18 - sufficient mucus
# Failed test 'sufficient mucus'
# in foo.t at line 42.
=begin original
This is the same as Test::Simple's ok() routine.
=end original
これは、Test::Simple の C<ok()> ルーチンと同じです。
=item B<is>
=item B<isnt>
is ( $got, $expected, $test_name );
isnt( $got, $expected, $test_name );
=begin original
Similar to ok(), is() and isnt() compare their two arguments
with C<eq> and C<ne> respectively and use the result of that to
determine if the test succeeded or failed. So these:
=end original
ok() と is() と isnt() の類似点は、二つの引数をそれぞれ C<eq> と C<ne> で
比較し、その結果を使って、テストが成功したか、失敗したかを決めることです。
それで、これらは:
# Is the ultimate answer 42?
is( ultimate_answer(), 42, "Meaning of Life" );
# $foo isn't empty
isnt( $foo, '', "Got some foo" );
=begin original
are similar to these:
=end original
次と似ています:
ok( ultimate_answer() eq 42, "Meaning of Life" );
ok( $foo ne '', "Got some foo" );
=begin original
C<undef> will only ever match C<undef>. So you can test a value
agains C<undef> like this:
=end original
C<undef> は C<undef> にのみマッチングします。
C<undef> に対して値をテストしたければ、次のようにします:
is($not_defined, undef, "undefined as expected");
=begin original
(Mnemonic: "This is that." "This isn't that.")
=end original
(覚えかた: "This is that." "This isn't that.")
=begin original
So why use these? They produce better diagnostics on failure. ok()
cannot know what you are testing for (beyond the name), but is() and
isnt() know what the test was and why it failed. For example this
test:
=end original
どうしてこれらを使うのでしょう?
is() と isnt() は、失敗に関して、よりよい診断をだします。
ok() は、(名前以上には)何のためにテストをしているのか知ることが出来ませんが、
is() と isnt() は、テストが何で、テストがなぜ失敗したかを知っています。
たとえばこのテスト:
my $foo = 'waffle'; my $bar = 'yarblokos';
is( $foo, $bar, 'Is foo the same as bar?' );
=begin original
Will produce something like this:
=end original
このようなものを出力します:
not ok 17 - Is foo the same as bar?
# Failed test 'Is foo the same as bar?'
# in foo.t at line 139.
# got: 'waffle'
# expected: 'yarblokos'
=begin original
So you can figure out what went wrong without rerunning the test.
=end original
これで、テストを再度走らせることなしに何が間違ったのか、判断できます。
=begin original
You are encouraged to use is() and isnt() over ok() where possible,
however do not be tempted to use them to find out if something is
true or false!
=end original
可能なら、is() と isnt() を ok() の代わりに使うことを勧めます。
ですが、何かが、真であるか偽であるかを見つけ出すために、
is() と isnt() を使おうとしてはいけません!
# XXX BAD!
is( exists $brooklyn{tree}, 1, 'A tree grows in Brooklyn' );
=begin original
This does not check if C<exists $brooklyn{tree}> is true, it checks if
it returns 1. Very different. Similar caveats exist for false and 0.
In these cases, use ok().
=end original
このコードは、C<exists $brooklyn{tree}> が真であるかどうかをチェックしません。
このコードは、1 を返すかどうかをチェックします。これらはまったく違います。
似たような警告は、偽 と 0 にも在ります。こういうケースでは、ok() を使います。
ok( exists $brooklyn{tree}, 'A tree grows in Brooklyn' );
=begin original
A simple call to isnt() usually does not provide a strong test but there
are cases when you cannot say much more about a value than that it is
different from some other value:
=end original
単純に isnt() を呼び出すのは、普通、強いテストを提供しませんが、
ある値について、ある特定の値と異なっているということ以上を
言えないような時に適しています:
new_ok $obj, "Foo";
my $clone = $obj->clone;
isa_ok $obj, "Foo", "Foo->clone";
isnt $obj, $clone, "clone() produces a different object";
=begin original
For those grammatical pedants out there, there's an C<isn't()>
function which is an alias of isnt().
=end original
文法学者ぶる人のために書いておくと、
isnt() 関数の別名として C<isn't()> 関数があります。
=item B<like>
like( $got, qr/expected/, $test_name );
=begin original
Similar to ok(), like() matches $got against the regex C<qr/expected/>.
=end original
ok() と似ていますが、like() は、 引数の $got を正規表現の
C<qr/expected/> にマッチングさせます。
=begin original
So this:
=end original
従ってこれは:
like($got, qr/expected/, 'this is like that');
=begin original
is similar to:
=end original
次と似ています:
ok( $got =~ /expected/, 'this is like that');
=begin original
(Mnemonic "This is like that".)
=end original
(覚えかた "This is like that".)
=begin original
The second argument is a regular expression. It may be given as a
regex reference (i.e. C<qr//>) or (for better compatibility with older
perls) as a string that looks like a regex (alternative delimiters are
currently not supported):
=end original
2 番目の引数は正規表現です。正規表現リファレンス
(つまり C<qr//>) や、(古い Perl とより互換性を持たせるなら)
正規表現に見える文字列(代替の区切りは現在サポートされていません)として
与えられます。
like( $got, '/expected/', 'this is like that' );
=begin original
Regex options may be placed on the end (C<'/expected/i'>).
=end original
正規表現のオプションは末尾に置かれます (C<'/expected/i'>)。
=begin original
Its advantages over ok() are similar to that of is() and isnt(). Better
diagnostics on failure.
=end original
ok() と比べたときの利点は、is() と isnt() の利点に似ています。
失敗に関して、よく診断します。
=item B<unlike>
unlike( $got, qr/expected/, $test_name );
=begin original
Works exactly as like(), only it checks if $got B<does not> match the
given pattern.
=end original
like() のように働きますが、 $got が与えたパターンに
ッチング B<しない> ことだけをチェックします。
=item B<cmp_ok>
cmp_ok( $got, $op, $expected, $test_name );
=begin original
Halfway between ok() and is() lies cmp_ok(). This allows you to
compare two arguments using any binary perl operator.
=end original
ok() と is() の中間に cmp_ok() があります。
これは、すべての二項の Perl の演算子を使って、二つの引数を
比較できるようにします。
# ok( $got eq $expected );
cmp_ok( $got, 'eq', $expected, 'this eq that' );
# ok( $got == $expected );
cmp_ok( $got, '==', $expected, 'this == that' );
# ok( $got && $expected );
cmp_ok( $got, '&&', $expected, 'this && that' );
...etc...
=begin original
Its advantage over ok() is when the test fails you'll know what $got
and $expected were:
=end original
ok() と比べたときの利点は、テストが失敗したときに、
$got と $expected が何かがわかることです。
not ok 1
# Failed test in foo.t at line 12.
# '23'
# &&
# undef
=begin original
It's also useful in those cases where you are comparing numbers and
is()'s use of C<eq> will interfere:
=end original
また、数を比較する際や、is() を C<eq> として使うことが、干渉する際に、
有益でしょう:
cmp_ok( $big_hairy_number, '==', $another_big_hairy_number );
=begin original
It's especially useful when comparing greater-than or smaller-than
relation between values:
=end original
二つの値の大小の比較に使うと、非常に便利です:
cmp_ok( $some_value, '<=', $upper_limit );
=cut
=item B<can_ok>
can_ok($module, @methods);
can_ok($object, @methods);
=begin original
Checks to make sure the $module or $object can do these @methods
(works with functions, too).
=end original
$module または $object がメソッド(または関数) @methods を実行できるかを
チェックします。
can_ok('Foo', qw(this that whatever));
=begin original
is almost exactly like saying:
=end original
この表現は、ほぼ正確に次のような意味です:
ok( Foo->can('this') &&
Foo->can('that') &&
Foo->can('whatever')
);
=begin original
only without all the typing and with a better interface. Handy for
quickly testing an interface.
=end original
すべてをタイプしなくていい、よりよいインターフェースです。
素早いテストのための、手ごろなインターフェースです。
=begin original
No matter how many @methods you check, a single can_ok() call counts
as one test. If you desire otherwise, use:
=end original
いくつの @methods をチェックするかに関わらず、
一つの can_ok() は一つのテストとして、カウントされます。
別の方法で、やりたいなら、次のように使います:
foreach my $meth (@methods) {
can_ok('Foo', $meth);
}
=item B<isa_ok>
isa_ok($object, $class, $object_name);
isa_ok($subclass, $class, $object_name);
isa_ok($ref, $type, $ref_name);
=begin original
Checks to see if the given C<< $object->isa($class) >>. Also checks to make
sure the object was defined in the first place. Handy for this sort
of thing:
=end original
与えられた C<< $object->isa($class) >> が見えるかどうかをチェックします。
オブジェクトが最初の場所で定義されているか確かめるための
チェックでもあります。
次のようなことをするのに便利です:
my $obj = Some::Module->new;
isa_ok( $obj, 'Some::Module' );
=begin original
where you'd otherwise have to write
=end original
さもなければ次のように書く必要があるものです:
my $obj = Some::Module->new;
ok( defined $obj && $obj->isa('Some::Module') );
=begin original
to safeguard against your test script blowing up.
=end original
これは、テストスクリプトが吹っ飛ぶのを防ぐためのセーフガードです。
=begin original
You can also test a class, to make sure that it has the right ancestor:
=end original
クラスもテストできます;
正しい先祖か確かめます:
isa_ok( 'Vole', 'Rodent' );
=begin original
It works on references, too:
=end original
リファレンスでも動きます:
isa_ok( $array_ref, 'ARRAY' );
=begin original
The diagnostics of this test normally just refer to 'the object'. If
you'd like them to be more specific, you can supply an $object_name
(for example 'Test customer').
=end original
このテストの診断は通常、単に「そのオブジェクト」のリファレンスです。
それらをもっと特定したいなら、$object_name
(たとえば、'Test customer')を指定できます。
=item B<new_ok>
my $obj = new_ok( $class );
my $obj = new_ok( $class => \@args );
my $obj = new_ok( $class => \@args, $object_name );
=begin original
A convenience function which combines creating an object and calling
isa_ok() on that object.
=end original
オブジェクトの作成と、そのオブジェクトへの isa_ok() の呼び出しを結合した
便利関数です。
=begin original
It is basically equivalent to:
=end original
これは、次のものと基本的に同じです:
my $obj = $class->new(@args);
isa_ok $obj, $class, $object_name;
=begin original
If @args is not given, an empty list will be used.
=end original
@args が与えられなければ、空のリストが使われます。
=begin original
This function only works on new() and it assumes new() will return
just a single object which isa C<$class>.
=end original
この関数は、 new() でのみ動き、new() が C<$class> と isa である
一つのオブジェクトを返すことを想定しています。
=cut
=item B<subtest>
subtest $name => \&code;
=begin original
subtest() runs the &code as its own little test with its own plan and
its own result. The main test counts this as a single test using the
result of the whole subtest to determine if its ok or not ok.
=end original
subtest() は &code をそれ自身の計画と結果をもつそれ自身小さなテストとして、
実行します。
メインのテストはこれを一つのテストとしてカウントします;
サブテスト全体の結果を使って、ok か not ok か決定します。
=begin original
For example...
=end original
例えば...
use Test::More tests => 3;
pass("First test");
subtest 'An example subtest' => sub {
plan tests => 2;
pass("This is a subtest");
pass("So is this");
};
pass("Third test");
=begin original
This would produce.
=end original
以下のように出力されます。
1..3
ok 1 - First test
1..2
ok 1 - This is a subtest
ok 2 - So is this
ok 2 - An example subtest
ok 3 - Third test
=begin original
A subtest may call "skip_all". No tests will be run, but the subtest is
considered a skip.
=end original
サブテストは、"skip_all" を呼んでもかまいません。
テストは実行されませんが、subtest は飛ばされたと考えられます。
subtest 'skippy' => sub {
plan skip_all => 'cuz I said so';
pass('this test will never be run');
};
=begin original
Returns true if the subtest passed, false otherwise.
=end original