File: m4.t

package info (click to toggle)
libfilter-perl 1.64-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 668 kB
  • sloc: perl: 963; makefile: 10
file content (101 lines) | stat: -rw-r--r-- 1,674 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# m4.t

use strict;
use warnings;
use Config;

use FindBin;
use lib "$FindBin::Bin"; # required to load filter-util.pl

BEGIN {
    my $m4;
    my $sep;

    if ($^O eq 'MSWin32') {
        $m4 = 'm4.exe';
        $sep = ';';
    }
    else {
        $m4 = 'm4';
        $sep = ':';
    }
    if (!$m4) {
        print "1..0 # Skipping m4 not found on this system.\n" ;
        exit 0 ;
    }

    # Check whether m4 is installed
    if (!-x $m4) {
        my $foundM4 = 0;
        foreach my $dir (split($sep, $ENV{PATH}), '') {
            if (-x "$dir/$m4") {
                $foundM4 = 1;
                last;
            }
        }
        if (!$foundM4) {
            print "1..0 # Skipping m4 not found on this system.\n" ;
            exit 0;
        }
    }
}

use vars qw($Inc $Perl);

require "filter-util.pl";


# normal module invocation

my $script = <<'EOF';
use Filter::m4;

define(`bar2baz', `$1 =~ s/bar/baz/')

$a = "foobar";
bar2baz(`$a');
print "a = $a\n";
EOF

my $m4_script = 'm4.script';
writeFile($m4_script, $script);

my $expected_output = <<'EOM';
a = foobaz
EOM


# module invocation with argument 'prefix'

my $prefix_script = <<'EOF';
use Filter::m4 'prefix';

m4_define(`bar2baz', `$1 =~ s/bar/baz/')

$a = "foobar";
bar2baz(`$a');
print "a = $a\n";
EOF

my $m4_prefix_script = 'm4_prefix.script';
writeFile($m4_prefix_script, $prefix_script);

my $expected_prefix_output = <<'EOM';
a = foobaz
EOM


print "1..3\n";
ok(1, ($? >>8) == 0);

$a = `$Perl $Inc $m4_script 2>&1`;
ok(2, $a eq $expected_output);

$a = `$Perl $Inc $m4_prefix_script 2>&1`;
ok(3, $a eq $expected_prefix_output);


unlink $m4_script;
unlink $m4_prefix_script;

# EOF