File: Helper.pm

package info (click to toggle)
libppi-perl 1.284-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,216 kB
  • sloc: perl: 15,295; makefile: 8
file content (56 lines) | stat: -rw-r--r-- 1,145 bytes parent folder | download | duplicates (2)
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
package Helper;

use strict;
use warnings;

use parent 'Exporter';
use Test::More;

use PPI::Document ();

our @EXPORT_OK = qw( check_with  safe_new );

=head1 safe_new @args

	my $doc = safe_new \"use strict";

Creates a PPI::Document object from the arguments and reports errors if
necessary. Can be used to replace most document new calls in the tests for
easier testing.

=cut

sub safe_new {
	my $Document = PPI::Document->new(@_);
	my $errstr   = PPI::Document->errstr;
	PPI::Document->_clear;
	if ( Test::More->builder->in_todo ) {
		local $TODO = 1;
		fail "no errors";
		fail 'PPI::Document';
		return $Document;
	}
	is( $errstr, '', "no errors" );
	isa_ok $Document, 'PPI::Document';
	return $Document;
}

=head1 check_with

	check_with "1.eqm'bar';", sub {
		is $_->child( 0 )->child( 1 )->content, "eqm'bar",
		  "eqm' bareword after number and concat op is not mistaken for eq";
	};

Creates a document object from the given code and stores it in $_, so the sub
passed in the second argument can quickly run tests on it.

=cut

sub check_with {
	my ( $code, $checker ) = @_;
	local $_ = safe_new \$code;
	return $checker->();
}

1;