File: cpp.t

package info (click to toggle)
libfilter-perl 1.64-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 668 kB
  • sloc: perl: 963; makefile: 10
file content (83 lines) | stat: -rw-r--r-- 1,496 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

use strict;
use warnings;
use Config;

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

BEGIN {
    my $cpp;
    my $sep;

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

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

use vars qw( $Inc $Perl ) ;

require "filter-util.pl" ;

my $script = <<'EOF' ;
use Filter::cpp ;
#define FRED 1
#define JOE

#a perl comment, not a cpp line

$a = FRED + 2 ;
print "a = $a\n" ;

require "./fred" ;

#ifdef JOE
  print "Hello Joe\n" ;
#else
  print "Where is Joe?\n" ;
#endif
EOF

my $cpp_script = 'cpp.script' ;
writeFile($cpp_script, $script) ;
writeFile('fred', 'print "This is FRED, not JOE\n" ; 1 ;') ;

my $expected_output = <<'EOM' ;
a = 3
This is FRED, not JOE
Hello Joe
EOM

$a = `$Perl $Inc $cpp_script 2>&1` ;

print "1..2\n" ;
ok(1, ($? >>8) == 0) ;
#print "|$a| vs |$expected_output|\n";
ok(2, $a eq $expected_output) ;

unlink $cpp_script ;
unlink 'fred' ;