From: Graham Knop Date: Tue, 6 Aug 2013 03:26:03 +0000 (-0400) Subject: Update threads usage in Sub::Quote/Defer tests X-Git-Tag: v1.003001~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a6d0da2fc8dbf846b6dce694af7bdc4a8c440376;p=gitmo%2FMoo.git Update threads usage in Sub::Quote/Defer tests Load threads before Test::More and return non-trivial results from thread->join to avoid various bugs. --- diff --git a/t/sub-defer-threads.t b/t/sub-defer-threads.t index a9f5dd6..73ab321 100644 --- a/t/sub-defer-threads.t +++ b/t/sub-defer-threads.t @@ -1,11 +1,13 @@ -use strictures 1; -use Test::More; use Config; BEGIN { - unless ($Config{useithreads} && eval { require threads } ) { - plan skip_all => "your perl does not support ithreads"; + unless ($Config{useithreads}) { + print "1..0 # SKIP your perl does not support ithreads\n"; + exit 0; } } +use threads; +use strictures 1; +use Test::More; use Sub::Defer; @@ -16,14 +18,14 @@ my $one_defer = defer_sub 'Foo::one' => sub { $made{'Foo::one'} = sub { 'one' } }; -ok(threads->create(sub { +is(threads->create(sub { my $info = Sub::Defer::defer_info($one_defer); - $info && $info->[0] eq 'Foo::one'; -})->join, 'able to retrieve info in thread'); + $info && $info->[0]; +})->join, 'Foo::one', 'able to retrieve info in thread'); -ok(threads->create(sub { +is(threads->create(sub { undefer_sub($one_defer); - $made{'Foo::one'} && $made{'Foo::one'} == \&Foo::one; -})->join, 'able to undefer in thread'); + $made{'Foo::one'} && $made{'Foo::one'} == \&Foo::one && 1234; +})->join, 1234, 'able to undefer in thread'); done_testing; diff --git a/t/sub-quote-threads.t b/t/sub-quote-threads.t index ecd8b2e..80f0fc8 100644 --- a/t/sub-quote-threads.t +++ b/t/sub-quote-threads.t @@ -1,11 +1,13 @@ -use strictures 1; -use Test::More; use Config; BEGIN { - unless ($Config{useithreads} && eval { require threads } ) { - plan skip_all => "your perl does not support ithreads"; + unless ($Config{useithreads}) { + print "1..0 # SKIP your perl does not support ithreads\n"; + exit 0; } } +use threads; +use strictures 1; +use Test::More; use Sub::Quote; @@ -19,10 +21,10 @@ my $two = quote_sub q{ 3 + $x++ } => { '$x' => \do { my $x = 0 } }; -ok(threads->create(sub { +is(threads->create(sub { my $quoted = quoted_from_sub($one); - $quoted && $quoted->[1] eq $one_code; -})->join, 'able to retrieve quoted sub in thread'); + $quoted && $quoted->[1]; +})->join, $one_code, 'able to retrieve quoted sub in thread'); my $u_one = unquote_sub $one;