]> Dogcows Code - chaz/p5-CGI-Ex/blob - t/1_validate_10_storable_file.t
add PSGI handler
[chaz/p5-CGI-Ex] / t / 1_validate_10_storable_file.t
1 # -*- Mode: Perl; -*-
2
3 use strict;
4
5 $^W = 1;
6
7 ### determine number of tests
8 seek(DATA,0,0);
9 my $prog = join "", <DATA>;
10 my @tests = ($prog =~ /&print_ok\(/g);
11 my $tests = @tests;
12 print "1..$tests\n";
13
14 require CGI::Ex::Validate;
15
16 my ($N, $v, $e, $ok) = (0);
17
18 sub validate {
19 return scalar &CGI::Ex::Validate::validate(@_);
20 }
21 sub print_ok {
22 my $ok = shift;
23 $N ++;
24 warn "Test failed at line ".(caller)[2]."\n" if ! $ok;
25 print "" . ($ok ? "" : "not ") . "ok $N\n";
26 }
27 &print_ok(1);
28
29 ###----------------------------------------------------------------###
30
31 ### where are my samples
32 my $dir = __FILE__;
33 $dir =~ tr|\\|/|; # should probably use File::Spec
34 $dir =~ s|[^/]+$|samples| || die "Couldn't determine dir";
35 $dir =~ s|^t/|./t/|; # to satisfy conf
36
37 ### single group
38 $v = "$dir/storable1.storable";
39
40 ### don't use the included binary - write our own - for portable tests
41 my $val = {
42 user => {
43 required => 1,
44 },
45 foo => {
46 required_if => 'bar',
47 },
48 };
49 &print_ok(eval {require Storable});
50 &print_ok(&Storable::store($val, $v));
51
52 $e = &validate({}, $v);
53 &print_ok($e);
54 $e = &validate({user => 1}, $v);
55 &print_ok(! $e);
56 $e = &validate({user => 1, bar => 1}, $v);
57 &print_ok($e);
58 $e = &validate({user => 1, bar => 1, foo => 1}, $v);
59 &print_ok(! $e);
60
61 __DATA__
This page took 0.037335 seconds and 4 git commands to generate.