| 1 | use v6; |
|---|
| 2 | |
|---|
| 3 | use Test; |
|---|
| 4 | |
|---|
| 5 | plan 3; |
|---|
| 6 | my $destroy_test = 'use v6; |
|---|
| 7 | |
|---|
| 8 | class Foo |
|---|
| 9 | { |
|---|
| 10 | submethod DESTROY { say "Foo goes away" } |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | class Parent |
|---|
| 14 | { |
|---|
| 15 | submethod DESTROY { say "Parent goes away" } |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | class Child is Parent |
|---|
| 19 | { |
|---|
| 20 | submethod DESTROY { say "Child goes away" } |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | my $foo = Foo.new(); |
|---|
| 24 | my $parent = Parent.new(); |
|---|
| 25 | my $child = Child.new();'; |
|---|
| 26 | |
|---|
| 27 | my $out = open('destroy_test.pl', :w); |
|---|
| 28 | |
|---|
| 29 | unless $out |
|---|
| 30 | { |
|---|
| 31 | diag( "Could not write destroy_test.pl" ); |
|---|
| 32 | exit; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | $out.say( $destroy_test ); |
|---|
| 36 | $out.close; |
|---|
| 37 | |
|---|
| 38 | my ($pugs,$redir) = ($*EXECUTABLE_NAME, ">"); |
|---|
| 39 | |
|---|
| 40 | if $*OS eq any <MSWin32 mingw msys cygwin> { |
|---|
| 41 | $pugs = 'pugs.exe'; |
|---|
| 42 | $redir = '>'; |
|---|
| 43 | }; |
|---|
| 44 | |
|---|
| 45 | sub nonce () { return (".{$*PID}." ~ (1..1000).pick) } |
|---|
| 46 | |
|---|
| 47 | sub run_pugs ($c) { |
|---|
| 48 | my $tempfile = "temp-ex-output" ~ nonce; |
|---|
| 49 | my $command = "$pugs $c $redir $tempfile"; |
|---|
| 50 | diag $command; |
|---|
| 51 | run $command; |
|---|
| 52 | my $res = slurp $tempfile; |
|---|
| 53 | unlink $tempfile; |
|---|
| 54 | return $res; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | my $output = run_pugs("destroy_test.pl"); |
|---|
| 58 | |
|---|
| 59 | like( $output, rx:P5/Foo goes away/, |
|---|
| 60 | 'global destruction should collect objects...' ); |
|---|
| 61 | like( $output, rx:P5/Parent goes away/, |
|---|
| 62 | '... of all types' ); |
|---|
| 63 | like( $output, rx:P5/Child goes away\s*Parent goes away/, |
|---|
| 64 | '... and calling all destructors' ); |
|---|
| 65 | |
|---|
| 66 | END |
|---|
| 67 | { |
|---|
| 68 | if ! %*ENV<TEST_DEBUG_FILES> |
|---|
| 69 | { |
|---|
| 70 | unlink 'destroy_test.pl'; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|