| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::RecordStream::Operation::assert; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = "4.0.23"; |
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
990
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
59
|
|
|
6
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
48
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
15
|
use base qw(App::RecordStream::Operation); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
117
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
407
|
use App::RecordStream::Executor::Getopt; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
42
|
|
|
11
|
2
|
|
|
2
|
|
10
|
use App::RecordStream::Executor; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
29
|
|
|
12
|
2
|
|
|
2
|
|
9
|
use Data::Dumper (); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
667
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub init { |
|
15
|
3
|
|
|
3
|
0
|
5
|
my $this = shift; |
|
16
|
3
|
|
|
|
|
6
|
my $args = shift; |
|
17
|
|
|
|
|
|
|
|
|
18
|
3
|
|
|
|
|
7
|
$this->{DIAGNOSTIC} = ''; |
|
19
|
3
|
|
|
|
|
6
|
$this->{VERBOSE} = 0; |
|
20
|
|
|
|
|
|
|
|
|
21
|
3
|
|
|
|
|
18
|
my $executor_options = App::RecordStream::Executor::Getopt->new(); |
|
22
|
|
|
|
|
|
|
my $spec = { |
|
23
|
|
|
|
|
|
|
'diagnostic|d=s' => \$this->{DIAGNOSTIC}, |
|
24
|
|
|
|
|
|
|
'verbose|v' => \$this->{VERBOSE}, |
|
25
|
3
|
|
|
|
|
11
|
$executor_options->arguments(), |
|
26
|
|
|
|
|
|
|
}; |
|
27
|
|
|
|
|
|
|
|
|
28
|
3
|
|
|
|
|
17
|
$this->parse_options($args, $spec, ['bundling']); |
|
29
|
|
|
|
|
|
|
|
|
30
|
3
|
|
|
|
|
12
|
my $expression = $executor_options->get_string($args); |
|
31
|
3
|
|
|
|
|
19
|
my $executor = App::RecordStream::Executor->new($expression); |
|
32
|
|
|
|
|
|
|
|
|
33
|
3
|
|
|
|
|
7
|
$this->{'ASSERTION'} = $expression; |
|
34
|
3
|
|
|
|
|
43
|
$this->{'EXECUTOR'} = $executor; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub accept_record { |
|
38
|
7
|
|
|
7
|
0
|
13
|
my $this = shift; |
|
39
|
7
|
|
|
|
|
11
|
my $record = shift; |
|
40
|
|
|
|
|
|
|
|
|
41
|
7
|
100
|
|
|
|
23
|
unless ($this->{'EXECUTOR'}->execute_code($record)) { |
|
42
|
|
|
|
|
|
|
die "Assertion failed! $this->{DIAGNOSTIC}\n", |
|
43
|
|
|
|
|
|
|
"Expression: « $this->{ASSERTION} »\n", |
|
44
|
|
|
|
|
|
|
"Filename: ", $this->get_current_filename, "\n", |
|
45
|
|
|
|
|
|
|
"Line: $.\n", |
|
46
|
|
|
|
|
|
|
($this->{VERBOSE} |
|
47
|
2
|
100
|
|
|
|
15
|
? ("Record: ", Data::Dumper->Dump([$record->as_hashref], ['r']), "\n") |
|
48
|
|
|
|
|
|
|
: ()); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
24
|
$this->push_record($record); |
|
52
|
5
|
|
|
|
|
21
|
return 1; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub add_help_types { |
|
56
|
3
|
|
|
3
|
0
|
5
|
my $this = shift; |
|
57
|
3
|
|
|
|
|
13
|
$this->use_help_type('snippet'); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub usage { |
|
61
|
0
|
|
|
0
|
0
|
|
my $this = shift; |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $options = [ |
|
64
|
|
|
|
|
|
|
['diagnostic|-d ' => 'Include the diagnostic string in any failed assertion errors'], |
|
65
|
|
|
|
|
|
|
['verbose|-v' => 'Verbose output for failed assertions; dumps the current record'], |
|
66
|
|
|
|
|
|
|
App::RecordStream::Executor::options_help(), |
|
67
|
|
|
|
|
|
|
]; |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $args_string = $this->options_string($options); |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $usage = <
|
|
72
|
|
|
|
|
|
|
Usage: recs-assert [] |
|
73
|
|
|
|
|
|
|
__FORMAT_TEXT__ |
|
74
|
|
|
|
|
|
|
Asserts that every record in the stream must pass the given . |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
is evaluated as Perl on each record of input (or records from |
|
77
|
|
|
|
|
|
|
) with \$r set to a App::RecordStream::Record object and \$line set |
|
78
|
|
|
|
|
|
|
to the current line number (starting at 1). If does not evaluate to |
|
79
|
|
|
|
|
|
|
true, processing is immediately aborted and an error message printed. See |
|
80
|
|
|
|
|
|
|
--help-snippets for more information on code snippets. |
|
81
|
|
|
|
|
|
|
__FORMAT_TEXT__ |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$args_string |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Examples: |
|
86
|
|
|
|
|
|
|
Require each record to have a "date" field. |
|
87
|
|
|
|
|
|
|
recs-assert '\$r->{date}' |
|
88
|
|
|
|
|
|
|
USAGE |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |