root/t/oo/global_destruction.t

Revision 22001, 1.2 kB (checked in by moritz, 5 months ago)

[t/oo] more s/system/run/ and try{...} fixes

  • Property svn:mime-type set to text/plain; charset=UTF-8
  • Property svn:eol-style set to native
Line 
1use v6;
2
3use Test;
4
5plan 3;
6my $destroy_test = 'use v6;
7
8class Foo
9{
10    submethod DESTROY { say "Foo goes away" }
11}
12
13class Parent
14{
15    submethod DESTROY { say "Parent goes away" }
16}
17
18class Child is Parent
19{
20    submethod DESTROY { say "Child goes away" }
21}
22
23my $foo    = Foo.new();
24my $parent = Parent.new();
25my $child  = Child.new();';
26
27my $out = open('destroy_test.pl', :w);
28
29unless $out
30{
31    diag( "Could not write destroy_test.pl" );
32    exit;
33}
34
35$out.say( $destroy_test );
36$out.close;
37
38my ($pugs,$redir) = ($*EXECUTABLE_NAME, ">");
39
40if $*OS eq any <MSWin32 mingw msys cygwin> {
41  $pugs = 'pugs.exe';
42  $redir = '>';
43};
44
45sub nonce () { return (".{$*PID}." ~ (1..1000).pick) }
46
47sub 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
57my $output  = run_pugs("destroy_test.pl");
58
59like( $output, rx:P5/Foo goes away/,
60    'global destruction should collect objects...' );
61like( $output, rx:P5/Parent goes away/,
62    '... of all types' );
63like( $output, rx:P5/Child goes away\s*Parent goes away/,
64    '... and calling all destructors' );
65
66END
67{
68    if ! %*ENV<TEST_DEBUG_FILES>
69    {
70        unlink 'destroy_test.pl';
71    }
72}
Note: See TracBrowser for help on using the browser.