File: sub_error.t

package info (click to toggle)
libconfig-grammar-perl 1.13-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 264 kB
  • sloc: perl: 1,352; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 924 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
#!/usr/sepp/bin/perl-5.6.1 -w

use lib 'lib';
use strict;
use Test::Simple tests => 3;
use Config::Grammar;

my $parser = Config::Grammar->new({
	_vars => [ 'var' ],
	_sections => [ 'table' ],
	_mandatory => [ 'var', 'table' ],
	var => {
		_sub => sub { $_[0] eq 'test' ? return undef : return 'error' },
	},
	table => {
		_table => {
			_columns => 1,
			0 => {
				_sub => sub { $_[0] eq 'test' ? return undef : return 'error'; },
			}
		}
	}
    });

ok(defined $parser, 'new works');

my $cfg = $parser->parse('t/sub_error1.conf');
if(defined $cfg) {
    ok(0, 'no error for variables'),
}
else {
    ok($parser->{err} eq 't/sub_error1.conf, line 1: error', '_sub error for variables');
}

$cfg = $parser->parse('t/sub_error2.conf');
if(defined $cfg) {
    ok(0, 'no error for table columns'),
}
else {
    ok($parser->{err} eq 't/sub_error2.conf, line 5: error', '_sub error for table columns');
}


# vi: ft=perl sw=4