File: test-line-parse

package info (click to toggle)
libterm-shellui-perl 0.92-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid
  • size: 336 kB
  • sloc: perl: 1,286; makefile: 2
file content (54 lines) | stat: -rwxr-xr-x 1,633 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl -w

# Tests the Term::ShellUI tokenizer/parser.
# Pass the indexes of the tests you want to run as arguments.
# If no arguments supplied, runs all tests.
# If arguments supplied, verbosely displays results.

use strict;

use lib '.';
use Parse;
use lib '../lib';
use Text::Shellwords::Cursor;

use FreezeThaw qw(freeze cmpStr);
use YAML qw(Dump);

my $parser = Text::Shellwords::Cursor->new();
die "No parser" unless $parser;

# Parse cmdline args
my %seltest;
for(@ARGV) { $seltest{$_} = 1; }
my $verbose = 1, $parser->{debug} = 1 if @ARGV;

print "\nTest Result\n---------------------------------\n" unless $verbose;

my($ntests, $nfail) = (0,0);
for my $input (sort keys %Parse::Tests) {
    my($index,$cpos,$test) = $input =~ /^(\d+):(\d*):(.*)$/;
    die "No test in item $index:    $input\n" unless defined $test;
    next if %seltest && !exists($seltest{0+$index});

    my($toks, $tokno, $tokoff) = $parser->parse_line($test, messages=>$verbose, cursorpos=>$cpos);
    my $result = [$toks, $tokno, $tokoff];
    my $eq = 0 == cmpStr($result, $Parse::Tests{$input});
    
    if($verbose) {
        print "\nTest $index: $test cursor=$cpos\n";
        print "Expected output: " . freeze($Parse::Tests{$input}) . "\n";
        print Dump($Parse::Tests{$input});
        print "Received output: " . freeze($result) . "\n";
        print Dump($result);
    } else {
        printf("%2d: %s    $test\n", $index, ($eq ? 'OK  ' : 'FAIL'));
    }

    $ntests++;
    $nfail++ unless $eq;
}

print "\n\n$ntests test" . ($ntests == 1 ? "" : "s") ." run, ";
print "$nfail failure" . ($nfail == 1 ? "" : "s") . ".\n\n";