Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eval_(dies|lives)_ok methods for rakudo's Test.pm, and more tests #116

Closed
p6rt opened this issue Jun 4, 2008 · 20 comments
Closed

eval_(dies|lives)_ok methods for rakudo's Test.pm, and more tests #116

p6rt opened this issue Jun 4, 2008 · 20 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 4, 2008

Migrated from rt.perl.org#55304 (status was 'resolved')

Searchable as RT55304$

@p6rt
Copy link
Author

p6rt commented Jun 4, 2008

From @moritz

Attached patch, mostly courtesy Vasily "bacek" Chekalkin, adds the
eval_lives_ok and eval_dies_ok methods to Test.pm, and adds three more
passing tests to 'make spectest_regression'.

--
Moritz Lenz
http://moritz.faui2k3.org/ | http://perl-6.de/

@p6rt
Copy link
Author

p6rt commented Jun 4, 2008

From @moritz

Oops, forgot to attach patch. Now it's really there.

--
Moritz Lenz
http://moritz.faui2k3.org/ | http://perl-6.de/

@p6rt
Copy link
Author

p6rt commented Jun 4, 2008

From @moritz

eval_stuff.patch
Index: languages/perl6/t/spectest_regression.data
===================================================================
--- languages/perl6/t/spectest_regression.data	(revision 28065)
+++ languages/perl6/t/spectest_regression.data	(working copy)
@@ -6,6 +6,8 @@
 S02-literals/autoref.t
 S02-literals/hex_chars.t
 S02-literals/radix.t
+S02-polymorphic_types/subset-code.t             # pure
+S02-polymorphic_types/subset-range.t
 S03-operators/autoincrement.t                   # pure
 S03-operators/comparison.t
 S03-operators/cross-metaop.t
@@ -39,6 +41,7 @@
 S29-list/map_empty_list.t
 S29-list/map_flattening.t
 S29-list/map_function_return_values.t
+S29-list/map.t
 S29-list/mutating_listops.t                     # pure
 S29-list/sort.t
 S29-num/abs.t
Index: languages/perl6/Test.pm
===================================================================
--- languages/perl6/Test.pm	(revision 28065)
+++ languages/perl6/Test.pm	(working copy)
@@ -122,7 +122,23 @@
     lives_ok($closure, '');
 }
 
+multi sub eval_dies_ok($code, $reason) {
+    eval ( $code );
+    proclaim((defined $!), $reason);
+}
+multi sub eval_dies_ok($code) {
+    eval_dies_ok($code, '');
+}
 
+multi sub eval_lives_ok($code, $reason) {
+    try { eval ($code) }
+    proclaim((not defined $!), $reason);
+}
+multi sub eval_lives_ok($code) {
+    eval_lives_ok($code, '');
+}
+
+
 ## 'private' subs
 
 sub proclaim($cond, $desc) {

@p6rt
Copy link
Author

p6rt commented Jun 4, 2008

From @particle

On Wed, Jun 4, 2008 at 2​:46 PM, Moritz Lenz <moritz@​casella.verplant.org> wrote​:

Oops, forgot to attach patch. Now it's really there.

thanks, applied as of r28074.
~jerry

@p6rt
Copy link
Author

p6rt commented Jun 4, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jun 5, 2008

From @ronaldxs

Moritz Lenz wrote​:

Oops, forgot to attach patch. Now it's really there.

Your implementations of eval_lives_ok and eval_dies_ok seem
inconsistent. eval_lives_ok uses try and eval_dies_ok does not. The
two implementations may catch different types of exceptions. I am
proposing the patch below​:

$ svn diff Test.pm
Index​: Test.pm

--- Test.pm (revision 28117)
+++ Test.pm (working copy)
@​@​ -122,17 +122,20 @​@​
  lives_ok($closure, '');
}

+sub eval_exception ($code) {
+ my $eval_exception;
+ try { eval ( $code ); $eval_exception = $! }
+ $eval_exception // $!;
+}
multi sub eval_dies_ok($code, $reason) {
- eval ( $code );
- proclaim((defined $!), $reason);
+ proclaim((defined eval_exception($code)), $reason);
}
multi sub eval_dies_ok($code) {
  eval_dies_ok($code, '');
}

multi sub eval_lives_ok($code, $reason) {
- try { eval ($code) }
- proclaim((not defined $!), $reason);
+ proclaim((not defined eval_exception($code)), $reason);
}
multi sub eval_lives_ok($code) {
  eval_lives_ok($code, '');

@p6rt
Copy link
Author

p6rt commented Jun 5, 2008

From @moritz

Ronald Schmidt wrote​:

Moritz Lenz wrote​:

Oops, forgot to attach patch. Now it's really there.

Your implementations of eval_lives_ok and eval_dies_ok seem
inconsistent. eval_lives_ok uses try and eval_dies_ok does not. The
two implementations may catch different types of exceptions. I am
proposing the patch below​:

Good catch. Actually I already encountered I problem with these two
subs, but haven't got around to fix it so far.

Are there any exceptions that are not caught by eval?
Currently rakudo seems to catch every run time exception, but parse
failures still throw an exception. I'm pretty sure that's wrong, because
it's contrary to Perl 6's exception philosophy.

So eval() needs more work, but in the mean time your patch works just
fine (and it will continue to work when eval is fixed), so I vote +1 here.

Cheers,
Moritz

$ svn diff Test.pm
Index​: Test.pm

--- Test.pm (revision 28117)
+++ Test.pm (working copy)
@​@​ -122,17 +122,20 @​@​
lives_ok($closure, '');
}

+sub eval_exception ($code) {
+ my $eval_exception;
+ try { eval ( $code ); $eval_exception = $! }
+ $eval_exception // $!;
+}
multi sub eval_dies_ok($code, $reason) {
- eval ( $code );
- proclaim((defined $!), $reason);
+ proclaim((defined eval_exception($code)), $reason);
}
multi sub eval_dies_ok($code) {
eval_dies_ok($code, '');
}

multi sub eval_lives_ok($code, $reason) {
- try { eval ($code) }
- proclaim((not defined $!), $reason);
+ proclaim((not defined eval_exception($code)), $reason);
}
multi sub eval_lives_ok($code) {
eval_lives_ok($code, '');

--
Moritz Lenz
http://moritz.faui2k3.org/ | http://perl-6.de/

@p6rt
Copy link
Author

p6rt commented Jun 5, 2008

From @particle

On Thu, Jun 5, 2008 at 3​:05 PM, Moritz Lenz <moritz@​casella.verplant.org> wrote​:

Ronald Schmidt wrote​:

Moritz Lenz wrote​:

Oops, forgot to attach patch. Now it's really there.

Your implementations of eval_lives_ok and eval_dies_ok seem
inconsistent. eval_lives_ok uses try and eval_dies_ok does not. The
two implementations may catch different types of exceptions. I am
proposing the patch below​:

Good catch. Actually I already encountered I problem with these two
subs, but haven't got around to fix it so far.

Are there any exceptions that are not caught by eval?
Currently rakudo seems to catch every run time exception, but parse
failures still throw an exception. I'm pretty sure that's wrong, because
it's contrary to Perl 6's exception philosophy.

So eval() needs more work, but in the mean time your patch works just
fine (and it will continue to work when eval is fixed), so I vote +1 here.

agreed, good catch. applied with some formatting tweaks (eg. putting
eval_exception() in the 'private' subs area) as r28124.
~jerry

@p6rt
Copy link
Author

p6rt commented Jun 7, 2008

From @particle

On Fri, Jun 6, 2008 at 7​:34 PM, Vasily Chekalkin <bacek@​bacek.com> wrote​:

jerry gay wrote​:

On Wed, Jun 4, 2008 at 2​:46 PM, Moritz Lenz <moritz@​casella.verplant.org>
wrote​:

Oops, forgot to attach patch. Now it's really there.

thanks, applied as of r28074.
~jerry

This is wrong patch. eval() shouldn't throws any exceptions.

Correct patch for 'eval()' and Test.pm attached.

would you reformat this in universal diff format please? my patch
program doesn't speak git.
~jerry

@p6rt
Copy link
Author

p6rt commented Jun 7, 2008

From @bacek

On Fri Jun 06 20​:11​:36 2008, particle wrote​:

(Sorry for spam if any. Looks like my message was rejected by mailman.)

eval() shouldn't throws any exceptions.

Correct patch for 'eval()' and Test.pm attached.

--
Bacek.

@p6rt
Copy link
Author

p6rt commented Jun 7, 2008

From @bacek

eval2.diff
===================================================
--- Test.pm (orig)
+++ Test.pm (modified)
@@ -123,14 +123,16 @@ multi sub lives_ok($closure) {
 }
 
 multi sub eval_dies_ok($code, $reason) {
-    proclaim((defined eval_exception($code)), $reason);
+	eval($code);
+    proclaim(defined($!), $reason);
 }
 multi sub eval_dies_ok($code) {
     eval_dies_ok($code, '');
 }
 
 multi sub eval_lives_ok($code, $reason) {
-    proclaim((not defined eval_exception($code)), $reason);
+	eval($code);
+    proclaim((not defined $!), $reason);
 }
 multi sub eval_lives_ok($code) {
     eval_lives_ok($code, '');
@@ -139,12 +141,6 @@ multi sub eval_lives_ok($code) {
 
 ## 'private' subs
 
-sub eval_exception($code) {
-    my $eval_exception;
-    try { eval ($code); $eval_exception = $! }
-    $eval_exception // $!;
-}
-
 sub proclaim($cond, $desc) {
     $testing_started  = 1;
     $num_of_tests_run = $num_of_tests_run + 1;
===================================================
--- src/builtins/control.pir (orig)
+++ src/builtins/control.pir (modified)
@@ -113,13 +113,12 @@ on error.
     unless have_lang goto no_lang
     'die'('Lanuage parameter to eval unimplemented.')
   no_lang:
+    push_eh catch
 
     .local pmc compiler, invokable
     .local pmc res, exception
     compiler = compreg 'Perl6'
     invokable = compiler.'compile'(code)
-
-    push_eh catch
     res = invokable()
     pop_eh
     exception = new 'Failure'

@p6rt
Copy link
Author

p6rt commented Jun 7, 2008

From @bacek

jerry gay wrote​:

On Wed, Jun 4, 2008 at 2​:46 PM, Moritz Lenz <moritz@​casella.verplant.org> wrote​:

Oops, forgot to attach patch. Now it's really there.

thanks, applied as of r28074.
~jerry

This is wrong patch. eval() shouldn't throws any exceptions.

Correct patch for 'eval()' and Test.pm attached.

--
Bacek.

@p6rt
Copy link
Author

p6rt commented Jun 7, 2008

From @bacek

eval.diff
diff --git a/languages/perl6/Test.pm b/languages/perl6/Test.pm
index 5cb04ae..ccc34a9 100644
--- a/languages/perl6/Test.pm
+++ b/languages/perl6/Test.pm
@@ -123,14 +123,16 @@ multi sub lives_ok($closure) {
 }
 
 multi sub eval_dies_ok($code, $reason) {
-    proclaim((defined eval_exception($code)), $reason);
+	eval(code);
+    proclaim(defined($!), $reason);
 }
 multi sub eval_dies_ok($code) {
     eval_dies_ok($code, '');
 }
 
 multi sub eval_lives_ok($code, $reason) {
-    proclaim((not defined eval_exception($code)), $reason);
+	eval($code);
+    proclaim((not defined $!), $reason);
 }
 multi sub eval_lives_ok($code) {
     eval_lives_ok($code, '');
@@ -139,12 +141,6 @@ multi sub eval_lives_ok($code) {
 
 ## 'private' subs
 
-sub eval_exception($code) {
-    my $eval_exception;
-    try { eval ($code); $eval_exception = $! }
-    $eval_exception // $!;
-}
-
 sub proclaim($cond, $desc) {
     $testing_started  = 1;
     $num_of_tests_run = $num_of_tests_run + 1;
diff --git a/languages/perl6/src/builtins/control.pir b/languages/perl6/src/builtins/control.pir
index 479b1b6..558a4c4 100644
--- a/languages/perl6/src/builtins/control.pir
+++ b/languages/perl6/src/builtins/control.pir
@@ -113,13 +113,12 @@ on error.
     unless have_lang goto no_lang
     'die'('Lanuage parameter to eval unimplemented.')
   no_lang:
+    push_eh catch
 
     .local pmc compiler, invokable
     .local pmc res, exception
     compiler = compreg 'Perl6'
     invokable = compiler.'compile'(code)
-
-    push_eh catch
     res = invokable()
     pop_eh
     exception = new 'Failure'

@p6rt
Copy link
Author

p6rt commented Jun 7, 2008

From @bacek

jerry gay wrote​:

would you reformat this in universal diff format please? my patch
program doesn't speak git.

Strange... It is 'universal diff' format. Can be applied with
'patch -p1 < eval.diff' in top-level parrot directory. Or with
'patch -p3 < eval.diff' in languages/perl6.

Anyway, attached patch can be applied within 'patch -p0' in
languages/perl6 directory.

--
Bacek.

@p6rt
Copy link
Author

p6rt commented Jun 7, 2008

From @bacek

eval2.diff
===================================================
--- Test.pm (orig)
+++ Test.pm (modified)
@@ -123,14 +123,16 @@ multi sub lives_ok($closure) {
 }
 
 multi sub eval_dies_ok($code, $reason) {
-    proclaim((defined eval_exception($code)), $reason);
+	eval(code);
+    proclaim(defined($!), $reason);
 }
 multi sub eval_dies_ok($code) {
     eval_dies_ok($code, '');
 }
 
 multi sub eval_lives_ok($code, $reason) {
-    proclaim((not defined eval_exception($code)), $reason);
+	eval($code);
+    proclaim((not defined $!), $reason);
 }
 multi sub eval_lives_ok($code) {
     eval_lives_ok($code, '');
@@ -139,12 +141,6 @@ multi sub eval_lives_ok($code) {
 
 ## 'private' subs
 
-sub eval_exception($code) {
-    my $eval_exception;
-    try { eval ($code); $eval_exception = $! }
-    $eval_exception // $!;
-}
-
 sub proclaim($cond, $desc) {
     $testing_started  = 1;
     $num_of_tests_run = $num_of_tests_run + 1;
===================================================
--- src/builtins/control.pir (orig)
+++ src/builtins/control.pir (modified)
@@ -113,13 +113,12 @@ on error.
     unless have_lang goto no_lang
     'die'('Lanuage parameter to eval unimplemented.')
   no_lang:
+    push_eh catch
 
     .local pmc compiler, invokable
     .local pmc res, exception
     compiler = compreg 'Perl6'
     invokable = compiler.'compile'(code)
-
-    push_eh catch
     res = invokable()
     pop_eh
     exception = new 'Failure'

@p6rt
Copy link
Author

p6rt commented Jun 7, 2008

From @ronaldxs

Vasily Chekalkin wrote​:

This is wrong patch. eval() shouldn't throws any exceptions.

Correct patch for 'eval()' and Test.pm attached.

As Mr Lenz wrote with respect to eval exceptions and this patch​:

Are there any exceptions that are not caught by eval?
Currently rakudo seems to catch every run time exception,
/***** BUT PARSE FAILURES STILL THROW AN EXCEPTION. *****/
I'm pretty sure that's wrong, because
it's contrary to Perl 6's exception philosophy.

So eval() needs more work, but in the mean time your patch works just
fine (and it will continue to work when eval is fixed), so I vote +1 here.

For example​:

eval 'my $x = 2; $x = $x / 0; say $x;'; say 'eval exception ', $!;
eval exception Divide by zero

eval 'my $x; my $y; ($x = $y) = 3; say $x;'; say 'eval exception ', $!;
Method 'lvalue' not found for invocant of class 'PAST​::Stmts'

In the second case eval throws an exception and it would make sense for
eval_dies_ok to catch it and report it as a case that died. The second
case is from the pugs lvalue.t suite. I am currently doing work in that
area and would like to use eval_(dies|lives)_ok for some tests including
tests from lvalue.t.

Ron

@p6rt
Copy link
Author

p6rt commented Jun 7, 2008

From @bacek

On Sat Jun 07 07​:13​:07 2008, ronaldxs wrote​:

Probably I don't understand correctly your question. This is output from
my version of patched rakudo​:

$ ../../parrot perl6.pbc

eval 'my $x = 2; $x = $x / 0; say $x;'; say 'eval exception ', $!;
eval exception Divide by zero

Is it what you want?

--
Bacek

@p6rt
Copy link
Author

p6rt commented Jun 7, 2008

From allbery@ece.cmu.edu

On 2008 Jun 6, at 23​:53, Vasily Chekalkin wrote​:

jerry gay wrote​:

would you reformat this in universal diff format please? my patch
program doesn't speak git.

Strange... It is 'universal diff' format. Can be applied with
'patch -p1 < eval.diff' in top-level parrot directory. Or with
'patch -p3 < eval.diff' in languages/perl6.

Anyway, attached patch can be applied within 'patch -p0' in
languages/perl6 directory.
--- Test.pm (orig)
+++ Test.pm (modified)
@​@​ -123,14 +123,16 @​@​ multi sub lives_ok($closure) {

Your mail program is mangling line endings (note last line of above
quote). Try it as an attachment.

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@​kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery@​ece.cmu.edu
electrical and computer engineering, carnegie mellon university KF8NH

@p6rt
Copy link
Author

p6rt commented Jul 1, 2008

From @moritz

I'm resolving this ticket, because now (aka r28926) eval_lives_ok and
eval_dies_ok are implemented (and implemented in a consistent way).

If eval() still throws an exception in some cases that should be a
separate ticket.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Jul 1, 2008

@moritz - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Jul 1, 2008
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant