File: 00_context.t

package info (click to toggle)
libaspect-perl 1.04-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 720 kB
  • sloc: perl: 6,846; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,042 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
68
69
70
#!/usr/bin/perl

# Validates some assumptions built into the Aspect code about how context
# and return work.

use strict;
BEGIN {
	$|  = 1;
	$^W = 1;
}
use Test::More tests => 28;
use Test::NoWarnings;

my $array  = 0;
my $scalar = 0;
my $void   = 0;

sub test {
	is( $array,  $_[0], "\$array = $_[0]"  );
	is( $scalar, $_[1], "\$scalar = $_[1]" );
	is( $void,   $_[2], "\$void = $_[2]"   );
}

# Direct usage
test( 1, 0, 0, context() );
test( 1, 1, 0, scalar(context()) );
context();
test( 1, 1, 1 );

# Plain single indirection
test( 2, 1, 1, one() );
test( 2, 2, 1, scalar(one()) );
one();
test( 2, 2, 2 );

# Plain explicit indirection
test( 3, 2, 2, two() );
test( 3, 3, 2, scalar(two()) );
two();
test( 3, 3, 3 );





######################################################################
# Test Functions

sub one {
	context();
}

sub two {
	return context();
}

sub context {
	if ( wantarray ) {
		$array++;
		return 'foo';
	} elsif ( defined wantarray ) {
		$scalar++;
		return 'bar';
	} else {
		$void++;
		return 'baz';
	}
}

1;