ktats****@users*****
ktats****@users*****
2013年 11月 10日 (日) 14:17:31 JST
Index: docs/modules/Test-Simple-0.99/lib/Test/More.pod diff -u /dev/null docs/modules/Test-Simple-0.99/lib/Test/More.pod:1.1 --- /dev/null Sun Nov 10 14:17:31 2013 +++ docs/modules/Test-Simple-0.99/lib/Test/More.pod Sun Nov 10 14:17:31 2013 @@ -0,0 +1,2372 @@ +=encoding utf8 + +=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() + + require_ok( 'Some::Module' ); + + # ãokãã¨ç¤ºãããã®ãã¾ãã¾ãªæ¹æ³ + ok($got eq $expected, $test_name); + + is ($got, $expected, $test_name); + isnt($got, $expected, $test_name); + + # 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<å¾ ã£ã!>ãããä»åãã¦ããã¹ããæ¸ããã¨ãã¦ããã®ãªããTest::Simpleãã¾ãè¦ã¦ãã ããã +Test::Moreã¯ãåºæ¬çãªãã¹ãã®ã³ããå¾ã¦ãç½®ãæãå¯è½ãª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 + +scriptãè¡ããã¨ãã¦ãããã¹ããããã¤ããããäºåã«ç¥ããªããããªãã¾ããªã±ã¼ã¹ãããã¾ãã +ããããã±ã¼ã¹ã§ã¯ãæå¾ã«ãã¹ãã宣è¨ãããã¨ãã§ãã¾ãã + + + 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 + +ããã¤ãã®ã±ã¼ã¹ã§ã¯ããããã¹ãscriptå ¨ã¦ãå®å ¨ã«ã¹ããããããã§ãããã + + 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 + +scriptãããªãã¹ãããããã®ãã®çç±ã宣è¨ããã¨ãå³åº§ã«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 + +å¾è ã¯ãä½ã失æãããã®æããããä¸ãã¦ããã¾ãã +ã¾ããscriptä¸ã®ãã¹ããè¦ã¤ãããããªãããç°¡åãªææ°é¢æ°ãã楽ã«æ¢ãã¾ãã + +=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. + +=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), 'all items defined' ); + + +=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 + +C<$test_name>ã¯ãã¨ã¦ãçããã¹ãã®èª¬æã§ãå®è¡æã«åºåããã¾ãã +$test_nameã¯ããã¹ãã失æããå ´åã«ãscriptä¸ã®ãã¹ããã¨ã¦ãè¦ã¤ãããããã¾ãã +ããã«ãä»ã®äººã«ãããªãã®æå³ããèããä¼ãã¾ãã$test_nameã¯ãã¯ããªãã·ã§ãã«ã§ããã +使ããã¨ãå¼·ãå§ãããã¦ãã¾ãã + +=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" ); + +(è¦ããã: "This is that." "This isn't that.") + +=begin original + +C<undef> will only ever match C<undef>. So you can test a value +against 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<exsits $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 + +ææ³å¦è ã¶ã人ã®ããã«ãæ¸ãã¦ããã¨ãC<isn't()> é¢æ°ã¯ isnt()é¢æ°ã® +ã¨ã¤ãªã¢ã¹ã¨ãã¦åå¨ãã¦ã¾ãã + +=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 =~ m/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 + +äºçªç®ã®å¼æ°ã¯æ£è¦è¡¨ç¾ã§ããæ£è¦è¡¨ç¾ã®ãªãã¡ã¬ã³ã¹ +(ãã¨ãã°ã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 C<ok()> and C<is()> lies C<cmp_ok()>. This allows you +to compare two arguments using any binary perl operator. The test +passes if the comparison is true and fails otherwise. + +=end original + +C<ok()> 㨠C<is()> ã®ä¸éã« C<cmp_ok()> ãããã¾ãã +ããã¯ããã¹ã¦ã®ãã¤ããªã®Perlã®æ¼ç®åã使ã£ã¦ãäºã¤ã®å¼æ°ãæ¯è¼ãããã¨ã許ãã¾ãã +The test passes if the comparison is true and fails otherwise. + + # 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()ã¨æ¯ã¹ãã¨ãã® cmp_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 + +cmp_ok ã¯ãæ°ãæ¯è¼ããéããis() ã 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 + +2ã¤ã®å¤ã®å¤§å°ã®æ¯è¼ã«ä½¿ãã¨ãé常ã«ä¾¿å©ã§ãã + + 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 + +ãã¹ãscriptããå¹ã£é£ã¶ã®ãé²ãããã®ã»ã¼ãã¬ã¼ãã§ãã + +=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 + # Subtest: An example subtest + 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 + +subtestã¯ã"skip_all"ãå¼ãã§ããã¾ãã¾ããããã¹ãã¯å®è¡ããã¾ãããã +subtest 㯠skip ãããã¨èãããã¾ãã + + 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 + +subtestãéãã°ãçãè¿ããä»ã¯å½ãè¿ãã¾ãã + +=begin original + +Due to how subtests work, you may omit a plan if you desire. This adds an +implicit C<done_testing()> to the end of your subtest. The following two +subtests are equivalent: + +=end original + +ãµããã¹ããã©ã®ããã«åãããã«ãã£ã¦ãæããªãè¨ç»ãçããã¨ãã§ãã¾ãã +C<done_testing()> ãæã«è¡ãããµããã¹ããçµãããã¾ãã以ä¸ã®2ã¤ã® +ãµããã¹ãã¯åãã§ã: + + subtest 'subtest with implicit done_testing()', sub { + ok 1, 'subtests with an implicit done testing should work'; + ok 1, '... and support more than one test'; + ok 1, '... no matter how many tests are run'; + }; + + subtest 'subtest with explicit done_testing()', sub { + ok 1, 'subtests with an explicit done testing should work'; + ok 1, '... and support more than one test'; + ok 1, '... no matter how many tests are run'; + done_testing(); + }; + + +=cut + +=item B<pass> + +=item B<fail> + + pass($test_name); + fail($test_name); + +=begin original + +Sometimes you just want to say that the tests have passed. Usually +the case is you've got some complicated condition that is difficult to +wedge into an ok(). In this case, you can simply use pass() (to +declare the test ok) or fail (for not ok). They are synonyms for +ok(1) and ok(0). + +=end original + +æã«ã¯ããã ããã¹ãããã¹ããã¨ç¤ºãããã§ãããã +æ®éããã®ã±ã¼ã¹ã¯ãok()ã«ãæ¼ãè¾¼ããã¨ãé£ããè¤éãªæ¡ä»¶ã«ãªã£ã¦ãã¾ãã +ããããå ´åãåç´ã«pass()(ãã¹ããokã§ããã¨å®£è¨ããããã«)ããfail(not ok ã®ããã«) +ãã使ãã¾ãããããã¯ãok(1)ã¨ãok(0)ã®åæèªã§ãã + +=begin original + +Use these very, very, very sparingly. + +=end original + +pass() 㨠fail() ã使ããã¨ã¯ã²ããã¼ã«æ éã«å¤æãã¦ãã ããã + +=cut + +=back + +=head2 Module tests + +(ã¢ã¸ã¥ã¼ã«ã®ãã¹ã) + +=begin original + +Sometimes you want to test if a module, or a list of modules, can +successfully load. For example, you'll often want a first test which +simply loads all the modules in the distribution to make sure they +work before going on to do more complicated testing. + +=end original + +ã¢ã¸ã¥ã¼ã«ãã¾ãã¯ã¢ã¸ã¥ã¼ã«ã®ãªã¹ããæ£ãããã¼ãããããããã¹ãããããå ´åã +ä¾ãã°ãããè¤éãªãã¹ããè¡ãåã«ããã£ã¹ããªãã¥ã¼ã·ã§ã³ã®å ¨ã¦ã®ã¢ã¸ã¥ã¼ã«ã +åããã¨ã確ãããããã«ãåç´ã«ãã¼ããããæåã®ãã¹ãã欲ããå ´åãããããã§ãããã + +=begin original + +For such purposes we have C<use_ok> and C<require_ok>. + +=end original + +ãã®ãããªç®çã®ããã«ãC<use_ok>ã¨ãC<require_ok>ãããã¾ãã + +=over 4 + +=item B<require_ok> + + require_ok($module); + require_ok($file); + +=begin original + +Tries to C<require> the given $module or $file. If it loads +successfully, the test will pass. Otherwise it fails and displays the +load error. + +=end original + +ä¸ãããã $module ã $file ã C<require> ã試ãã¦ãæåããã°ã +ãã¹ãã¯ãã¹ãã¾ããããã§ãªããã°ã失æãããã¼ãã¨ã©ã¼ã表示ãã¾ãã + +=begin original + +C<require_ok> will guess whether the input is a module name or a +filename. + +=end original + +C<require_ok>ã¯ãå ¥åãã¢ã¸ã¥ã¼ã«åããã¡ã¤ã«åãã®ã©ã¡ãããã«æ¨æ¸¬ãã¾ãã + +=begin original + +No exception will be thrown if the load fails. + +=end original + +ãã¼ãã失æãã¦ããä¾å¤ãåºãã¾ããã + + # require Some::Module + require_ok "Some::Module"; + + # require "Some/File.pl"; + require_ok "Some/File.pl"; + + # stop testing if any of your modules will not load + for my $module (@module) { + require_ok $module or BAIL_OUT "Can't load $module"; + } + + +=cut + +=item B<use_ok> + + BEGIN { use_ok($module); } + BEGIN { use_ok($module, @imports); } + +=begin original + +Like C<require_ok>, but it will C<use> the $module in question and +only loads modules, not files. + +=end original + +C<require_ok>ã¨ä¼¼ã¦ãã¾ããã$module ã C<use>ãã¾ãã +ã¢ã¸ã¥ã¼ã«ã®ã¿ããã¼ããããã¡ã¤ã«ã¯è¡ãã¾ããã + +=begin original + +If you just want to test a module can be loaded, use C<require_ok>. + +=end original + +ã¢ã¸ã¥ã¼ã«ããã¼ãããããããã¹ããããã ããªããC<require_ok>ã使ã£ã¦ãã ããã + +=begin original + +If you just want to load a module in a test, we recommend simply using +C<use> directly. It will cause the test to stop. + +=end original + +ãã¹ãã§ã¢ã¸ã¥ã¼ã«ããã¼ãããããã°ãåç´ã« C<use>ãç´æ¥ã«ä½¿ããã¨ã +æ¨å¥¨ãã¾ãããã¹ããåæ¢ããåå ã«ãªãã¾ãã + +=begin original + +It's recommended that you run use_ok() inside a BEGIN block so its +functions are exported at compile-time and prototypes are properly +honored. + +=end original + +BEGIN ãããã¯å ã§ãuse_ok() ãèµ°ããããã¨ãæ¨å¥¨ãã¾ãã +ããã«ããããã®é¢æ°ã¯ãã³ã³ãã¤ã«æã«exportããããããã¿ã¤ããé©åã«åãåãã¾ãã + +=begin original + +If @imports are given, they are passed through to the use. So this: + +=end original + + @ import ãä¸ãããå ´åãuse ã®éã«æ¸¡ããã¾ãã次ã®ããã« : + + BEGIN { use_ok('Some::Module', qw(foo bar)) } + +=begin original + +is like doing this: + +=end original + +次ã®ããã«ããã®ã¨åãã§ãï¼ + + use Some::Module qw(foo bar); + +=begin original + +Version numbers can be checked like so: + +=end original + +ãã¼ã¸ã§ã³ã¯æ¬¡ã®ããã«ãã§ãã¯ã§ãã¾ã: + + # Just like "use Some::Module 1.02" + BEGIN { use_ok('Some::Module', 1.02) } + +=begin original + +Don't try to do this: + +=end original + +次ã®ããã«ãããã¨ãã¦ã¯ããã¾ããï¼ + + BEGIN { + use_ok('Some::Module'); + + ...some code that depends on the use... + ...happening at compile time... + } + +=begin original + +because the notion of "compile-time" is relative. Instead, you want: + +=end original + +"compile-time"ã®è¨è¿°ãé¢ä¿ããããã§ãã代ããã«ã次ã®ããã«ãã¾ãããã + + BEGIN { use_ok('Some::Module') } + BEGIN { ...some code that depends on the use... } + +=cut + +If you want the equivalent of C<use Foo ()>, use a module but not +import anything, use C<require_ok>. + +=end original + +C<use Foo ()>ã¨åçã®ãã®ãã»ãããã°ã,ã¢ã¸ã¥ã¼ã«ã使ãããã©ã +ä½ãã¤ã³ãã¼ãããªããC<require_ok>ã使ã£ã¦ãã ããã + + BEGIN { require_ok "Foo" } + +=cut + +=back + + +=head2 Complex data structures + +(è¤éãªãã¼ã¿æ§é ) + +=begin original + +Not everything is a simple eq check or regex. There are times you +need to see if two data structures are equivalent. For these +instances Test::More provides a handful of useful functions. + +=end original + +å ¨ã¦ããåç´ãªeq ãã§ãã¯ããæ£è¦è¡¨ç¾ ã§ã¯ããã¾ããã +ãã¨ãã°ãäºã¤ã®é åãã¤ã³ã¼ã«ã§ãããã©ãããè¦ãå¿ è¦ãããã¨ããããã¾ãã +ãããã£ãä¾ã®ããã«ãTest::Moreã¯ãã¡ãã£ã¨ããæçãªé¢æ°ãæä¾ãã¦ãã¾ãã + +=begin original + +B<NOTE> I'm not quite sure what will happen with filehandles. + +=end original + +B<注æ>ãã¡ã¤ã«ãã³ãã«ã«ã¤ãã¦èµ·ãããã¨ã«ã¤ãã¦ããã¾ã確信ãããã¾ããã + +=over 4 + +=item B<is_deeply> + + is_deeply( $got, $expected, $test_name ); + +=begin original + +Similar to is(), except that if $got and $expected are references, it +does a deep comparison walking each data structure to see if they are +equivalent. If the two structures are different, it will display the +place where they start differing. + +=end original + +is()ã¨ä¼¼ã¦ãã¾ããã$got 㨠$expectedãããªãã¡ã¬ã³ã¹ã§ãã +ããããã®ãã¼ã¿ã®æ§é ãè¦ã¦ã¾ãããããããããã¤ã³ã¼ã«ãã©ãããæ·±ãæ¯è¼ããã¾ãã +äºã¤ã®æ§é ãéã£ã¦ããã°ãäºã¤ãéãå§ããå ´æã示ãã¾ãã + +=begin original + +is_deeply() compares the dereferenced values of references, the +references themselves (except for their type) are ignored. This means +aspects such as blessing and ties are not considered "different". + +=end original + +is_deeply() ã¯ããªãã¡ã¬ã³ã¹ã®å¤ã®éããæ¯è¼ãã¾ãã +ãªãã¡ã¬ã³ã¹ããèªèº«(ãã®åãã®ãã)ã¯ç¡è¦ããã¾ãã +ã¤ã¾ããblessã tie ã®ãããªå´é¢ã¯ã"éã"ã¨èãããã¾ããã + +=begin original + +is_deeply() currently has very limited handling of function reference +and globs. It merely checks if they have the same referent. This may +improve in the future. + +=end original + +is_deeply() ã¯ãä»ã®ã¨ãããé¢æ°ãªãã¡ã¬ã³ã¹ã¨globã®ãã³ããªã³ã°ã¯ +é常ã«éå®çã§ããåç´ã«ãåã referent ãæã£ã¦ãããããã§ãã¯ãã¾ãã +å°æ¥æ¹åãããããããã¾ããã + +=begin original + +L<Test::Differences> and L<Test::Deep> provide more in-depth functionality +along these lines. + +=end original + +L<Test::Differences>ã¨L<Test::Deep>ã¯ããããå¾¹åºçãªæ©è½æ§ãæä¾ãã¦ãã¾ãã + +=cut + +=back + + +=head2 Diagnostics + +(è¤æ°ã®è¨ºæ) + +=begin original + +If you pick the right test function, you'll usually get a good idea of +what went wrong when it failed. But sometimes it doesn't work out +that way. So here we have ways for you to write your own diagnostic +messages which are safer than just C<print STDERR>. + +=end original + +æ£ãããã¹ãé¢æ°ãé¸ãã ãªãããµã¤ãããã®ãã¹ãé¢æ°ã失æããå ´åã«ã +ä½ãééã£ã¦ãããã«ã¤ãã¦ããæ å ±ãå¾ããã¨ãã§ããã§ããããã§ãããæã«ã +ãããã風ã«ã¯ããã¾ãåããªããã¨ãããã¾ãã +ãã®ããã«ãèªåã§èªåèªèº«ã®è¨ºæã¡ãã»ã¼ã¸ãæ¸ãæ¹æ³ãããã¾ãã +C<print STDERR> ããããå®å ¨ã§ãã + +=over 4 + +=item B<diag> + + diag(@diagnostic_message); + +=begin original + +Prints a diagnostic message which is guaranteed not to interfere with +test output. Like C<print> @diagnostic_message is simply concatenated +together. + +=end original + +ãã¹ãã®åºåã«å¹²æ¸ããªãã¨ä¿è¨¼ããã¦ãã診æã¡ãã»ã¼ã¸ãåºåãã¾ãã +C<print> ã®ããã«ã@diagnostic_message ãåç´ã«ä¸ç·ã«ã¤ãªãã¾ãã + +=begin original + +Returns false, so as to preserve failure. + +=end original + +失æã®ã¾ã¾ã«ããããã«ãå½ãè¿ãã¾ãã + +=begin original + +Handy for this sort of thing: + +=end original + +次ã®ãããªå ´åã«ãæããã§ãï¼ + + ok( grep(/foo/, @users), "There's a foo user" ) or + diag("Since there's no foo, check that /etc/bar is set up right"); + +=begin original + +which would produce: + +=end original + +次ã®ããã«ãªãã¾ãï¼ + + not ok 42 - There's a foo user + # Failed test 'There's a foo user' + # in foo.t at line 52. + # Since there's no foo, check that /etc/bar is set up right. + +=begin original + +You might remember C<ok() or diag()> with the mnemonic C<open() or +die()>. + +=end original + +C<ok() or diag()>ããC<open() or die()> ã®ããã«è¦ããã¨è¦ããããã§ãããã + +=begin original + +B<NOTE> The exact formatting of the diagnostic output is still +changing, but it is guaranteed that whatever you throw at it won't +interfere with the test. + +=end original + +B<注æ> 診æã®åºåã®ããã®ãã©ã¼ãããã¯ãã¾ã ã¾ã æµåçã§ãã +changing, but it is guaranteed that whatever you throw at it won't +ããããããã«ä½ã渡ãã¦ããã¹ãã«å¹²æ¸ããªããã¨ã¯ä¿è¨¼ããã¦ãã¾ãã + +=item B<note> + + note(@diagnostic_message); + +=begin original + +Like diag(), except the message will not be seen when the test is run +in a harness. It will only be visible in the verbose TAP stream. + +=end original + +diag()ã¨ä¼¼ã¦ãã¾ããï¼harnessã§ãã¹ããåãã¦ããå ´åã«ã¯ã表示ããã¾ããã +åé·ãªTAPã¹ããªã¼ã ã§ã®ã¿ãè¦ããã¾ãã + + +=begin original + +Handy for putting in notes which might be useful for debugging, but +don't indicate a problem. + +=end original + +ãããã°ã«æç¨ãªã¡ã¢ãããã®ã«æããã§ããï¼åé¡ãææããã®ã« +使ã£ã¦ã¯ããã¾ããã + + note("Tempfile is $tempfile"); + +=cut + +=item B<explain> + + my @dump = explain @diagnostic_message; + + +=begin original + +Will dump the contents of any references in a human readable format. +Usually you want to pass this into C<note> or C<diag>. + +=end original + +人ãèªã¿ããããã©ã¼ãããã§ããªãã¡ã¬ã³ã¹ã®å 容ããã³ããã¾ãã +C<not> ã C<diag>ã«ä¸ãããã¨æãã§ãããã + +=begin original + +Handy for things like... + +=end original + +次ã®ãããªå ´åã«ãæããã§ãï¼ + + is_deeply($have, $want) || diag explain $have; + + +=begin original + +or + +=end original + +ã¾ãã¯ã + + note explain \%args; + Some::Class->method(%args); + + +=cut + +=back + + +=head2 Conditional tests + +(æ¡ä»¶ãã¹ã) + +=begin original + +Sometimes running a test under certain conditions will cause the +test script to die. A certain function or method isn't implemented +(such as fork() on MacOS), some resource isn't available (like a +net connection) or a module isn't available. In these cases it's +necessary to skip tests, or declare that they are supposed to fail +but will work in the future (a todo test). + +=end original + +ããæ¡ä»¶ä¸ã§ãã¹ããåãããã¨ã«ãã£ã¦ããã¹ãã¹ã¯ãªãããæ»ã¬æãããã¾ãã +(MacOSã§ã®fork()ã®ãããª)ç¹å®ã®é¢æ°ãã¡ã½ããã¯å®è£ ããã¦ããªãã£ããã +(ãããæ¥ç¶ã®ãããª)ããã¤ãã®ãªã½ã¼ã¹ãå©ç¨ã§ããªãã£ããã +ã¢ã¸ã¥ã¼ã«ãå©ç¨ã§ããªãã£ããã¨ãã +ãããã£ãã±ã¼ã¹ã§ã¯ããã¹ããã¹ãããããªããã°ãªããªããã +ããã§ãªããã°ã失æãããã¨ãäºæ³ãããããã©ã +å°æ¥çã«åã(a todo test)ã§ãããã¨ãããã¨ã宣è¨ããªããã°ãªãã¾ããã + +=begin original + +For more details on the mechanics of skip and todo tests see +L<Test::Harness>. + +=end original + +skip 㨠todo ãã¹ãã®æ©æ§ã®è©³ç´°ã¯ãC<Test::Harness>ãè¦ã¦ä¸ããã + +=begin original + +The way Test::More handles this is with a named block. Basically, a +block of tests which can be skipped over or made todo. It's best if I +just show you... + +=end original + +ååã®ã¤ãããããã¯ã¨ä¸ç·ã«ããTest::More ãã³ãã«ã®ä½¿ãæ¹ã +åºæ¬çã«ãã¹ãã®ãããã¯ã¯ãã¹ããããããããtodo ã«ãããã§ãã +ãã ã³ã¼ããè¦ããã®ãæåã§ããã⦠+ +=over 4 + +=item B<SKIP: BLOCK> + + SKIP: { + skip $why, $how_many if $condition; + + ...normal testing code goes here... + } + +=begin original + +This declares a block of tests that might be skipped, $how_many tests +there are, $why and under what $condition to skip them. An example is +the easiest way to illustrate: + +=end original + +ããã¯ãã¹ããããããã¹ãã®ãããã¯ã宣è¨ãã¾ãã +$how_many ã¯ãã¹ãã®æ°ã $why ã¯çç±ã$conditionã¯ã +ã©ãããæ¡ä»¶ã§ããããã®ãã¹ããã¹ãããããã®ããæå³ãã¾ãã +æãç°¡åãªä¾ãè¦ãã¾ãï¼ + + + SKIP: { + eval { require HTML::Lint }; + + skip "HTML::Lint not installed", 2 if $@; + + my $lint = new HTML::Lint; + isa_ok( $lint, "HTML::Lint" ); + + $lint->parse( $html ); + is( $lint->errors, 0, "No errors found in HTML" ); + } + +=begin original + +If the user does not have HTML::Lint installed, the whole block of +code I<won't be run at all>. Test::More will output special ok's +which Test::Harness interprets as skipped, but passing, tests. + +=end original + +ã¦ã¼ã¶ããHTML::Lint ãã¤ã³ã¹ãã¼ã«ãã¦ããªããã°ãå ¨ã¦ã®ãããã¯ã³ã¼ãã¯ã +I<ã¾ã£ããå®è¡ãããªãã§ããã>ã Test::Moreã¯ãç¹å¥ãª ok() ãåºåãã +Test::Harnes ã¯ããã¹ããã¹ãããããããåæ ¼ããã¨è§£éãã¾ãã + +=begin original + +It's important that $how_many accurately reflects the number of tests +in the SKIP block so the # of tests run will match up with your plan. +If your plan is C<no_plan> $how_many is optional and will default to 1. + +=end original + +ãã¹ãã®æ°ããè¨ç»ã«ãããããããã«ã +$how_many ãæ£ããSKIP ãããã¯ã®ä¸ã®ãã¹ãã®æ°ãåæ ãããã¨ã¯éè¦ã§ãã +ãããè¨ç»ãC<no_plan>ã§ããã°ã$how_many ã¯ãªãã·ã§ã³ã§ãããã©ã«ãã¯1ã«ãªãã¾ãã + +=begin original + +It's perfectly safe to nest SKIP blocks. Each SKIP block must have +the label C<SKIP>, or Test::More can't work its magic. + +=end original + +ãã¹ãããSKIPãããã¯ã¯å®å ¨ã«å®å ¨ã§ããããããã®SKIPãããã¯ã«ã¯ã +C<SKIP>ã©ãã«ããªããã°ãªãã¾ãããããããªãã¨ãTest::Moreã¯ããã®éæ³ããã¾ã使ãã¾ããã + +=begin original + +You don't skip tests which are failing because there's a bug in your +program, or for which you don't yet have code written. For that you +use TODO. Read on. + +=end original + +失æãããã¹ããã¹ããããã¦ã¯ããã¾ããã失æããã®ã¯ãããã°ã©ã ã«ãã°ãããããã§ããã +ããã§ãªããã°ãã¾ã ã³ã¼ããæ¸ãã¦ããªãããã§ãã +TODO ã®ä½¿ãæ¹ãæ¸ãã®ã§ãèªã¿ç¶ãã¦ãã ããã + +=item B<TODO: BLOCK> + + TODO: { + local $TODO = $why if $condition; + + ...ãµã¤ãã®ãã¹ãã³ã¼ããããã«ç¶ãã¦ãã ãã... + } + +=begin original + +Declares a block of tests you expect to fail and $why. Perhaps it's +because you haven't fixed a bug or haven't finished a new feature: + +=end original + +失æããã¨äºæ¸¬ãã¦ãããã¹ãã¨ã$why ã®ãããã¯ã宣è¨ãã¾ãã +ãã¶ãããã°ãã¾ã ç´ãã¦ããªãããæ°ããæ©è½ãä½ãçµãã¦ããªãã®ã§ãããã + + TODO: { + local $TODO = "URI::Geller not finished"; + + my $card = "Eight of clubs"; + is( URI::Geller->your_card, $card, 'Is THIS your card?' ); + + my $spoon; + URI::Geller->bend_spoon; + is( $spoon, 'bent', "Spoon bending, that's original" ); + } + +=begin original + +With a todo block, the tests inside are expected to fail. Test::More +will run the tests normally, but print out special flags indicating +they are "todo". Test::Harness will interpret failures as being ok. +Should anything succeed, it will report it as an unexpected success. +You then know the thing you had todo is done and can remove the +TODO flag. + +=end original + +todoãããã¯ã§ã¯ããã®ä¸ã®ãã¹ãã¯ã失æããã¨äºæããã¾ããTest::More ã¯ã +æ®éã«ãã¹ããè¡ãã¾ãããç¹å¥ãªãã©ã°ãåºåããããã®ãã¹ãããtodoãã§ãããã¨ã示ãã¾ãã +Test::Harness ã¯ããã®å¤±æã ok ã§ããã¨è§£éãã¾ãã +ãªãã§ãæåã«ããäºæããªãæåã¨ãå ±åãã¾ãã +todoã解æ¶ãããã¨åãã£ãããTODOãã©ã°ãå¤ããã¨ãåºæ¥ã¾ãã + +=begin original + +The nice part about todo tests, as opposed to simply commenting out a +block of tests, is it's like having a programmatic todo list. You know +how much work is left to be done, you're aware of what bugs there are, +and you'll know immediately when they're fixed. + +=end original + +todo ãã¹ãã®è¯ãã¨ããã¯ããã¹ãã®ãããã¯ãåç´ã«ã³ã¡ã³ãã¢ã¦ããããã¨ã§ã¯ãªãã +ããã°ã©ãçãªtodoãªã¹ãã§ããããã«ãªããã¨ã§ãã +ã©ããããããã¹ãä»äºãæ®ã£ã¦ããã®ãåããããã©ã®ãããªãã°ãããã®ããæ°ä»ãã¾ãã +ã¾ãããããã®ãã¹ããä¿®æ£ãããå ´åãå³åº§ã«èå¥ãããã¨ãåºæ¥ãã§ãããã + +=begin original + +Once a todo test starts succeeding, simply move it outside the block. +When the block is empty, delete it. + +=end original + +ä¸åº¦ãtodoãã¹ããæåãå§ããã¨ãåç´ã«ããããã¯ã®å¤å´ã«todoãã¹ãã移ãã¾ãã +ãããã¯ã空ãªããåé¤ãã¾ãã + +=item B<todo_skip> + + TODO: { + todo_skip $why, $how_many if $condition; + + ...normal testing code... + } + +=begin original + +With todo tests, it's best to have the tests actually run. That way +you'll know when they start passing. Sometimes this isn't possible. +Often a failing test will cause the whole program to die or hang, even +inside an C<eval BLOCK> with and using C<alarm>. In these extreme +cases you have no choice but to skip over the broken tests entirely. + +=end original + +todo ãã¹ãã§ã¯ãå®éã«ãã¹ãããªãã¹ãèµ°ããããã¨ãã¾ãã +ãã®ããã«ããããã®ãã¹ãããã¤ééãå§ããããç¥ãã§ãããã +ãããããã¨ããå¯è½ã§ãªãæãããã¾ãã +失æãããã¹ãã¯å ¨ã¦ã®ããã°ã©ã ãæ»ã¬ãããã³ã°ããåå ã«ãªããã¨ãããããã¾ãã +C<eval BLOCK>ã®å å´ã§ãC<alarm>ã使ã£ã¦ãã +ãã®ãããªæ¥µç«¯ãªã±ã¼ã¹ã§ã¯ãå£ãããã¹ããå®å ¨ã«ã¹ããããã以å¤ã«ã¯ãé¸æã®ä½å°ã¯ããã¾ããã + +=begin original + +The syntax and behavior is similar to a C<SKIP: BLOCK> except the +tests will be marked as failing but todo. Test::Harness will +interpret them as passing. + +=end original + +todoã§ã¯ãªããã¹ãã失æã¨ãã¦ãã¼ã¯ããã以å¤ã¯ã +æ§æãæ¯ãèããC<SKIP: BLOCK>ã«ä¼¼ã¦ãã¾ãã +Test::Harness ã¯ããã¹ãã«åæ ¼ãã¦ããã¨è§£éãã¾ãã + +=item When do I use SKIP vs. TODO? + +(SKIP 対 TODO ãã©ã®ããã«ä½¿ãåããã®ã§ãããï¼) + +=begin original + +B<If it's something the user might not be able to do>, use SKIP. +This includes optional modules that aren't installed, running under +an OS that doesn't have some feature (like fork() or symlinks), or maybe +you need an Internet connection and one isn't available. + +=end original + +B<ãããã¦ã¼ã¶ãåºæ¥ããã«ãªãã¨ãã«ã¯>ãSKIPã使ã£ã¦ãã ããã +ããã«ã¯ãã¤ã³ã¹ãã¼ã«ããã¦ããªããªãã·ã§ãã«ãªã¢ã¸ã¥ã¼ã«ãã +(fork()ãsymlinksãªã©ã®)æ©è½ãæã£ã¦ããªãOSã§å®è¡ãããã¨ãã +ã¤ã³ã¿ã¼ãããæ¥ç¶ãå¿ è¦ã¨ãã¦ããã®ã«ããããã¦ã¼ã¶ãå©ç¨ã§ããªããã¨ãå«ã¿ã¾ãã + +=begin original + +B<If it's something the programmer hasn't done yet>, use TODO. This +is for any code you haven't written yet, or bugs you have yet to fix, +but want to put tests in your testing script (always a good idea). + +=end original + +B<ãããããã°ã©ããã¾ã ããã£ã¦ããªãã¨ãã«ã¯>ãTODO ã使ã£ã¦ãã ããã +ããã¯ããã¹ãscriptã«ããã¹ããç½®ããã(常ã«ããèãã§ã)ããã©ãã +ã¾ã æ¸ãã¦ããªãã³ã¼ãããã¾ã ç´ãã¦ããªããã°ãªã©ã§ãã + +=back + + +=head2 Test control + +(ãã¹ãã®å¶å¾¡) + +=over 4 + +=item B<BAIL_OUT> + + BAIL_OUT($reason); + +=begin original + +Indicates to the harness that things are going so badly all testing +should terminate. This includes the running of any additional test scripts. + +=end original + +æ²æ¨ãªãªãã¨ã«ãªã£ãããããã¹ã¦ã®ãã¹ããçµäºãããããã«ãharnessã«ä¼ãã¾ãã +ããã¯ãã©ããªè¿½å ã®ãã¹ãã¹ã¯ãªããã®å®è¡ãå«ã¿ã¾ãã + +=begin original + +This is typically used when testing cannot continue such as a critical +module failing to compile or a necessary external utility not being +available such as a database connection failing. + +=end original + +ãã¼ã¿ãã¼ã¹æ¥ç¶ã®ãããªãéè¦ãªã¢ã¸ã¥ã¼ã«ã®ã³ã³ãã¤ã«ã¨ã©ã¼ã +å¿ é ã®å¤é¨ã¦ã¼ãã£ãªãã£ãå©ç¨ã§ããªããããªããã«ã +ãã¹ããç¶ããããªãå ´åã«ãå ¸åçã«ä½¿ããã¾ãã + +=begin original + +The test will exit with 255. + +=end original + +ãã¹ãã¯255ã§çµäºãã¾ãã + +For even better control look at L<Test::Most>. + +L<Test::Most>ã«ãããããå¶å¾¡ãããã¾ãã + + +=cut + +=back + + +=head2 Discouraged comparison functions + +(æ¨å¥¨ãããªãæ¯è¼é¢æ°) + +=begin original + +The use of the following functions is discouraged as they are not +actually testing functions and produce no diagnostics to help figure +out what went wrong. They were written before is_deeply() existed +because I couldn't figure out how to display a useful diff of two +arbitrary data structures. + +=end original + +ä¸è¨ã®é¢æ°ã®ä½¿ç¨ã¯æ¨å¥¨ããã¾ããããããã¯ãå®éã«ã¯ãã¹ãé¢æ°ã§ã¯ãªãã +ä½ãééã£ã¦ããããçªãæ¢ããå©ãã¨ãªã診æã¯æä¾ãã¾ããã +is_deeply() ãã§ããããåã«æ¸ãããé¢æ°ã§ã2ã¤ã®ä»»æã®ãã¼ã¿æ§é ã® +éãã表示ããæå¹ãªæ¹æ³ãèãä»ããã¨ãåºæ¥ãªãã£ãããã§ãã + +=begin original + +These functions are usually used inside an ok(). + +=end original + +ãããã¯ãok() ã®ä¸ã§ä½¿ãããã®ãæ®éã§ãã + + ok( eq_array(\@got, \@expected) ); + +C<is_deeply()> can do that better and with diagnostics. + +C<is_deeply()>ã¯ãããè¯ãã§ããã診æãããã¾ãã + + is_deeply( \@got, \@expected ); + +=begin original + +They may be deprecated in future versions. + +=end original + +å°æ¥ã®ãã¼ã¸ã§ã³ã§ãªããªãããããã¾ããã + +=over 4 + +=item B<eq_array> + + my $is_eq = eq_array(\@got, \@expected); + +=begin original + +Checks if two arrays are equivalent. This is a deep check, so +multi-level structures are handled correctly. + +=end original + +äºã¤ã®é åãã¤ã³ã¼ã«ãã©ããããã§ãã¯ãã¾ããããã¯ãæ·±ããã§ãã¯ã§ããã +ãã«ãã¬ãã«ã®æ§é ãæ£ç¢ºã«æ±ããã¾ãã + +=item B<eq_hash> + + my $is_eq = eq_hash(\%got, \%expected); + +=begin original + +Determines if the two hashes contain the same keys and values. This +is a deep check. + +=end original + +äºã¤ã®ããã·ã¥ãåããã¼ã¨å¤ãå«ãã§ãããã©ããã調ã¹ã¾ãã +ããã¯æ·±ããã§ãã¯ã§ãã + +=item B<eq_set> + + my $is_eq = eq_set(\@got, \@expected); + +=begin original + +Similar to eq_array(), except the order of the elements is B<not> +important. This is a deep check, but the irrelevancy of order only +applies to the top level. + +=end original + +eq_array() ã¨ã«ã¦ãã¾ãããè¦ç´ ã®é çªã¯éè¦ã§ã¯ããã¾ããã +ããã¯ãæ·±ããã§ãã¯ã§ãããé çªã®ä¸æ´åã¯ããããã¬ãã«ã«ããé©ç¨ããã¾ããã + + ok( eq_set(\@got, \@expected) ); + +=begin original + +Is better written: + +=end original + +ããè¯ãæ¸ãæ¹: + + is_deeply( [sort @got], [sort @expected] ); + +=begin original + +B<NOTE> By historical accident, this is not a true set comparison. +While the order of elements does not matter, duplicate elements do. + +=end original + +B<注æ>ãæ´å²çãªé½åã«ãããããã¯ãæ¬å½ã® set ã®æ¯è¼ã§ã¯ããã¾ããã +è¦ç´ ã®é çªãåé¡ã§ã¯ãªãä¸ã«ãéè¤ããè¦ç´ ãåé¡ã«ãã¾ããã + +=begin original + +B<NOTE> eq_set() does not know how to deal with references at the top +level. The following is an example of a comparison which might not work: + +=end original + +B<注æ>ãeq_set() ã¯ããããã¬ãã«ã§ãªãã¡ã¬ã³ã¹ãã©ãæ±ãããç¥ãã¾ããã +以ä¸ã®ãã®ã¯ãåããªãæ¯è¼ã®ä¾ã§ãã + + eq_set([\1, \2], [\2, \1]); + +=begin original + +L<Test::Deep> contains much better set comparison functions. + +=end original + +L<Test::Deep> ã«ã¯ãããããæ¯è¼é¢æ°ã®ã»ãããããã¾ãã + +=cut + +=back + + +=head2 Extending and Embedding Test::More + +(Test::Moreã®æ¡å¼µã¨å å«) + +=begin original + +Sometimes the Test::More interface isn't quite enough. Fortunately, +Test::More is built on top of Test::Builder which provides a single, +unified backend for any test library to use. This means two test +libraries which both use Test::Builder B<can be used together in the +same program>. + +=end original + +Test::More ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ããã¾ã£ããååã§ãªãæãããã¾ãã +幸éãªãã¨ã«ãTest::More ã¯ãTest::Builderã®ä¸ã«ä½ããã¦ãã¾ãã +Test::Builder ã¯ããããããã¹ãã©ã¤ãã©ãªã¼ã®ããã®ãä¸ã¤ã®ãçµ±åããããããã¯ã¨ã³ããæä¾ãã¦ãã¾ãã +ãã®ãã¨ã¯ã両æ¹ã¨ããTest::Builderã使ã£ã¦ãããäºã¤ã®ãã¹ãã©ã¤ãã©ãªã¼ãªãã°ã +B<åãããã°ã©ã ã§ãã£ããã«ä½¿ãããã¨>ãæå³ãã¾ã + +=begin original + +If you simply want to do a little tweaking of how the tests behave, +you can access the underlying Test::Builder object like so: + +=end original + +ããåç´ã«ããã¹ãã®æåã®ä»æ¹ã微調æ´ããããã°ã次ã®ããã«ã +ãã¼ã¹ã¨ãããTest::Builderãªãã¸ã§ã¯ãã«ã¢ã¯ã»ã¹ã§ãã¾ã: + +=over 4 + +=item B<builder> + + my $test_builder = Test::More->builder; + +=begin original + +Returns the Test::Builder object underlying Test::More for you to play +with. + +=end original + +Test::Moreã§éã¶ããã®ãTest::Moreã®åºç¤ããªãTest::Builder ãªãã¸ã§ã¯ãã +è¿ãã¾ãã + +=cut + +=back + +=head1 EXIT CODES + +(çµäºã³ã¼ã) + +=begin original + +If all your tests passed, Test::Builder will exit with zero (which is +normal). If anything failed it will exit with how many failed. If +you run less (or more) tests than you planned, the missing (or extras) +will be considered failures. If no tests were ever run Test::Builder +will throw a warning and exit with 255. If the test died, even after +having successfully completed all its tests, it will still be +considered a failure and will exit with 255. + +=end original + +ãã¹ã¦ã®ãã¹ãããã¹ããããTest::Builder㯠0 ã§çµäºãã¾ã(é常ã§ã)ã +ä½ãééã£ã¦ãããï¼ééã£ãæ°ã§çµäºãã¾ããè¨ç»ãã¦ãããããã +å°ãªã(ããå¤ã)ããè¦å¤±ã£ãããä½è¨ãªãã¹ããèµ°ãããã¨ã失æããã¨ã¿ãªããã¾ãã +ãã¹ããå®è¡ãããªããã°ãè¦åãæãã255ã§çµäºãã¾ãã +ãã¹ããæ»ãã ãããã¨ããã¹ã¦ã®ãã¹ããæåãã¦ãã +失æã¨ã¿ãªãã255ã§çµäºãã¾ãã + +=begin original + +So the exit codes are... + +=end original + +çµäºã³ã¼ãã¯... + + 0 ãã¹ã¦ã®ãã¹ããæå + 255 ãã¹ãã¯æ»ãã ãããã¹ã¦æåããããééã£ã¦ãã # of tests run + any other number ééã£ãæ°(失æããä½è¨ãªãã®ãå«ã) + +=begin original + +If you fail more than 254 tests, it will be reported as 254. + +=end original + +254以ä¸ã®ãã¹ãã«å¤±æãããã254ãå ±åãã¾ãã + +=begin original + +B<NOTE> This behavior may go away in future versions. + +=end original + +B<注æ>ããã®æ¯ãèãã¯ãå°æ¥ã®ãã¼ã¸ã§ã³ã§ãªããªãããããã¾ããã + +=head1 è¦åã¨æ³¨æ + +=over 4 + +=item å¾æ¹äºææ§ + +=begin original + +Test::More works with Perls as old as 5.6.0. + +=end original + +Test::More ã¯Perl 5.6.0ã§åãã¾ãã + +=head1 COMPATIBILITY + +(äºææ§) + +=begin original + +Test::More works with Perls as old as 5.8.1. + +=end original + +Test::Moreã¯ã5.8.1 ã®å¤ã Perl ã§ãåãã¾ãã + +=begin original + +Thread support is not very reliable before 5.10.1, but that's +because threads are not very reliable before 5.10.1. + +=end original + +5.10.1 ããåã§ã¯ãã¹ã¬ãããµãã¼ãã¯ãã¾ãä¿¡é ¼ã§ãã¾ãããããããããã¯ã +threads ã5.10.1 ããåã«ãã¾ãä¿¡é ¼ã§ãªãã£ãããã§ãã + +=begin original + +Although Test::More has been a core module in versions of Perl since 5.6.2, Test::More has evolved since then, and not all of the features you're used to will be present in the shipped version of Test::More. If you are writing a module, don't forget to indicate in your package metadata the minimum version of Test::More that you require. For instance, if you want to use C<done_testing()> but want your test script to run on Perl 5.10.0, you will need to explicitly require Test::More > 0.88. + +=end original + +Test::More ã¯ãPerl 5.6.2 ã®ãã¼ã¸ã§ã³ããã³ã¢ã¢ã¸ã¥ã¼ã«ã§ãããTest::More ã¯ãããããé²åãã¦ãã¾ãããã使ã£ã¦ããå ¨ã¦ã®æ©è½ããTest::More ã®ã·ããããããã¼ã¸ã§ã³ã«åå¨ããããã§ã¯ããã¾ãããã¢ã¸ã¥ã¼ã«ãæ¸ãã¦ãããªããããã±ã¼ã¸ã®ã¡ã¿ãã¼ã¿ã§ãå¿ è¦ã¨ãã Test::More ã®æå°ã®ãã¼ã¸ã§ã³ãæå®ãã¦ãããã®ãå¿ããªãã§ãã ãããä¾ãã°ãC<done_testing()> ã使ã£ã¦ãããã§ãããã¹ã¯ãªããã¯ãPerl 5.10.0 ã§åãããããªããTest::More > 0.88 ãå¿ è¦ã ã¨æ示ããªããã°ãªãã¾ããã + +=begin original + +Key feature milestones include: + +=end original + +éè¦ãªæ©è½ã®ãã¤ã«ã¹ãã¼ã³ã¯: + +=over 4 + +=item subtests + +=begin original + +Subtests were released in Test::More 0.94, which came with Perl 5.12.0. Subtests did not implicitly call C<done_testing()> until 0.96; the first Perl with that fix was Perl 5.14.0 with 0.98. + +=end original + +ãµããã¹ã㯠Test::More 0.94 ã§ãªãªã¼ã¹ããã¾ããã Perl 5.12.0 ã«ä»å±ã¾ãããµããã¹ãã¯ã0.96ã¾ã§ãæé»çã«ãC<done_testing()>ãå¼ã³ã¾ãã; 0.98ã§ããããã®ä¿®æ£ãã¤ãã¦ããæåã® Perl ã¯ã5.14.0 ã§ãã + +=item C<done_testing()> + +=begin original + +This was released in Test::More 0.88 and first shipped with Perl in 5.10.1 as part of Test::More 0.92. + +=end original + +Test::More 0.88 ã§ãªãªã¼ã¹ããã¾ãããTest::More 0.92 㯠Perl 5.10.1 ã®ä¸é¨ã¨ãã¦ä»å±ãã¾ãã + +=item C<cmp_ok()> + +=begin original + +Although C<cmp_ok()> was introduced in 0.40, 0.86 fixed an important bug to make it safe for overloaded objects; the fixed first shipped with Perl in 5.10.1 as part of Test::More 0.92. + +=end original + +C<cmp_ok()> ã¯ã 0.40 ã§å°å ¥ããã¾ãããã0.86 ã§ããªã¼ãã¼ãã¼ãããããªãã¸ã§ã¯ããå®å ¨ã«ããããã®éè¦ãªãã°ãä¿®æ£ããã¾ãã; Test::More 0.92 ã®ä¸é¨ã¨ãã¦ãPerl 5.10.1 ã§æåã«ãªãªã¼ã¹ããã¾ããã + +=item C<new_ok()> C<note()> and C<explain()> + +=begin original + +These were was released in Test::More 0.82, and first shipped with Perl in 5.10.1 as part of Test::More 0.92. + +=end original + +ãããã¯ãTest::More 0.82 ã§ãªãªã¼ã¹ããã¾ãããTest::More 0.92 ã®ä¸é¨ã¨ãã¦ãPerl 5.10.1 ã§æåã«ãªãªã¼ã¹ããã¾ããã + +=back + +=begin original + +There is a full version history in the Changes file, and the Test::More versions included as core can be found using L<Module::CoreList>: + +=end original + +å¤æ´ãã¡ã¤ã«ã®å®å ¨ãªãã¼ã¸ã§ã³ãã¹ããªã¼ã§ããã¾ããL<Module::CoreList>ã使ãã°ãã³ã¢ã¨ãã¦å«ã¾ãã Test::More ã®ãã¼ã¸ã§ã³ããããã¾ãã + + $ corelist -a Test::More + + +=head1 CAVEATS and NOTES + +=over 4 + +=item utf8 / "Wide character in print" + +=begin original + +If you use utf8 or other non-ASCII characters with Test::More you +might get a "Wide character in print" warning. Using C<binmode +STDOUT, ":utf8"> will not fix it. Test::Builder (which powers +Test::More) duplicates STDOUT and STDERR. So any changes to them, +including changing their output disciplines, will not be seem by +Test::More. + +=end original + +utf8 ã non-ASCIIãªæåãTest::Moreã¨ä¸ç·ã«ä½¿ãå ´åã +"Wide character in print"ã®è¦åãåºãããããã¾ããã +C<binmode STDOUT, ":utf8">ã使ã£ã¦ããç´ãã¾ãããTest::Builder ( +Test::Moreã«åãä¸ãã¦ãã) STDOUTã¨STDERRãè¤è£½ãã¦ãã¾ãã +ãã®ããããããã¸ã®ã©ããªå¤æ´ãããããã®åºåã®ä»æ¹ã®å¤æ´ãå«ã¿ã +Test::Moreã«ã¯ãããã¾ããã + +=begin original + +One work around is to apply encodings to STDOUT and STDERR as early +as possible and before Test::More (or any other Test module) loads. + +=end original + +1ã¤ã®ã¯ã¼ã¯ã¢ã©ã¦ã³ã㯠Test::More(ããã»ãã®Testã¢ã¸ã¥ã¼ã«)ããã¼ããããåã«ã +STDOUTã¨STDERRã«å¯è½ãªéãæ©ãã¨ã³ã³ã¼ãã£ã³ã°ãé©ç¨ãããã¨ã§ãã + + use open ':std', ':encoding(utf8)'; + use Test::More; + +=begin original + +A more direct work around is to change the filehandles used by +Test::Builder. + +=end original + +ããç´æ¥çãªå¯¾å¦æ¹æ³ã¨ãã¦ã¯ãTest::Builderã使ã£ã¦ãã¡ã¤ã«ãã³ãã«ãå¤æ´ãããã¨ã§ãã + + + my $builder = Test::More->builder; + binmode $builder->output, ":encoding(utf8)"; + binmode $builder->failure_output, ":encoding(utf8)"; + binmode $builder->todo_output, ":encoding(utf8)"; + + +=item Overloaded objects + +(ãªã¼ãã¼ãã¼ãããããªãã¸ã§ã¯ã) + +=begin original + +String overloaded objects are compared B<as strings> (or in cmp_ok()'s +case, strings or numbers as appropriate to the comparison op). This +prevents Test::More from piercing an object's interface allowing +better blackbox testing. So if a function starts returning overloaded +objects instead of bare strings your tests won't notice the +difference. This is good. + +=end original + +ãªã¼ãã¼ãã¼ãããããªãã¸ã§ã¯ãã¯B<æååã¨ãã¦>(ã¾ãã¯ã cmp_ok()ã§ã¯ã +æ¯è¼ãããªãã¬ã¼ã¿ã¼ã«ãããã£ã¦ãæååãæ°åã¨ãã¦)æ¯è¼ããã¾ããããã¯ã +Test::Moreããããè¯ããã©ãã¯ããã¯ã¹ãã¹ãã許ãã¦ãããªãã¸ã§ã¯ãã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã +çªãåºãã®ã妨ãã¾ãããã®ãããé¢æ°ã裸ã®æååã®ä»£ããã«ããªã¼ãã¼ãã¼ãããã +ãªãã¸ã§ã¯ããè¿ãããã«ãªãã°ãããªãã®ãã¹ãã¯éãã«æ°ä»ããªãã§ããããããã¯è¯ããã¨ã§ãã + +=begin original + +However, it does mean that functions like is_deeply() cannot be used to +test the internals of string overloaded objects. In this case I would +suggest L<Test::Deep> which contains more flexible testing functions for +complex data structures. + +=end original + +ã§ãããis_deeply()ã®ãããªé¢æ°ãããªãã¸ã§ã¯ãããªã¼ãã¼ãã¼ããããæååã®å é¨ã® +ãã¹ãã«ä½¿ããã¨ãåºæ¥ãªãã¨ããããã§ã¯ããã¾ããããã®ã¨ã¼ã¹ã§ã¯ã +L<Test::Deep>ãææ¡ãã¾ããè¤éãªãã¼ã¿æ§é ã®ããã«ãããæè»ãªãã¹ãé¢æ°ãããã¾ãã + + +=item Threads + +=begin original + +Test::More will only be aware of threads if "use threads" has been done +I<before> Test::More is loaded. This is ok: + +=end original + +Test::Moreã¯ãTest::Moreããã¼ããããåã«ã"use threads"ãããã¦ããå ´åã +ã¹ã¬ãããæèãã¾ãã次㯠ok ã§ã: + + + use threads; + use Test::More; + +=begin original + +This may cause problems: + +=end original + +次ã®ãã®ã¯åé¡ã«ãªãã¾ã: + + use Test::More + use threads; + +=begin original + +5.8.1 and above are supported. Anything below that has too many bugs. + +=end original + +5.8.1 以ä¸ãæ³å®ãã¦ãã¾ããããæªæºã®ãã¼ã¸ã§ã³ã¯ãå¤ãã®ãã°ãããã¾ãã + +=back + + +=head1 HISTORY + +(çµç·¯) + +=begin original + +This is a case of convergent evolution with Joshua Pritikin's Test +module. I was largely unaware of its existence when I'd first +written my own ok() routines. This module exists because I can't +figure out how to easily wedge test names into Test's interface (along +with a few other problems). + +=end original + +ããã¯ãJoshua Pritikin ã®ãã¹ãã¢ã¸ã¥ã¼ã«ãã¾ã¨ãã¦é²åããããã®ã§ãã +èªåã®ok()ã«ã¼ãã³ãæåã«æ¸ããã¨ããPritikinã®ãã¹ãã¢ã¸ã¥ã¼ã«ã®åå¨ã«ã¾ã£ããæ°ã¥ãã¦ãã¾ããã§ããã +ãã®ã¢ã¸ã¥ã¼ã«ãå¨ãã®ã¯ãç°¡åã«ãã¹ãã®ååããã¹ãã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã«ãæ¼ãè¾¼ãæ¹æ³ãè¦ã¤ãåºããªãã£ãããã§ã +(ä»ã®ããã¤ãã®åé¡ã¨ã¨ãã«)ã + +=begin original + +The goal here is to have a testing utility that's simple to learn, +quick to use and difficult to trip yourself up with while still +providing more flexibility than the existing Test.pm. As such, the +names of the most common routines are kept tiny, special cases and +magic side-effects are kept to a minimum. WYSIWYG. + +=end original + +ããã§ã®ã´ã¼ã«ã¯ãåå¨ããTest.pmãããæè»æ§ãæä¾ãã¤ã¤ +å¦ã³ããããããã«ä½¿ãã¦ãã¤ã¾ããã«ãããã¹ãã®ã¦ã¼ãã£ãªãã£ã§ãã +ãããªããã§ãã»ã¨ãã©ã®å ±éã®ã«ã¼ãã³ã®ååã¯å°ããã¾ã¾ã«ãã¦ã +ç¹å¥ãªã±ã¼ã¹ã¨éæ³ã®å´é¢ã®å¹æã¯æå°éã«ã¨ã©ãã¾ããã +WYSIWYGï¼è¨³è¨»:what you see is what you getï¼ã + + +=head1 SEE ALSO + +=begin original + +L<Test::Simple> if all this confuses you and you just want to write +some tests. You can upgrade to Test::More later (it's forward +compatible). + +=end original + +L<Test::Simple> ãããTest::Moreãã¾ã£ããæ··ä¹±ãããã ãã®ãã®ã§ããã +ãã ããã¹ããæ¸ãããã ããªããå¾ã§ãTest::Moreã«ã¢ããã°ã¬ã¼ãã§ãã¾ã +(Test::More ã¯ãä¸ä½äºææ§ãããã¾ã)ã + +=begin original + +L<Test::Harness> is the test runner and output interpreter for Perl. +It's the thing that powers C<make test> and where the C<prove> utility +comes from. + +=end original + +L<Test::Harness>ã¯ããã¹ããå®è¡æ©ã§ãããPerlã®åºåã¤ã³ã¿ããªã¿ã§ãã +C<make test>ã«åãä¸ãã¦ãããã®ã§ãããC<prove>ã¦ã¼ãã£ãªãã£ã +ç±æ¥ããã¨ããã§ãã + +=begin original + +L<Test::Legacy> tests written with Test.pm, the original testing +module, do not play well with other testing libraries. Test::Legacy +emulates the Test.pm interface and does play well with others. + +=end original + +C<Test::Legacy>ã¯ãTest.pmã¨ä¸ç·ã«æ¸ãããããªãªã¸ãã«ã®ãã¹ãã¢ã¸ã¥ã¼ã«ã§ãã +ä»ã®ãã¹ãã©ã¤ãã©ãªã¨ä¸ç·ã«ã¾ãã¾ãåãã¾ãããTest::Legacyã¯ã +Test.pmã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ãã¨ãã¥ã¬ã¼ãããä»ã®ãã®ã¨ãã¾ãåãã¾ãã + +=begin original + +L<Test::Differences> for more ways to test complex data structures. +And it plays well with Test::More. + +=end original + +L<Test::Differences> è¤éãªãã¼ã¿æ§é ããã¹ãããããã®ããå¤ãã®æ¹æ³ã®ããã«ã +Test::Moreã¨ä¸ç·ã«ããã¯ãããã¾ãã + +L<Test::Class> is like xUnit but more perlish. + +L<Test::Class> ã¯ãxUnitã«ä¼¼ã¦ãã¾ããããã perlã£ã½ãã§ãã + +L<Test::Deep> gives you more powerful complex data structure testing. + +L<Test::Deep> ã¯ãããååã§è¤éãªãã¼ã¿æ§é ã®ãã¹ããã§ãã¾ãã + +L<Test::Inline> shows the idea of embedded testing. + +L<Test::Inline>ãã¹ããåãè¾¼ãèããè¦ãã¾ãã + +L<Bundle::Test> installs a whole bunch of useful test modules. + +L<Bundle::Test> ã¯ã便å©ãªãã¹ããã¸ã¥ã¼ã«ãå ¨é¨ã¤ã³ã¹ãã¼ã«ãã¾ãã + +=head1 AUTHORS + +Michael G Schwern E<lt>schwe****@pobox*****<gt> with much inspiration +from Joshua Pritikin's Test module and lots of help from Barrie +Slaymaker, Tony Bowden, blackstar.co.uk, chromatic, Fergal Daly and +the perl-qa gang. + +=head1 BUGS + +See F<http://rt.cpan.org> to report and view bugs. + + +=head1 SOURCE + +The source code repository for Test::More can be found at +F<http://github.com/schwern/test-more/>. + + +=head1 COPYRIGHT + +Copyright 2001-2008 by Michael G Schwern E<lt>schwe****@pobox*****<gt>. + +This program is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. + +See F<http://www.perl.com/perl/misc/Artistic.html> Index: docs/modules/Test-Simple-0.99/lib/Test/Simple.pod diff -u /dev/null docs/modules/Test-Simple-0.99/lib/Test/Simple.pod:1.1 --- /dev/null Sun Nov 10 14:17:31 2013 +++ docs/modules/Test-Simple-0.99/lib/Test/Simple.pod Sun Nov 10 14:17:31 2013 @@ -0,0 +1,411 @@ +=encoding utf8 + +=head1 NAME + +=begin original + +Test::Simple - Basic utilities for writing tests. + +=end original + + +Test::Simple - ãã¹ããæ¸ãããã®åºæ¬çãªã¦ã¼ãã£ãªã㣠+ +=head1 SYNOPSIS + + use Test::Simple tests => 1; + + ok( $foo eq $bar, 'foo is bar' ); + + +=head1 DESCRIPTION + +=begin original + +** If you are unfamiliar with testing B<read Test::Tutorial> first! ** + +=end original + +** ãã¹ãã«é¦´æããªããªããã¾ããB<Test::Tutorialãèªãã§ä¸ãã>! ** + +=begin original + +This is an extremely simple, extremely basic module for writing tests +suitable for CPAN modules and other pursuits. If you wish to do more +complicated testing, use the Test::More module (a drop-in replacement +for this one). + +=end original + +ããã¯ãCPANã¢ã¸ã¥ã¼ã«ããä»ã®ç®çã®ããã«ãã¹ããæ¸ãã®ã«ã +極ãã¦ç°¡åãªã極ãã¦åºæ¬çãªã¢ã¸ã¥ã¼ã«ã§ãããããããè¤éãªãã¹ããæããªãã +(ç½®ãæãå¯è½ãªå®è£ ã§ãã)Test::Moreã¢ã¸ã¥ã¼ã«ã使ã£ã¦ä¸ããã + +=begin original + +The basic unit of Perl testing is the ok. For each thing you want to +test your program will print out an "ok" or "not ok" to indicate pass +or fail. You do this with the ok() function (see below). + +=end original + +Perlã®ãã¹ãã®åºæ¬çãªã¦ãããã¯ãokã§ãããã¹ãããããã®ããããã«ã¤ãã¦ã +ããã°ã©ã ã¯ããokããããnot okããåºåããåæ ¼ãããã失æãããã示ãã¾ãã +ok()é¢æ°ã§ããããè¡ãã¾ã(ä¸ãè¦ã¦ãã ãã)ã + +=begin original + +The only other constraint is you must pre-declare how many tests you +plan to run. This is in case something goes horribly wrong during the +test and your test program aborts, or skips a test or whatever. You +do this like so: + +=end original + +å¯ä¸ã®ä»ã®å¼·å¶ã¯ãè¡ããã¨è¨ç»ãã¦ãããã¹ãããããã¤ã§ããããå ã«å®£è¨ããªããã°ãªããªããã¨ã§ãã +ãã®å®£è¨ã¯ãä½ãããã¹ãã®éã«æãããåé¡ã«ãªãããã¹ãã®ããã°ã©ã ãä¸æãããã +ãã¹ããã¹ãããããããä½ããããã£ããã®ãèµ·ããå ´åã®ããã«ããã¾ãããã®ããã«ãã¾ãï¼ + + use Test::Simple tests => 23; + +=begin original + +You must have a plan. + +=end original + +è¨ç»ãå¿ è¦ã§ãã + +=over 4 + +=item B<ok> + + ok( $foo eq $bar, $name ); + ok( $foo eq $bar ); + +=begin original + +ok() is given an expression (in this case C<$foo eq $bar>). If it's +true, the test passed. If it's false, it didn't. That's about it. + +=end original + +ok() ã«ã¯å¼ãä¸ãããã¦ãã¾ã(ãã®å ´åãC<$foo eq $bar>)ã +ä¸ããããå¼ããçãªãããã¹ãã¯åæ ¼ã§ãã ä¸ããããå¼ããå½ãªããåæ ¼ã§ã¯ããã¾ããã +ã ããããããããã§ãã + +=begin original + +ok() prints out either "ok" or "not ok" along with a test number (it +keeps track of that for you). + +=end original + +ok() ã¯ããã¹ãã®çªå·ã¨ä¸ç·ã«ããokãããnot okãã®ã©ã¡ãããåºåãã¾ã +(å¾ã追ãç¶ãã¾ã)ã + + # This produces "ok 1 - Hell not yet frozen over" (or not ok) + ok( get_temperature($hell) > 0, 'Hell not yet frozen over' ); + +=begin original + +If you provide a $name, that will be printed along with the "ok/not +ok" to make it easier to find your test when if fails (just search for +the name). It also makes it easier for the next guy to understand +what your test is for. It's highly recommended you use test names. + +=end original + +ããã$nameãå¼æ°ã«ä¸ãããªãã$nameã¯ããok/not okãã¨ä¸ç·ã«åºåããã +ãã¹ãã失æããå ´åã«ããã¹ããè¦ã¤ããã®ãç°¡åã«ãªãã¾ã(ã ãååã ãã§æ¢ãã¾ã)ã +ã¾ãããããã¦ããã°ãä»ã®äººããããªãã®ãã¹ããä½ã®ããã«ããã®ããç解ããã®ãç°¡åã«ãªãã¾ãã +ãã¹ãã®ååãç¨ãããã¨ã¯ãå¼·ãæ¨å¥¨ããã¾ãã + +=begin original + +All tests are run in scalar context. So this: + +=end original + +å ¨ã¦ã®ãã¹ãã¯ãã¹ã«ã©ã¼ã³ã³ããã¹ãã§åãã¾ããã¤ã¾ããããã¯ï¼ + + ok( @stuff, 'I have some stuff' ); + +=begin original + +will do what you mean (fail if stuff is empty) + +=end original + +ããªãã®æå³ããããã«åãã¾ãï¼stuffã空ãªã失æãã¾ãï¼ã + +=back + +=begin original + +Test::Simple will start by printing number of tests run in the form +"1..M" (so "1..5" means you're going to run 5 tests). This strange +format lets Test::Harness know how many tests you plan on running in +case something goes horribly wrong. + +=end original + +Test::Simple ã¯ãã1..Mãã¨è¨ãå½¢å¼ã§ããã¹ãã®åãçªå·ãããªã³ããããã¨ã§ã +å§ã¾ãã¾ãï¼ã¤ã¾ããã1..5ãã¯ãï¼ã¤ã®ãã¹ããåããã¨ããæå³ã§ãï¼ã +ãã®ãå¤ãã£ããã©ã¼ãããã¯ãä½ããæãããééã£ã¦ãããããªå ´åã«ã +å®è¡ä¸ã®è¨ç»ãããã¤ãããããTest::Harnessã«ç¥ããã¾ãã + +=begin original + +If all your tests passed, Test::Simple will exit with zero (which is +normal). If anything failed it will exit with how many failed. If +you run less (or more) tests than you planned, the missing (or extras) +will be considered failures. If no tests were ever run Test::Simple +will throw a warning and exit with 255. If the test died, even after +having successfully completed all its tests, it will still be +considered a failure and will exit with 255. + +=end original + +ãããå ¨ã¦ã®ãã¹ããåæ ¼ããã°ãTest::Simpleã¯ã0ã§ãçµãã¾ã(ããã¯æ®éã§ã)ã +ä½ããééã£ã¦ããã°ãééã£ããæ°ã§çµäºãã¾ãã +è¨ç»ããã®ãããå°ãªãï¼ã¾ãã¯ãå¤ãã®ï¼ãã¹ããå®è¡ãããå ´åãè¦ããããªããã®ï¼ãä½åãªãã®ï¼ã +ãããããè¨ç»ã¯å¤±æããã¨ã¿ãªããã¾ãã +ããããã¹ããå®è¡ãããªããã°ãTest::Simpleã¯ãè¦åãæãã¦ã +255ãã§çµãã¾ãã +å ¨ã¦ã®ãã¹ããã¡ããã¨å®å ¨ã«ãããå¾ã§ãããã¹ããæ»ãã° +ããããã¾ã 失æã§ããã¨èãããã255ã§çµãã¾ãã + +=begin original + +So the exit codes are... + +=end original + +ã¤ã¾ããçµäºã³ã¼ãã¯â¦ + + 0 å ¨ã¦ã®ãã¹ããæå + 255 ãã¹ããæ»ãã ãå ¨é¨éã£ããä½ããããã # ãã¹ãã®å®è¡ã«ã¤ã㦠+ any other number ããã¤å¤±æããã(足ããªããã®ãä½è¨ãªãã®ãå«ã) + +=begin original + +If you fail more than 254 tests, it will be reported as 254. + + +=end original + +254以ä¸ã®ãã¹ãã失æããå ´åã¯ã254ã¨ãã¦ãå ±åããã¾ãã + +=begin original + +This module is by no means trying to be a complete testing system. +It's just to get you started. Once you're off the ground its +recommended you look at L<Test::More>. + +=end original + +ãã®ã¢ã¸ã¥ã¼ã«ã¯ã決ãã¦ãå®å ¨ãªãã¹ãã·ã¹ãã ã§ãããã¨ã¯ãã¾ããã +ãã®ã¢ã¸ã¥ã¼ã«ã¯ããã ãããªãã«ãã¹ããå§ããããåã£æãã«ããã¾ããã +ä¸æ¦ãã¹ããå§ãããªãã°ãL<Test::More>ãè¦ããã¨ãã奨ããã¾ãã + +=head1 EXAMPLE + +(ä¾) + +=begin original + +Here's an example of a simple .t file for the fictional Film module. + +=end original + +æ¶ç©ºã®Filmã¢ã¸ã¥ã¼ã«ã®ããã®ç°¡åãªã.t ãã¡ã¤ã«ã®ä¾ãããã¾ãã + + use Test::Simple tests => 5; + + use Film; # What you're testing. + + my $btaste = Film->new({ Title => 'Bad Taste', + Director => 'Peter Jackson', + Rating => 'R', + NumExplodingSheep => 1 + }); + ok( defined($btaste) && ref $btaste eq 'Film', 'new() works' ); + + ok( $btaste->Title eq 'Bad Taste', 'Title() get' ); + ok( $btaste->Director eq 'Peter Jackson', 'Director() get' ); + ok( $btaste->Rating eq 'R', 'Rating() get' ); + ok( $btaste->NumExplodingSheep == 1, 'NumExplodingSheep() get' ); + +=begin original + +It will produce output like this: + +=end original + +ããã¯ããã®ããã«åºåãã¾ã: + + 1..5 + ok 1 - new() works + ok 2 - Title() get + ok 3 - Director() get + not ok 4 - Rating() get + # Failed test 'Rating() get' + # in t/film.t at line 14. + ok 5 - NumExplodingSheep() get + # Looks like you failed 1 tests of 5 + +=begin original + +Indicating the Film::Rating() method is broken. + +=end original + +Film::Rating()ã¡ã½ãããå£ãã¦ããäºã示ãã¦ãã¾ãã + +=head1 CAVEATS + +(è¦å) + +=begin original + +Test::Simple will only report a maximum of 254 failures in its exit +code. If this is a problem, you probably have a huge test script. +Split it into multiple files. (Otherwise blame the Unix folks for +using an unsigned short integer as the exit status). + +=end original + +Test::Simpleã¯ããã®çµäºã³ã¼ãã§ãæ大ã§254ã®å¤±æãå ±åããã ãã§ãã +ãã®ãã¨ãåé¡ã«ãªãã®ãªãããããããè«å¤§ãªãã¹ãscriptãªã®ã§ãããã +ãã®ãã¹ãscriptãè¤æ°ã®ãã¡ã¤ã«ã«åå²ãã¦ä¸ããã +(ãããã¯ãçµäºç¶æ ã¨ãã¦ã符å·ãªãã®çãæ´æ°ã使ãUNIXã®äººã ãéé£ãã¦ä¸ãã) + +=begin original + +Because VMS's exit codes are much, much different than the rest of the +universe, and perl does horrible mangling to them that gets in my way, +it works like this on VMS. + +=end original + +VMSã®çµäºã³ã¼ãã¯ãã以å¤ã®ä¸çã¨ã¯ããã£ã¨ããã£ã¨éã£ã¦ããã +èªåã®ããæ¹ãå¾ã¦ããPerlã¯æããããã®çµäºã³ã¼ããæ¼ãã¤ã¶ãã®ã§ã +VMSã§ã¯ã次ã®ããã«åãã¾ãã + + 0 SS$_NORMAL å ¨ã¦ã®ãã¹ãã¯æå + 4 SS$_ABORT ä½ããééã£ã¦ãã¾ã + +=begin original + +Unfortunately, I can't differentiate any further. + +=end original + +æ®å¿µãªãã¨ã«ããã以ä¸åãåãã§ãã¾ããã + +=head1 NOTES + +(注æ) + +=begin original + +Test::Simple is B<explicitly> tested all the way back to perl 5.6.0. + +=end original + +Test::Simpleã¯ãperl 5.6.0 ã¾ã§ãB<ã¯ã£ããã¨>ãã¹ãããã¾ãã + +=begin original + +Test::Simple is thread-safe in perl 5.8.1 and up. + +=end original + +Test::Simple ã¯ãperl 5.8.1 以ä¸ã§ãã¹ã¬ããã»ã¼ãã§ãã + +=head1 HISTORY + +(çµç·¯) + +=begin original + +This module was conceived while talking with Tony Bowden in his +kitchen one night about the problems I was having writing some really +complicated feature into the new Testing module. He observed that the +main problem is not dealing with these edge cases but that people hate +to write tests B<at all>. What was needed was a dead simple module +that took all the hard work out of testing and was really, really easy +to learn. Paul Johnson simultaneously had this idea (unfortunately, +he wasn't in Tony's kitchen). This is it. + +=end original + +ãã®ã¢ã¸ã¥ã¼ã«ã¯ãããå¤ãTony Bowden ã¨ä¸ç·ã«ãå½¼ã®å®¶ã®ãããã³ã§ã +ç§ã®æ±ãã¦ããæ°ãããã¹ãã®ã¢ã¸ã¥ã¼ã«ã«æ¬å½ã«è¤éãªç¹å¾´ãæ¸ãã¨ããåé¡ã«ã¤ãã¦è©±ãã¦ããéä¸ã«ãæãã¤ãã¾ããã +å½¼ã¯ã主ãªåé¡ã¯ããããã®ã¨ãã¸ã±ã¼ã¹ãå¦çãããã¨ã§ã¯ãªãã +人ã ããã¹ããæ¸ãã®ãå«ã£ã¦ããäºã«ã¤ããã¨è¦ã¦ãã¾ããã +å¿ è¦ã¨ããã¦ããã®ã¯ããã¹ããããå ¨ã¦ã®ãã¤ãä»äºãåãåºãããå®ã«ãæ¬å½ã«ãå¦ã³ãããã +å ¨ãç°¡åãªã¢ã¸ã¥ã¼ã«ã§ãããPaul Johnsonã¯ãåæã«ãã®ã¢ã¤ãã£ã¢ãæã£ã¦ãã¾ãã(ããä¸å¹¸ãªãã¨ã«ãããã¯ãTonyã®ãããã³ã«ããªãã£ã)ã +ãããããããã®ã¾ã£ããç°¡åãªãã¹ãã®ã¢ã¸ã¥ã¼ã«ã§ãã + +=head1 SEE ALSO + +=over 4 + +=item L<Test::More> + +=begin original + +More testing functions! Once you outgrow Test::Simple, look at +Test::More. Test::Simple is 100% forward compatible with Test::More +(i.e. you can just use Test::More instead of Test::Simple in your +programs and things will still work). + +=end original + +ãã¹ãã®æ©è½ãããå¤ãï¼Test::Simpleãåæ¥ããããTest::Moreãè¦ã¦ãã ããã +Test::Simpleã¯ãTest::Moreã§ã100%äºææ§ãããã¾ãã +(ãã¨ãã°ãããã°ã©ã ã§ãTest::Simpleã®ä»£ããã«ãTest::Moreã使ããã¨ãåºæ¥ã¾ããã +ããã¯ãã®ã¾ã¾åãã¾ãã) + +=item L<Test> + +ãªãªã¸ãã«ã®Perlã®ãã¹ãã¢ã¸ã¥ã¼ã«ã + +=item L<Test::Unit> + +ã¦ããããã¹ããå ¥å¿µã«ãã¾ãã + +=item L<Test::Inline>, L<SelfTest> + +ããªãã®ã³ã¼ãä¸ã«ããã¹ããå«ãã¾ã! + +=item L<Test::Harness> + +ãã¹ãããã°ã©ã ã®åºåã解éãã¾ãã + +=back + +=begin original + +Look in Test::More's SEE ALSO for more testing modules. + +=end original + +Test::Moreã® SEE ALSO ã«ã¯ãããå¤ãã®ãã¹ãã¢ã¸ã¥ã¼ã«ãããã¾ãã + + +=head1 AUTHORS + +Idea by Tony Bowden and Paul Johnson, code by Michael G Schwern +E<lt>schwe****@pobox*****<gt>, wardrobe by Calvin Klein. + +=head1 COPYRIGHT + +Copyright 2001-2008 by Michael G Schwern E<lt>schwe****@pobox*****<gt>. + +This program is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. + +See F<http://www.perl.com/perl/misc/Artistic.html> Index: docs/modules/Test-Simple-0.99/lib/Test/Tutorial.pod diff -u /dev/null docs/modules/Test-Simple-0.99/lib/Test/Tutorial.pod:1.1 --- /dev/null Sun Nov 10 14:17:31 2013 +++ docs/modules/Test-Simple-0.99/lib/Test/Tutorial.pod Sun Nov 10 14:17:31 2013 @@ -0,0 +1,1131 @@ +=encoding utf8 + +=head1 NAME + +=begin original + +Test::Tutorial - A tutorial about writing really basic tests + +=end original + +Test::Tutorial - ããåºæ¬çãªãã¹ããæ¸ããã¨ã«ã¤ãã¦ã®ãã¥ã¼ããªã¢ã« + +=head1 DESCRIPTION + +=begin original + +I<AHHHHHHH!!!! NOT TESTING! Anything but testing! +Beat me, whip me, send me to Detroit, but don't make +me write tests!> + +=end original + +I<ãã¼ã¼ã¼ã¼ã¼!!!!ãã¹ãã¯å«! ä½ãããã¦ããã¹ãã¯å«! +ã¶ã£ã¦ãããã¡æã£ã¦ãããããã¤ãã«éã£ã¦ããããã©ã +ãã¹ããæ¸ãããªãã§!> + +=begin original + +I<*sob*> + +=end original + +I<*ãããã*> + +=begin original + +I<Besides, I don't know how to write the damned things.> + +=end original + +I<ãã¾ãã«ããããªå¿ã¾ããããã®ã®æ¸ãæ¹ãªã©ç¥ãã¾ããã> + +=begin original + +Is this you? Is writing tests right up there with writing +documentation and having your fingernails pulled out? Did you open up +a test and read + +=end original + +ããªãã¯ãããªäººã§ãã? +ãã¹ããæ¸ããã¨ã¯ãã¡ããã©ãããã¥ã¡ã³ããæ¸ããæã®çªãå¼ãæããã¨ã§ãã? +ãã¹ããéããèªã¿ã + +=begin original + + ######## We start with some black magic + +=end original + + ######## ããã¤ãã®é»éè¡ãå§ãã¾ãã + + +=begin original + +and decide that's quite enough for you? + +=end original + +ãã¹ãã¯ããããããã ã¨å¤æãã¾ããï¼ + +=begin original + +It's ok. That's all gone now. We've done all the black magic for +you. And here are the tricks... + +=end original + +ããã§ããããå ¨ã¦ã¯è¡ã£ã¦ãã¾ãã¾ãããããªãã®ããã«ãé»éè¡ããã¹ã¦è¡ãã¾ãã +ããã«ãã®ä»æããããã¾ã⦠+ +=head2 Nuts and bolts of testing. + +(ãã¹ãã®åºæ¬) + +=begin original + +Here's the most basic test program. + +=end original + +æãåºæ¬çãªãã¹ãã®ããã°ã©ã ã + + #!/usr/bin/perl -w + + print "1..1\n"; + + print 1 + 1 == 2 ? "ok 1\n" : "not ok 1\n"; + +=begin original + +Because 1 + 1 is 2, it prints: + +=end original + +1 + 1 㯠2ã§ãããã次ã®ããã«è¡¨ç¤ºãã¾ã: + + 1..1 + ok 1 + +=begin original + +What this says is: C<1..1> "I'm going to run one test." [1] C<ok 1> +"The first test passed". And that's about all magic there is to +testing. Your basic unit of testing is the I<ok>. For each thing you +test, an C<ok> is printed. Simple. L<Test::Harness> interprets your test +results to determine if you succeeded or failed (more on that later). + +=end original + +ãã®ã³ã¼ãã®æå³ï¼ C<1..1>[1]ãä¸ã¤ã®ãã¹ããè¡ãã¾ãããC<ok 1>ãæåã®ãã¹ãã¯ãã¹ãã¾ãããã +ããã¦ããããããã¹ãã®éæ³ã®ã»ã¨ãã©å ¨é¨ã§ããåºæ¬çãªã¦ãããã®ãã¹ãã¯I<ok>ã§ãã +L<Test::Harness>ã¯ããã¹ãã®çµæã解éããæåããã失æããããå¤æãã¾ã(å¾ã§ã¯ããã£ã¨å¤æãã¾ã)ã + +=begin original + +Writing all these print statements rapidly gets tedious. Fortunately, +there's L<Test::Simple>. It has one function, C<ok()>. + +=end original + +ãããã®ã³ã¼ããå ¨é¨æ¸ãã®ã¯ãããã«é£½ãã¦ãã¾ãã¾ãã +ã§ããã幸éãªãã¨ã«ãL<Test::Simple>ãããã¾ããããã«ã¯ãC<ok()>ã¨ããä¸ã¤ã®é¢æ°ãããã¾ãã + + #!/usr/bin/perl -w + + use Test::Simple tests => 1; + + ok( 1 + 1 == 2 ); + +=begin original + +That does the same thing as the previous code. C<ok()> is the backbone +of Perl testing, and we'll be using it instead of roll-your-own from +here on. If C<ok()> gets a true value, the test passes. False, it +fails. + +=end original + +ããã¯ä¸ã®ã³ã¼ãã¨åããã¨ããã¾ããC<ok()>ã¯ãPerlã®ãã¹ãã®ä¸å¿ã§ãã +ããããã¯ãèªåã§æ¸ã代ããã«ãC<ok()>ã使ãã¾ãã +C<ok()> ãçãè¿ãã°ããã¹ãã¯åæ ¼ã§ããå½ã§ããã°ã失æã§ã. + + #!/usr/bin/perl -w + + use Test::Simple tests => 2; + ok( 1 + 1 == 2 ); + ok( 2 + 2 == 5 ); + +=begin original + +From that comes: + +=end original + +ãã®ã³ã¼ãããã + + 1..2 + ok 1 + not ok 2 + # Failed test (test.pl at line 5) + # Looks like you failed 1 tests of 2. + +=begin original + +C<1..2> "I'm going to run two tests." This number is a I<plan>. It helps to +ensure your test program ran all the way through and didn't die or skip some +tests. C<ok 1> "The first test passed." C<not ok 2> "The second test failed". +Test::Simple helpfully prints out some extra commentary about your tests. + +=end original + +C<1..2> ãäºã¤ã®ãã¹ããè¡ãã¾ãã +ãã®çªå·ã¯ããã¹ãããã°ã©ã ãæåããæå¾ã¾ã§å®è¡ããããã¨ãä¿è¨¼ãã +æ»ãã ããããã¤ãã®ãã¹ããã¹ãããããããã¦ããªããã¨ãä¿è¨¼ããå©ãã«ãªãã¾ãã +C<ok 1>ãæåã®ãã¹ãã¯ãã¹ãã¾ãããã C<not ok 2> ã2çªç®ã®ãã¹ãã¯å¤±æãã¾ãããã +Test::Simple ã¯ãã¹ãã«ã¤ãã¦ã®æç¨ãªç¹å¥ã®ã³ã¡ã³ããåºåãã¾ãã + +=begin original + +It's not scary. Come, hold my hand. We're going to give an example +of testing a module. For our example, we'll be testing a date +library, L<Date::ICal>. It's on CPAN, so download a copy and follow +along. [2] + +=end original + +æãã¯ããã¾ãããããã£ã¡ã¸ãã¦ãæãåã£ã¦ãã¢ã¸ã¥ã¼ã«ããã¹ãããä¾ãã¿ãã¾ãããã +ãã®ä¾ã«ãæ¥ä»ã®ã©ã¤ãã©ãªã§ãããB<Date::ICal>ãããã¹ããã¾ãã +B<Date::ICal>ã¯ãCPANã«ããã¾ãã®ã§ãã³ãã¼ããã¦ã³ãã¼ããã¦ãé²ãã§ä¸ãã[2]ã + +=head2 Where to start? + +(ã©ãããã¯ããã¾ããã?) + +=begin original + +This is the hardest part of testing, where do you start? People often get +overwhelmed at the apparent enormity of the task of testing a whole module. +The best place to start is at the beginning. C<Date::ICal> is an +object-oriented module, and that means you start by making an object. Test +C<new()>. + +=end original + +ããããã¹ãã®ä¸çªé£ããã¨ããã§ã.ã©ãããã¯ããã¾ããã? +ã¢ã¸ã¥ã¼ã«ã®å ¨ã¦ããã¹ããããã¨ã¯ãæããã«å¤§ããªä»äºã§ãããå§åããã¾ãã +æãè¯ãã®ã¯ãæåã¯ããã¯ããããã¨ã§ã. +C<Date::ICal> ã¯ããªãã¸ã§ã¯ãæåã®ã¢ã¸ã¥ã¼ã«ã§ããã§ãããããªãã¸ã§ã¯ããä½ããã¨ããã¯ãããã°ããã +ãããC<new()>ããã¹ããã¾ãããã + + #!/usr/bin/perl -w + + # assume these two lines are in all subsequent examples + use strict; + use warnings; + + use Test::Simple tests => 2; + + use Date::ICal; + + my $ical = Date::ICal->new; # ãªãã¸ã§ã¯ããä½æã + ok( defined $ical ); # ä½ããå¾ããããã¹ãã + ok( $ical->isa('Date::ICal') ); # ããã¦ãæ£ããã¯ã©ã¹ããã¹ããã¾ã + +=begin original + +Run that and you should get: + +=end original + +ãããå®è¡ããã¨ã以ä¸ã®ããã«ãªãã¾ã: + + 1..2 + ok 1 + ok 2 + +=begin original + +Congratulations! You've written your first useful test. + +=end original + +ããã§ã¨ã! æåã®æçãªãã¹ããæ¸ãã¾ããã + +=head2 Names + +(åå) + +=begin original + +That output isn't terribly descriptive, is it? When you have two tests you can +figure out which one is #2, but what if you have 102 tests? + +=end original + +ãã®åºåã¯ãå ¨ç¶è¨è¿°çãããªãã§ãã? +2ã¤ãããã¹ããç¡ããªãããã®ãã¡ã®ä¸ã¤ã2çªç®ã®ãã®ã ã¨åããã¾ããã +102ããã¹ãããã£ãããã©ãã§ãããï¼ + +=begin original + +Each test can be given a little descriptive name as the second +argument to C<ok()>. + +=end original + +ããããã®ãã¹ãã«ã¯ãã¡ãã£ã¨ããè¨è¿°çãªååã2çªç®ã®å¼æ°ã¨ãã¦ã +C<ok()>ã«ä¸ãããã¨ãåºæ¥ã¾ãã + + use Test::Simple tests => 2; + + ok( defined $ical, 'new() returned something' ); + ok( $ical->isa('Date::ICal'), " and it's the right class" ); + +=begin original + +Now you'll see: + +=end original + +ä»åº¦ã¯æ¬¡ã®ããã«ãªãã¾ã: + + 1..2 + ok 1 - new() returned something + ok 2 - and it's the right class + + +=head2 Test the manual + +(ããã¥ã¢ã«ã®ãã¹ã) + +=begin original + +The simplest way to build up a decent testing suite is to just test what +the manual says it does. [3] Let's pull something out of the +L<Date::ICal/SYNOPSIS> and test that all its bits work. + +=end original + +ãã£ã¨ãç°¡åã«ãã¡ãã¨ãããã¹ããä½ãæ¹æ³ã¯ããã ããã¥ã¢ã«ã«æ¸ããã¦ãããã¨ããã¹ããã¾ã[3]ã +L<Date::ICal/SYNOPSIS>ããä½ããå¼ãã¦ãã¦ããããå ¨ã¦ãã¹ããã¾ããããã¡ãã£ã¨ãããã¨ã§ãã + + #!/usr/bin/perl -w + + use Test::Simple tests => 8; + + use Date::ICal; + + $ical = Date::ICal->new( year => 1964, month => 10, day => 16, + hour => 16, min => 12, sec => 47, + tz => '0530' ); + + ok( defined $ical, 'new() returned something' ); + ok( $ical->isa('Date::ICal'), " and it's the right class" ); + ok( $ical->sec == 47, ' sec()' ); + ok( $ical->min == 12, ' min()' ); + ok( $ical->hour == 16, ' hour()' ); + ok( $ical->day == 17, ' day()' ); + ok( $ical->month == 10, ' month()' ); + ok( $ical->year == 1964, ' year()' ); + +=begin original + +Run that and you get: + +=end original + +å®è¡ããã¨ã次ã®ããã«ãªãã¾ã: + + 1..8 + ok 1 - new() returned something + ok 2 - and it's the right class + ok 3 - sec() + ok 4 - min() + ok 5 - hour() + not ok 6 - day() + # Failed test (- at line 16) + ok 7 - month() + ok 8 - year() + # Looks like you failed 1 tests of 8. + +=begin original + +Whoops, a failure! [4] C<Test::Simple> helpfully lets us know on what line the +failure occurred, but not much else. We were supposed to get 17, but we +didn't. What did we get?? Dunno. You could re-run the test in the debugger +or throw in some print statements to find out. + +=end original + +ãã¼ã£ã¨ã失æ![4] C<Test::Simple>ã¯ãå½¹ã«ç«ã¤ãã¨ã«ãä½è¡ç®ã§å¤±æããã®ããç¥ããã¦ããã¾ãã +ããã©ãä»ã«ã¯ä½ãç¥ããã¾ããã17ãå¾ãªããã°ãªããªãã£ãã®ã§ãããããã¯ãªãã¾ããã§ãããä½ãå¾ãã®ã§ãããã?? +ãããã¾ããããããè¦ã¤ããã«ã¯ããããã¬ã¼ã§ãã¹ããåå®è¡ããªããã°ãªããããprintæã«æããªããã°ãªãã¾ããã + +=begin original + +Instead, switch from L<Test::Simple> to L<Test::More>. C<Test::More> +does everything C<Test::Simple> does, and more! In fact, C<Test::More> does +things I<exactly> the way C<Test::Simple> does. You can literally swap +C<Test::Simple> out and put C<Test::More> in its place. That's just what +we're going to do. + +=end original + +ãã®ä»£ããã«ãL<Test::Simple>ãããL<Test::More>ã«ããããã¾ãããã +C<Test::More> ã¯ã C<Test::Simple>ã®è¡ãå ¨ã¦ã®ãã¨ãè¡ãããããã£ã¨è¡ãã¾ã! +å®éãTest::Moreã¯ãC<Test::Simple>ãè¡ãæ¹æ³ãI<æ£ç¢ºã«>è¡ãã¾ãã +æåéããC<Test::Simple>ãåãå¤ããC<Test::More>ãããã«ç½®ããã¨ãåºæ¥ã¾ãã +ã¡ããã©ããããã¨ãã¦ãããã¨ã§ãã + +=begin original + +C<Test::More> does more than C<Test::Simple>. The most important difference at +this point is it provides more informative ways to say "ok". Although you can +write almost any test with a generic C<ok()>, it can't tell you what went +wrong. The C<is()> function lets us declare that something is supposed to be +the same as something else: + +=end original + +C<Test::More> ã¯ãC<Test::Simple>ãããåãã¾ããæãéè¦ãªéãã¯ã +Test::Moreã¯ããåèã«ãªãããã«ãokãã¨è¨ãç¹ã§ãã +ä¸è¬çãªC<ok()>ã§ã»ã¨ãã©ãã¹ã¦ã®ãã¹ããæ¸ããã¨ãåºæ¥ã¾ããã +C<ok()>ã§ã¯ãä½ãééã£ã¦ããã®ããããã¾ããã +代ããã«ãC<is()>é¢æ°ã使ãã¾ããããC<is()>ã¯ã +ãããã®ãä»ã®ãã®ã¨åãã§ããã¨æãããã¨ç§ãã¡ã«å®£è¨ããã¾ã: + + + use Test::More tests => 8; + + use Date::ICal; + + $ical = Date::ICal->new( year => 1964, month => 10, day => 16, + hour => 16, min => 12, sec => 47, + tz => '0530' ); + + ok( defined $ical, 'new() returned something' ); + ok( $ical->isa('Date::ICal'), " and it's the right class" ); + is( $ical->sec, 47, ' sec()' ); + is( $ical->min, 12, ' min()' ); + is( $ical->hour, 16, ' hour()' ); + is( $ical->day, 17, ' day()' ); + is( $ical->month, 10, ' month()' ); + is( $ical->year, 1964, ' year()' ); + +=begin original + +"Is C<$ical-E<gt>sec> 47?" "Is C<$ical-E<gt>min> 12?" With C<is()> in place, +you get more information: + +=end original + +"C<$ical-E<gt>sec> 㯠47?" "C<$ical-E<gt>min> 㯠12?" 代ããã«ãC<is()>ã使ããã¨ã§ã +ããå¤ãã®æ å ±ãå¾ããã¨ãã§ãã¾ã: + + 1..8 + ok 1 - new() returned something + ok 2 - and it's the right class + ok 3 - sec() + ok 4 - min() + ok 5 - hour() + not ok 6 - day() + # Failed test (- at line 16) + # got: '16' + # expected: '17' + ok 7 - month() + ok 8 - year() + # Looks like you failed 1 tests of 8. + +=begin original + +Aha. C<$ical-E<gt>day> returned 16, but we expected 17. A +quick check shows that the code is working fine, we made a mistake +when writing the tests. Change it to: + +=end original + +ãã¯ãC<$ical-E<gt>day>ã¯ã16ãè¿ãã¾ããããæå¾ ãã¦ããã®ã¯ã17ã§ãã£ãã¨ç¥ããã¾ãã +ç´ æ©ããã§ãã¯ã«ããããã®ã³ã¼ãããã¾ãåããããã¹ããæ¸ãä¸ããã¨ãã«ãã¹ããããã示ãã¾ãã +ãããå¤ãã¾ãããï¼ + + is( $ical->day, 16, ' day()' ); + +=begin original + +... and everything works. + +=end original + +... ããã§ãå ¨é¨åãã¾ãã + +=begin original + +Any time you're doing a "this equals that" sort of test, use C<is()>. +It even works on arrays. The test is always in scalar context, so you +can test how many elements are in an array this way. [5] + +=end original + +ãããã¯ãããã§ãããã¨è¨ã£ã種é¡ã®ãã¹ããããã¨ãã¯ãã¤ããC<is>ã使ãã¨ããã§ãã +C<is>ã¯ãé åã§ãåãã¾ãããã ããã¹ãã¯ãã¤ãã«ãã¹ã«ã©ã¼ã³ã³ããã¹ãã§åãã®ã§ã +次ã®æ¹æ³ã§ãé åã®ä¸ã®è¦ç´ ãããã¤ãããããã¹ãã§ãã¾ã[5]ã + + is( @foo, 5, 'foo has 5 elements' ); + + +=head2 Sometimes the tests are wrong + +(ãã¹ãã¯ééã£ã¦ããæããã) + +=begin original + +This brings up a very important lesson. Code has bugs. Tests are +code. Ergo, tests have bugs. A failing test could mean a bug in the +code, but don't discount the possibility that the test is wrong. + +=end original + +ééãã¯ãã¨ã¦ã大åãªã¬ãã¹ã³ã«ãªãã¾ããã³ã¼ãã«ã¯ãã°ãããããã¹ãã¯ã³ã¼ãã§ããã +ããã«ããã¹ãã«ã¯ãã°ãããã失æãããã¹ãã¯ãã³ã¼ãã«ãã°ããããã¨ãæå³ãã¾ãã +ãããããã¹ããééã£ã¦ããå¯è½æ§ãæé¤ãã¦ã¯ãªãã¾ããã + +=begin original + +On the flip side, don't be tempted to prematurely declare a test +incorrect just because you're having trouble finding the bug. +Invalidating a test isn't something to be taken lightly, and don't use +it as a cop out to avoid work. + +=end original + +åé¢ãææå°æ©ã«ããã ããã°ãè¦ã¤ããã®ã«è¦å´ãã¦ããããã¨ãã£ã¦ã +ãã¹ããä¸æ£ç¢ºã§ããã¨æè¨ãããã¨ããèªæã«ããããªãããã«ã +ãã¹ããç¡å¹ã«ãããã¨ã¯ãæéã«ã¨ãããã®ã§ã¯ããã¾ããããä»äºããéãã¦ãé¿ããããã«ã +ãã¹ããç¡å¹ã«ãã¦ã¯ããã¾ããã + +=head2 Testing lots of values + +(ããããã®å¤ã®ãã¹ã) + +=begin original + +We're going to be wanting to test a lot of dates here, trying to trick +the code with lots of different edge cases. Does it work before 1970? +After 2038? Before 1904? Do years after 10,000 give it trouble? +Does it get leap years right? We could keep repeating the code above, +or we could set up a little try/expect loop. + +=end original + +å¤ãã®éã£ãã¨ãã¸ã±ã¼ã¹ã§ã³ã¼ãããã¹ããããã¨ããã¨ããå¤ãã®å¤ããã¹ããããã¨æãã¾ãã +1970年以åã§ã¯ãåãã ãããï¼2038å¹´ã®å¾ã¯ï¼1904年以åã¯ï¼10,000å¹´å¾ã«ããã©ãã«ãèµ·ãããï¼ +éå¹´ãæ£ããå¾ããããï¼ +ä¸ã®ã³ã¼ããç¹°ãè¿ãç¶ããããã«ã¼ãã試ã¿ããããæå¾ ãããã¨ãåºæ¥ã¾ãã + + use Test::More tests => 32; + use Date::ICal; + + my %ICal_Dates = ( + # An ICal string And the year, month, day + # hour, minute and second we expect. + '19971024T120000' => # from the docs. + [ 1997, 10, 24, 12, 0, 0 ], + '20390123T232832' => # after the Unix epoch + [ 2039, 1, 23, 23, 28, 32 ], + '19671225T000000' => # before the Unix epoch + [ 1967, 12, 25, 0, 0, 0 ], + '18990505T232323' => # before the MacOS epoch + [ 1899, 5, 5, 23, 23, 23 ], + ); + + + while( my($ical_str, $expect) = each %ICal_Dates ) { + my $ical = Date::ICal->new( ical => $ical_str ); + + ok( defined $ical, "new(ical => '$ical_str')" ); + ok( $ical->isa('Date::ICal'), " and it's the right class" ); + + is( $ical->year, $expect->[0], ' year()' ); + is( $ical->month, $expect->[1], ' month()' ); + is( $ical->day, $expect->[2], ' day()' ); + is( $ical->hour, $expect->[3], ' hour()' ); + is( $ical->min, $expect->[4], ' min()' ); + is( $ical->sec, $expect->[5], ' sec()' ); + } + +=begin original + +Now we can test bunches of dates by just adding them to +C<%ICal_Dates>. Now that it's less work to test with more dates, you'll +be inclined to just throw more in as you think of them. +Only problem is, every time we add to that we have to keep adjusting +the C<use Test::More tests =E<gt> ##> line. That can rapidly get +annoying. There are ways to make this work better. + +=end original + +ä»ãããã ãC<%ICal_Dates>ã«æ¥ä»ã®æãå ããã ãã§ããã¹ãã§ãã¾ãã +ãã¦ãããããã®æ¥ä»ããã¹ãããã®ãå°ãªãä»äºã«ãªãã¾ãããã +èããããã«ããã ãæ¥ä»ãæããã ãã«ãããããããã¾ããã +å¯ä¸ã®åé¡ã¯ãæ¯åãC<use Test::More tests =E<gt> ##> ã®è¡ãã調ç¯ããªããã°ãªããªãäºã§ãã +ãã®ãã¨ã¯ãæ¥éã«ç ©éã«ãªãã§ããããããã¤ãã®æ¹æ³ã§ããã£ã¨ãã¾ãããã¾ãã + +=begin original + +First, we can calculate the plan dynamically using the C<plan()> +function. + +=end original + +ä¸ã¤ãã®æ¹æ³ã¯ãC<plan()>é¢æ°ãåçã«ä½¿ã£ã¦ãè¨ç»ãè¨ç®ãã¾ãã + + use Test::More; + use Date::ICal; + + my %ICal_Dates = ( + ...same as before... + ); + + # For each key in the hash we're running 8 tests. + plan tests => keys(%ICal_Dates) * 8; + + ...and then your tests... + +=begin original + +To be even more flexible, use C<done_testing>. This means we're just +running some tests, don't know how many. [6] + +=end original + +ãããã¬ãã·ãã«ã«ãC<done_testing> ã使ãã¾ããããã«ããã +ããã¤ãã®ãã¹ãããã èµ°ããã¾ããããã¤ãªã®ãã¯ç¥ãã¾ãã[6]ã + + use Test::More; # instead of tests => 32 + + ... # tests here + + done_testing(); # reached the end safely + +=begin original + +If you don't specify a plan, C<Test::More> expects to see C<done_testing()> +before your program exits. It will warn you if you forget it. You can give +C<done_testing()> an optional number of tests you expected to run, and if the +number ran differs, C<Test::More> will give you another kind of warning. + +=end original + +ãã©ã³ãç¹å®ããªãã¨ãC<Test::More>ã¯ãããã°ã©ã ãçµäºããåã«ã +C<done_testing()>ãããã¨æå¾ ãã¾ãããããæ¸ãå¿ãã¦ããã°è¦åãã¾ãã +C<done_testing()>ã«ãå®è¡ãããäºå®ã®ãã¹ãã®æ°ã渡ããã¨ãã§ãã¾ãã +åããæ°ãéã£ã¦ããã°ãC<Test::More>ã¯ãå¥ã®ç¨®é¡ã®è¦åãåºã¾ãã + +=head2 Informative names + +(æçãªåå) + +=begin original + +Take a look at the line: + +=end original + +次ã®è¡ãã¿ã¦ãã ãã + + + ok( defined $ical, "new(ical => '$ical_str')" ); + +=begin original + +We've added more detail about what we're testing and the ICal string +itself we're trying out to the name. So you get results like: + +=end original + +ãã¹ããã¦ãããã¨ã¨ããã¹ããã¦ãã ICal ã¹ããªã³ã°èªèº«ã®è©³ç´°ããååã«å ãã¾ãã +次ã®ãããªçµæãåºã¾ãï¼ + + ok 25 - new(ical => '19971024T120000') + ok 26 - and it's the right class + ok 27 - year() + ok 28 - month() + ok 29 - day() + ok 30 - hour() + ok 31 - min() + ok 32 - sec() + +=begin original + +If something in there fails, you'll know which one it was and that +will make tracking down the problem easier. Try to put a bit of +debugging information into the test names. + +=end original + +失æã®ä¸ã«ä½ããããªãããããä¸ã¤ã§ãããããã«ãã£ã¦ãåé¡ã追跡ããã®ãç°¡åã«ãªããã¨ããããã§ãããã +ã¡ãã£ã¨ãããããã°æ å ±ããã¹ãã®ååã«å ¥ãã¦ã¿ã¦ä¸ããã + +=begin original + +Describe what the tests test, to make debugging a failed test easier +for you or for the next person who runs your test. + +=end original + +ãã®ãã¹ããä½ããã¹ãããããè¨è¿°ãã¦ããã°ã +失æãããã¹ãããããã°ããéãèªåãä»ã®äººããã¹ããå®è¡ããã®ããç°¡åã«ãªãã¾ãã + +=head2 Skipping tests + +(ãã¹ããã¹ããããã) + +=begin original + +Poking around in the existing Date::ICal tests, I found this in +F<t/01sanity.t> [7] + +=end original + +Date::ICal ã§ç¨æããã¦ãããã¹ããæ¢ãåã£ã¦ãF<t/01sanity.t>ã«ã次ã®ãã®ãè¦ã¤ãã¾ãã[7]ã + + #!/usr/bin/perl -w + + use Test::More tests => 7; + use Date::ICal; + + # Make sure epoch time is being handled sanely. + my $t1 = Date::ICal->new( epoch => 0 ); + is( $t1->epoch, 0, "Epoch time of 0" ); + + # XXX This will only work on unix systems. + is( $t1->ical, '19700101Z', " epoch to ical" ); + + is( $t1->year, 1970, " year()" ); + is( $t1->month, 1, " month()" ); + is( $t1->day, 1, " day()" ); + + # like the tests above, but starting with ical instead of epoch + my $t2 = Date::ICal->new( ical => '19700101Z' ); + is( $t2->ical, '19700101Z', "Start of epoch in ICal notation" ); + + is( $t2->epoch, 0, " and back to ICal" ); + +=begin original + +The beginning of the epoch is different on most non-Unix operating systems [8]. +Even though Perl smooths out the differences for the most part, certain ports +do it differently. MacPerl is one off the top of my head. [9] Rather than +putting a comment in the test and hoping someone will read the test while +debugging the failure, we can explicitly say it's never going to work and skip +the test. + +=end original + +ããã¦ãã®éUNIX OS ã§ã¯ãã¨ããã¯ã®å§ã¾ããç°ãªã£ã¦ãã¾ã[8]ã +ã»ã¨ãã©ã®é¨åã§Perlã¯ãå·®ç°ããªããã¦ãã¾ãããããé¨åã§ã¯ãéã£ãããã«è¡ãã¾ãã +ä»ãæ£ç¢ºã«ã¯æãåºãã¾ããããMacPerlã¯ãã®ä¸ã¤ã ã¨æãã¾ã[9]ã +ãã ãã¹ãã«ã³ã¡ã³ããæ¸ãã¦ã失æããããã°ãã¦ããéã«ã誰ãããã¹ãèªããã¨ã +æå¾ ããããããã¯ã£ããã¨ã決ãã¦åããªãããã«è¨ãããã¹ããã¹ããããããã¨ãåºæ¥ã¾ãã + + use Test::More tests => 7; + use Date::ICal; + + # Make sure epoch time is being handled sanely. + my $t1 = Date::ICal->new( epoch => 0 ); + is( $t1->epoch, 0, "Epoch time of 0" ); + + SKIP: { + skip('epoch to ICal not working on Mac OS', 6) + if $^O eq 'MacOS'; + + is( $t1->ical, '19700101Z', " epoch to ical" ); + + is( $t1->year, 1970, " year()" ); + is( $t1->month, 1, " month()" ); + is( $t1->day, 1, " day()" ); + + # like the tests above, but starting with ical instead of epoch + my $t2 = Date::ICal->new( ical => '19700101Z' ); + is( $t2->ical, '19700101Z', "Start of epoch in ICal notation" ); + + is( $t2->epoch, 0, " and back to ICal" ); + } + + +=begin original + +A little bit of magic happens here. When running on anything but MacOS, all +the tests run normally. But when on MacOS, C<skip()> causes the entire +contents of the SKIP block to be jumped over. It never runs. Instead, +C<skip()> prints special output that tells C<Test::Harness> that the tests have +been skipped. + +=end original + +ããã§ãã¡ãã£ã¨ããéæ³ãèµ·ãã¾ãã +MacOS以å¤ã§åããå ´å,å ¨ã¦ã®ãã¹ãã¯æ®éã«ãã¹ãããã¾ãã +ããããMacOSä¸ã®å ´åãC<skip()>ã«ãã£ã¦ãSKIPãããã¯ã®ä¸ã®å ¨ã¦ã®å 容ãé£ã°ããã¾ãã +決ãã¦åããã¨ã¯ããã¾ããã +ãããã«ãC<skip()>ã¯ãã¹ããã¹ãããããã¦ãããã¨ãTest::Harness ã«ä¼ããç¹å¥ãªåºåãããªã³ããã¾ãã + + 1..7 + ok 1 - Epoch time of 0 + ok 2 # skip epoch to ICal not working on MacOS + ok 3 # skip epoch to ICal not working on MacOS + ok 4 # skip epoch to ICal not working on MacOS + ok 5 # skip epoch to ICal not working on MacOS + ok 6 # skip epoch to ICal not working on MacOS + ok 7 # skip epoch to ICal not working on MacOS + +=begin original + +This means your tests won't fail on MacOS. This means fewer emails +from MacPerl users telling you about failing tests that you know will +never work. You've got to be careful with skip tests. These are for +tests which don't work and I<never will>. It is not for skipping +genuine bugs (we'll get to that in a moment). + +=end original + +ããã¯ãMacOSä¸ã§,ãã¹ãã¯å¤±æããªãã¨ããæå³ã§ãã +ããã§ãMacPerlã®ã¦ã¼ã¶ã¼ããã®ãåããªãã¨åãã£ã¦ãããã¹ããåããªãã¨å ±åããemailãããå°ãªããªãã¾ãã +ãã¹ãã®ã¹ãããã«ã¤ãã¦æ éã«ãªãããã«ãã¹ãããã®ãã¹ãã¯ãåããªããI<決ãã¦åããªã>ãã¹ãã«å¯¾ãã¦ãããã®ã§ãã +æ¬ç©ã®ãã°ãã¹ãããããçºã®ãã®ã§ã¯ããã¾ãã(ããã«ãããªãã§ããã)ã + +=begin original + +The tests are wholly and completely skipped. [10] This will work. + +=end original + +ãã®ãã¹ãã¯ãã¾ã£ãããå®å ¨ã«ã¹ãããããã¾ã[10]ã以ä¸ã®ã³ã¼ãã¯ãåãã¾ãã + + SKIP: { + skip("I don't wanna die!"); + + die, die, die, die, die; + } + + +=head2 Todo tests + +(ToDo ãã¹ã) + +=begin original + +While thumbing through the C<Date::ICal> man page, I came across this: + +=end original + +C<Date::ICal>ã®manãã¼ã¸ããã£ã¨ç®ãéãã¦ãã¦ã次ã®ãã®ã«ééãã¾ãã: + + ical + + $ical_string = $ical->ical; + + ãªãã¸ã§ã¯ãã®æ¥ä»ã®åå¾ãã¾ãã¯ãã»ããã + ãã¹ã¦ã®å¦¥å½ãª ICal date/time æååã使ã£ã¦ããªãã¸ã§ã¯ãã«æ¥ä»ãã»ããããã + +=begin original + +"Retrieves or sets". Hmmm. I didn't see a test for using C<ical()> to set +the date in the Date::ICal test suite. So I wrote one: + +=end original + +ãåå¾ã¾ãã¯ã»ãããããµããDate::ICalã®ãã¹ãã§ãæ¥ä»ãã»ããããC<ical()> ã使ããã¹ããè¦ã¾ããã§ããã +ç§ã¯ã次ã®ããã«æ¸ãã§ãããã + + use Test::More tests => 1; + use Date::ICal; + + my $ical = Date::ICal->new; + $ical->ical('20201231Z'); + is( $ical->ical, '20201231Z', 'Setting via ical()' ); + +=begin original + +Run that. I saw: + +=end original + +ãããå®è¡ããã¨: + + 1..1 + not ok 1 - Setting via ical() + # Failed test (- at line 6) + # got: '20010814T233649Z' + # expected: '20201231Z' + # Looks like you failed 1 tests of 1. + +=begin original + +Whoops! Looks like it's unimplemented. Assume you don't have the time to fix +this. [11] Normally, you'd just comment out the test and put a note in a todo +list somewhere. Instead, explicitly state "this test will fail" by wrapping it +in a C<TODO> block: + +=end original + +ãã¼ã£ã¨! å®è¡ãããªãããã ããã¦ããããä¿®æ£ããæéããªãã¨æ³å®ãã¾ãããã[11] +ãµã¤ãã¯ããã®ãã¹ããã³ã¡ã³ãã«ãã¦ãToDoãªã¹ãã«æ¸ãçãã¦ããã§ãããã +ãã®ä»£ããã«ãC<TODO>ãããã¯å ã§ã©ããã³ã°ãã¦ï¼å ãã§ï¼ãããã®ãã¹ãã失æãããã¨ããæãããªç¶æ ã«ãã¾ãããã + + use Test::More tests => 1; + + TODO: { + local $TODO = 'ical($ical) not yet implemented'; + + my $ical = Date::ICal->new; + $ical->ical('20201231Z'); + + is( $ical->ical, '20201231Z', 'Setting via ical()' ); + } + +=begin original + +Now when you run, it's a little different: + +=end original + +å®è¡ããã¨ãã¡ãã£ã¨ããéããããã¾ãï¼ + + 1..1 + not ok 1 - Setting via ical() # TODO ical($ical) not yet implemented + # got: '20010822T201551Z' + # expected: '20201231Z' + +=begin original + +C<Test::More> doesn't say "Looks like you failed 1 tests of 1". That '# +TODO' tells C<Test::Harness> "this is supposed to fail" and it treats a +failure as a successful test. You can write tests even before +you've fixed the underlying code. + +=end original + +C<Test::More>ã¯ããä¸ã¤ã®ãã¹ãã®ä¸ã®ä¸ã¤ã失æããããã ãã¨ã¯è¨ãã¾ããã +ãã®ã# TODOãã¯ãC<Test::Harness> ã«ãããã¯ã失æããã¨æããããã¨ä¼ãã +C<Test::Harness>ã¯ã失æãããã¹ããæåãããã¹ãã®ããã«æ±ãã¾ããããã§ã +ãã°ãä¿®æ£ããåã«ãã¹ããæ¸ããã¨ãã§ãã¾ãã + +=begin original + +If a TODO test passes, C<Test::Harness> will report it "UNEXPECTEDLY +SUCCEEDED". When that happens, remove the TODO block with C<local $TODO> and +turn it into a real test. + +=end original + +ãããTODOãã¹ãããã¹ããã¨ãTest::Harness ã¯ããã¹ããããæããããæåãããã¨å ±åãã¾ãã +ãããèµ·ããã°ãC<local $TODO>ã§TODOãããã¯ãå¤ãã¦ãæ¬å½ã®ãã¹ãã«å¤ããã°è¯ãã§ãããã + + +=head2 Testing with taint mode. + +(æ±æã¢ã¼ãã§ã®ãã¹ã) + +=begin original + +Taint mode is a funny thing. It's the globalest of all global +features. Once you turn it on, it affects I<all> code in your program +and I<all> modules used (and all the modules they use). If a single +piece of code isn't taint clean, the whole thing explodes. With that +in mind, it's very important to ensure your module works under taint +mode. + +=end original + +æ±æã¢ã¼ãã¯æ¥½ãããã®ã§ããå ¨ã¦ã®å ¨ä½çãªç¹å¾´ã®ãªãã§ãããã£ã¨ãå ¨ä½çãªãã®ã§ãã +æ±æã¢ã¼ããä»ããã¨ãæ±æã¢ã¼ãã¯ãããã°ã©ã ã®å ¨ã¦ã®ã³ã¼ãã¨I<å ¨ã¦ã®>ã¢ã¸ã¥ã¼ã« +(ã¨ããããã使ã£ã¦ããI<å ¨ã¦ã®>ã¢ã¸ã¥ã¼ã«)ã«å½±é¿ãã¾ãã +ã³ã¼ãã®ä¸ã¤ã§ããæ±æããã¦ããã°ãå ¨ã¦ãççºãã¾ãã +ãã®ãã¨ã念é ã«ç½®ãã¦ãæ±æã¢ã¼ãã®ä¸ã§ãã¢ã¸ã¥ã¼ã«ãåãã®ãä¿è¨¼ãããã¨ã¯ãã¨ã¦ãéè¦ã§ãã + +=begin original + +It's very simple to have your tests run under taint mode. Just throw +a C<-T> into the C<#!> line. C<Test::Harness> will read the switches +in C<#!> and use them to run your tests. + +=end original + +ãã¹ãããæ±æã¢ã¼ãã§èµ°ãããã®ã¯ãã¨ã¦ãç°¡åã§ãã +C<#!>è¡ã«ãC<-T>ãæããã ãã§ããC<Test::Harness> ã¯ã +C<#!> è¡ã®ã¹ã¤ãããèªã¿ããã¹ãã§ãã®ã¹ã¤ããã使ãã¾ãã + + + #!/usr/bin/perl -Tw + + ...test normally here... + +=begin original + +When you say C<make test> it will run with taint mode on. + +=end original + +C<make test>ãããã¨ããã¹ãã¯æ±æã¢ã¼ãã¨è¦åãæå¹ã«ãã¦èµ°ãã§ãããã + +=head1 FOOTNOTES + +(è注) + +=over 4 + +=item 1 + +=begin original + +The first number doesn't really mean anything, but it has to be 1. +It's the second number that's important. + +=end original + +æåã®æ°åã¯å®éä½ãæå³ãã¦ãã¾ãããã1ã§ãªããã°ããã¾ããã +éè¦ãªã®ã¯ã2çªç®ã®æ°åã§ãã + +=item 2 + +=begin original + +For those following along at home, I'm using version 1.31. It has +some bugs, which is good -- we'll uncover them with our tests. + +=end original + +以ä¸ã«é²ãããããã¼ã¸ã§ã³1.31ã使ãã¾ãããã®ãã¼ã¸ã§ã³ã«ã¯ããã°ãå°ã ããã¾ããã +大ä¸å¤«ã§ã -- ãã¹ãã§ãã°ãæããã«ãã¾ãããã + +=item 3 + +=begin original + +You can actually take this one step further and test the manual +itself. Have a look at L<Test::Inline> (formerly L<Pod::Tests>). + +=end original + +å®éã«ããã®ã¹ãããããã£ã¨åãå ¥ããããã¥ã¢ã«èªèº«ããã¹ãã§ãã¾ãã +L<Test::Inline>ãè¦ãªããã (以åã® L<Pod::Tests>) + +=item 4 + +=begin original + +Yes, there's a mistake in the test suite. What! Me, contrived? + +=end original + +ãã®ãã¹ãã«ã¯ãééããããã¾ããä½! ç§ããä»çµãã ã£ã¦ï¼ + +=item 5 + +=begin original + +We'll get to testing the contents of lists later. + +=end original + +å¾ã§ããªã¹ãã®å 容ããã¹ããã¾ãã + +=item 6 + +=begin original + +But what happens if your test program dies halfway through?! Since we +didn't say how many tests we're going to run, how can we know it +failed? No problem, C<Test::More> employs some magic to catch that death +and turn the test into a failure, even if every test passed up to that +point. + +=end original + +ãããããã¹ãããã°ã©ã ãéä¸ã§æ»ãã ããä½ãèµ·ããã®ã ããã?! +ã©ããããã®ãã¹ããåããã¦ããã®ãæ¸ããªãã§ãã©ããã£ã¦å¤±æããã®ããããã ããã? +åé¡ããã¾ãããC<Test::More>ã¯ãããã¤ãã®éæ³ã使ãããã®æ»ãæããã +ãã¹ãã失æã«å¤ãã¾ãããã¨ããå ¨ã¦ã®ãã¹ããããã®å ´æã§ãã¹ããã¨ãã¦ãã + +=item 7 + +=begin original + +I cleaned it up a little. + +=end original + +ã¡ãã£ã¨ã ã綺éºã«ãã¾ããã + +=item 8 + +=begin original + +Most Operating Systems record time as the number of seconds since a +certain date. This date is the beginning of the epoch. Unix's starts +at midnight January 1st, 1970 GMT. + +=end original + +ããã¦ãã®OSã¯ãããæ¥ä»ããã®ç§æ°ã¨ãã¦æéãè¨é²ãã¾ãã +ãã®æ¥ä»ããã¨ããã¯ã®å§ã¾ãã§ããUNIXã®ã¨ããã¯ã®å§ã¾ãã¯ãæ¨æºæã®1970å¹´ã®1æ1æ¥ã®æ·±å¤ã§ãã + +=item 9 + +=begin original + +MacOS's epoch is midnight January 1st, 1904. VMS's is midnight, +November 17th, 1858, but vmsperl emulates the Unix epoch so it's not a +problem. + +=end original + +MacOSã®ã¨ããã¯ã¯ã1904å¹´ã®1æ1æ¥ã®æ·±å¤ã§ããVMSã®ã¨ããã¯ã¯ã1858å¹´ã®11æ17æ¥ã®æ·±å¤ã§ãã +ã§ãããvmsperlã¯ãUNIXã®ã¨ããã¯ãã¨ãã¥ã¬ã¼ããã¦ããã®ã§ãåé¡ã¯ããã¾ããã + +=item 10 + +=begin original + +As long as the code inside the SKIP block at least compiles. Please +don't ask how. No, it's not a filter. + +=end original + +SKIPãããã¯ã®ä¸ã«ã³ã¼ããå¨ãéããå°ãªãã¨ãã³ã³ãã¤ã«ããã¾ããã©ããã£ã¦ããã¯èããªãã§ä¸ããã +ãã£ã«ã¿ã¼ã§ã¯ããã¾ããã + +=item 11 + +=begin original + +Do NOT be tempted to use TODO tests as a way to avoid fixing simple +bugs! + +=end original + +ç°¡åãªãã°ãç´ãã®ãé¿ããããã®æ¹æ³ã¨ãã¦ãTODOãã¹ãã使ããã¨ãã¦ã¯ããã¾ãã! + +=back + +=head1 AUTHORS + +Michael G Schwern E<lt>schwe****@pobox*****<gt> and the perl-qa dancers! + +=head1 COPYRIGHT + +Copyright 2001 by Michael G Schwern E<lt>schwe****@pobox*****<gt>. + +This documentation is free; you can redistribute it and/or modify it +under the same terms as Perl itself. + +Irrespective of its distribution, all code examples in these files +are hereby placed into the public domain. You are permitted and +encouraged to use this code in your own programs for fun +or for profit as you see fit. A simple comment in the code giving +credit would be courteous but is not required. + + +=cut