晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /usr/share/doc/perl-Test-Simple/t/Legacy/subtest/ |
Upload File : |
#!/usr/bin/perl -w
# Test todo subtests.
#
# A subtest in a todo context should have all of its diagnostic output
# redirected to the todo output destination, but individual tests
# within the subtest should not become todo tests themselves.
BEGIN {
if( $ENV{PERL_CORE} ) {
chdir 't';
@INC = ( '../lib', 'lib' );
}
else {
unshift @INC, 't/lib';
}
}
use strict;
use warnings;
use Test::More;
use Test::Builder;
use Test::Builder::Tester;
# Formatting may change if we're running under Test::Harness.
$ENV{HARNESS_ACTIVE} = 0;
our %line;
# Repeat each test for various combinations of the todo reason,
# the mechanism by which it is set and $Level.
our @test_combos;
foreach my $level (1, 2, 3) {
push @test_combos, ['$TODO', 'Reason', $level],
['todo_start', 'Reason', $level],
['todo_start', '', $level],
['todo_start', 0, $level];
}
plan tests => 8 * @test_combos;
sub test_subtest_in_todo {
my ($name, $code, $want_out, $no_tests_run) = @_;
my $xxx = $no_tests_run ? 'No tests run for subtest "xxx"' : 'xxx';
chomp $want_out;
my @outlines = split /\n/, $want_out;
foreach my $combo (@test_combos) {
my ($set_via, $todo_reason, $level) = @$combo;
test_out( map { my $x = $_; $x =~ s/\s+$//g; $x }
"# Subtest: xxx",
@outlines,
"not ok 1 - $xxx # TODO $todo_reason",
"# Failed (TODO) test '$xxx'",
"# at $0 line $line{xxx}.",
"not ok 2 - regular todo test # TODO $todo_reason",
"# Failed (TODO) test 'regular todo test'",
"# at $0 line $line{reg}.",
);
{
local $TODO = $set_via eq '$TODO' ? $todo_reason : undef;
if ($set_via eq 'todo_start') {
Test::Builder->new->todo_start($todo_reason);
}
subtest_at_level(
'xxx', $code, $level); BEGIN{ $line{xxx} = __LINE__ }
ok 0, 'regular todo test'; BEGIN{ $line{reg} = __LINE__ }
if ($set_via eq 'todo_start') {
Test::Builder->new->todo_end;
}
}
test_test("$name ($level), todo [$todo_reason] set via $set_via");
}
}
package Foo; # If several stack frames are in package 'main' then $Level
# could be wrong and $main::TODO might still be found. Using
# another package makes the tests more sensitive.
sub main::subtest_at_level {
my ($name, $code, $level) = @_;
if ($level > 1) {
local $Test::Builder::Level = $Test::Builder::Level + 1;
main::subtest_at_level($name, $code, $level-1);
}
else {
Test::Builder->new->subtest($name => $code);
}
}
package main;
test_subtest_in_todo("plan, no tests run", sub {
plan tests => 2;
}, <<END, 1);
1..2
# No tests run!
END
test_subtest_in_todo("noplan, no tests run", sub {
plan 'no_plan';
}, <<END, 1);
# No tests run!
END
test_subtest_in_todo("missingplan, no tests run", sub {
1;
}, <<END, 1);
1..0
# No tests run!
END
test_subtest_in_todo("donetesting, no tests run", sub {
done_testing;
}, <<END, 1);
1..0
# No tests run!
END
test_subtest_in_todo("1 failed test", sub {
ok 0, 'failme'; BEGIN { $line{fail1} = __LINE__ }
}, <<END);
not ok 1 - failme
# Failed test 'failme'
# at $0 line $line{fail1}.
1..1
# Looks like you failed 1 test of 1.
END
test_subtest_in_todo("1fail, wrongplan", sub {
plan tests => 17;
ok 0, 'failme'; BEGIN { $line{fail2} = __LINE__ }
}, <<END);
1..17
not ok 1 - failme
# Failed test 'failme'
# at $0 line $line{fail2}.
# Looks like you planned 17 tests but ran 1.
# Looks like you failed 1 test of 1 run.
END
test_subtest_in_todo("1fail, 1pass", sub {
ok 0, 'failme'; BEGIN { $line{fail3} = __LINE__ }
ok 1, 'passme';
}, <<END);
not ok 1 - failme
# Failed test 'failme'
# at $0 line $line{fail3}.
ok 2 - passme
1..2
# Looks like you failed 1 test of 2.
END
test_subtest_in_todo("todo tests in the subtest", sub {
ok 0, 'inner test 1'; BEGIN{ $line{in1} = __LINE__ }
TODO: {
local $TODO = 'Inner1';
ok 0, 'failing TODO a'; BEGIN{ $line{fta} = __LINE__ }
ok 1, 'unexpected pass a';
}
ok 0, 'inner test 2'; BEGIN{ $line{in2} = __LINE__ }
Test::Builder->new->todo_start('Inner2');
ok 0, 'failing TODO b'; BEGIN{ $line{ftb} = __LINE__ }
ok 1, 'unexpected pass b';
Test::Builder->new->todo_end;
ok 0, 'inner test 3'; BEGIN{ $line{in3} = __LINE__ }
}, <<END);
not ok 1 - inner test 1
# Failed test 'inner test 1'
# at $0 line $line{in1}.
not ok 2 - failing TODO a # TODO Inner1
# Failed (TODO) test 'failing TODO a'
# at $0 line $line{fta}.
ok 3 - unexpected pass a # TODO Inner1
not ok 4 - inner test 2
# Failed test 'inner test 2'
# at $0 line $line{in2}.
not ok 5 - failing TODO b # TODO Inner2
# Failed (TODO) test 'failing TODO b'
# at $0 line $line{ftb}.
ok 6 - unexpected pass b # TODO Inner2
not ok 7 - inner test 3
# Failed test 'inner test 3'
# at $0 line $line{in3}.
1..7
# Looks like you failed 3 tests of 7.
END