Add the following packages libalgorithm-diff-perl libspiffy-perl libtext-diff-perl...
[pkg-perl] / deb-src / libfilter-perl / libfilter-perl-1.34 / t / cpp.t
1
2 use strict;
3 use warnings;
4 use Config;
5
6 BEGIN 
7 {
8     my $cpp;
9     my $sep;
10     if ($^O eq 'MSWin32') {
11         $cpp = 'cpp.exe' ;
12         $sep = ';';
13     }
14     else {
15         ($cpp) = $Config{cppstdin} =~ /^(\S+)/;
16         $sep = ':';
17     }
18      
19     if (! $cpp) {
20         print "1..0 # Skipping cpp not found on this system.\n" ;
21         exit 0 ;
22     }
23      
24     # Check if cpp is installed
25     if ( ! -x $cpp) {
26         my $foundCPP = 0 ;
27         foreach my $dir (split($sep, $ENV{PATH}), '')
28         {
29             if (-x "$dir/$cpp")
30             {
31                 $foundCPP = 1;
32                 last ;
33             }
34         }
35      
36         if (! $foundCPP) {
37             print "1..0 # Skipping cpp not found on this system.\n" ;
38             exit 0 ;
39         }
40     }                              
41 }
42
43 use vars qw( $Inc $Perl ) ;
44
45 require "./filter-util.pl" ;
46
47 my $script = <<'EOF' ;
48 use Filter::cpp ;
49 #define FRED 1
50 #define JOE
51
52 #a perl comment, not a cpp line
53
54 $a = FRED + 2 ;
55 print "a = $a\n" ;
56
57 require "./fred" ;
58
59 #ifdef JOE
60   print "Hello Joe\n" ;
61 #else
62   print "Where is Joe?\n" ;
63 #endif
64 EOF
65
66 my $cpp_script = 'cpp.script' ;
67 writeFile($cpp_script, $script) ;
68 writeFile('fred', 'print "This is FRED, not JOE\n" ; 1 ;') ;
69
70 my $expected_output = <<'EOM' ;
71 a = 3
72 This is FRED, not JOE
73 Hello Joe
74 EOM
75
76 $a = `$Perl $Inc $cpp_script 2>&1` ;
77
78 print "1..2\n" ;
79 ok(1, ($? >>8) == 0) ;
80 #print "|$a| vs |$expected_output|\n";
81 ok(2, $a eq $expected_output) ;
82
83 unlink $cpp_script ;
84 unlink 'fred' ;