File: 007_cleanup.t

package info (click to toggle)
libeval-context-perl 0.09.11-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 292 kB
  • ctags: 23
  • sloc: perl: 762; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,011 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# test

use strict ;
use warnings ;

use Data::TreeDumper ;

use Test::Exception ;
use Test::Warn;
use Test::NoWarnings qw(had_no_warnings);

use Test::More 'no_plan';
use Test::Block qw($Plan);

use Eval::Context ; 


{
local $Plan = {'cleanup' => 4} ;

lives_ok
	{
	my $context = new Eval::Context() ;

	$context->eval
		(
		PACKAGE => 'A',
		REMOVE_PACKAGE_AFTER_EVAL => 0,
		CODE => 'sub sub1{1} ;',
		) ;
		
	is(A::sub1(), 1,  'package sub still accessible') ;
	} 'no cleanup' ;
	
dies_ok
	{
	warnings_like
		{
		my $context = new Eval::Context() ;

		$context->eval
			(
			PACKAGE => 'A',
			REMOVE_PACKAGE_AFTER_EVAL => 1,
			CODE => 'sub sub2{2} ;',
			) ;
			
		A::sub2() ;
		} qr/Undefined subroutine &A::sub2/, 'forced cleanup' ;
	} 'package gone' ;
	
dies_ok
	{
	warnings_like
		{
		my $context = new Eval::Context() ;

		$context->eval
			(
			PACKAGE => 'A',
			CODE => 'sub sub3 {3} ;',
			) ;
			
		A::sub3() ;
		} qr/Undefined subroutine &A::sub3/, 'automatic cleanup' ;
	} 'package gone' ;
}