1# Same as t_code.t, but using ParseRegExp.pm.
2use warnings;
3use strict;
4use InlineX::C2XS qw(c2xs);
5
6print "1..2\n";
7
8my $code = "simple_double  simple(simple_double);\nextra_simple_double x_simple(extra_simple_double);";
9
10my %config_opts = (
11                  'USING' => ['ParseRegExp'],
12                  'AUTOWRAP' => 1,
13                  'AUTO_INCLUDE' => '#include <simple.h>' . "\n" .'#include "src/extra_simple.h"',
14                  'TYPEMAPS' => ['src/simple_typemap.txt'],
15                  'INC' => '-Isrc',
16                  'CODE' => $code,
17                  );
18
19c2xs('testc', 'testc', '.', \%config_opts);
20
21my ($ok, $ok2) = (1, 1);
22my @rd1;
23my @rd2;
24
25if(!rename('testc.xs', 'testc.txt')) {
26  warn "couldn't rename testc.xs\n";
27  print "not ok 1\n";
28  $ok = 0;
29}
30
31if($ok) {
32  if(!open(RD1, "testc.txt")) {
33    warn "unable to open testc.txt for reading: $!\n";
34    print "not ok 1\n";
35    $ok = 0;
36  }
37}
38
39if($ok) {
40  if(!open(RD2, "expected_code.txt")) {
41    warn "unable to open expected_code.txt for reading: $!\n";
42    print "not ok 1\n";
43    $ok = 0;
44  }
45}
46
47if($ok) {
48  @rd1 = <RD1>;
49  @rd2 = <RD2>;
50}
51
52if($ok) {
53  if(scalar(@rd1) != scalar(@rd2)) {
54    warn "testc.txt does not have the expected number of lines\n";
55    print "not ok 1\n";
56    $ok = 0;
57  }
58}
59
60if($ok) {
61  for(my $i = 0; $i < scalar(@rd1); $i++) {
62     # Try to take care of platform/machine-specific issues
63     # regarding line endings and whitespace.
64     $rd1[$i] =~ s/\s//g;
65     $rd2[$i] =~ s/\s//g;
66     #$rd1[$i] =~ s/\r//g;
67     #$rd2[$i] =~ s/\r//g;
68
69     if($rd1[$i] ne $rd2[$i]) {
70       warn "At line ", $i + 1, ":\n     GOT:", $rd1[$i], "*\nEXPECTED:", $rd2[$i], "*\n";
71       $ok2 = 0;
72       last;
73     }
74  }
75}
76
77if(!$ok2) {
78  warn "testc.txt does not match expected_code.txt\n";
79  print "not ok 1\n";
80}
81
82elsif($ok) {print "ok 1\n"}
83
84close(RD1) or warn "Unable to close testc.txt after reading: $!\n";
85close(RD2) or warn "Unable to close expected_code.txt after reading: $!\n";
86if(!unlink('testc.txt')) { warn "Couldn't unlink testc.txt\n"}
87
88($ok, $ok2) = (1, 1);
89
90###########################################################################
91
92if(!open(RD1, "INLINE.h")) {
93  warn "unable to open INLINE.h for reading: $!\n";
94  print "not ok 2\n";
95  $ok = 0;
96}
97
98if($ok) {
99  if(!open(RD2, "expected.h")) {
100    warn "unable to open expected.h for reading: $!\n";
101    print "not ok 2\n";
102    $ok = 0;
103  }
104}
105
106if($ok) {
107  @rd1 = <RD1>;
108  @rd2 = <RD2>;
109}
110
111if($ok) {
112  if(scalar(@rd1) != scalar(@rd2)) {
113    warn "INLINE.h does not have the expected number of lines\n";
114    print "not ok 2\n";
115    $ok = 0;
116  }
117}
118
119if($ok) {
120  for(my $i = 0; $i < scalar(@rd1); $i++) {
121     # Try to take care of platform/machine-specific issues
122     # regarding line endings and whitespace.
123     $rd1[$i] =~ s/\s//g;
124     $rd2[$i] =~ s/\s//g;
125     #$rd1[$i] =~ s/\r//g;
126     #$rd2[$i] =~ s/\r//g;
127
128     if($rd1[$i] ne $rd2[$i]) {
129       warn "At line ", $i + 1, ":\n     GOT:", $rd1[$i], "*\nEXPECTED:", $rd2[$i], "*\n";
130       $ok2 = 0;
131       last;
132     }
133  }
134}
135
136if(!$ok2) {
137  warn "INLINE.h does not match expected.h\n";
138  print "not ok 2\n";
139}
140
141elsif($ok) {print "ok 2\n"}
142
143close(RD1) or warn "Unable to close INLINE.h after reading: $!\n";
144close(RD2) or warn "Unable to close expected.h after reading: $!\n";
145if(!unlink('INLINE.h')) { warn "Couldn't unlink INLINE.h\n"}
146
147
148