996
|
1 # test the options for intercalc
|
|
2
|
|
3 # Copyright (c) 2006-2008 Claudio Calvelli, all rights reserved.
|
|
4
|
|
5 # CLC-INTERCAL is copyrighted software. However, permission to use, modify,
|
|
6 # and distribute it is granted provided that the conditions set out in the
|
|
7 # licence agreement are met. See files README and COPYING in the distribution.
|
|
8
|
|
9 use IO::Handle;
|
|
10 require 't/run-calculator';
|
|
11
|
|
12 my @tests = (
|
|
13 ['Base 2', 2, [], '1972', '#V6', 'VII #V6'],
|
|
14 ['Base 3', 3, [], '1972', '#V6', 'VIII #V6'],
|
|
15 ['Base 4', 4, [], '1972', '#V6', 'xxxiiDCCLXXIV #V6'],
|
|
16 ['Base 5', 5, [], '1972', '#V6', 'MMMCXXXI #V6'],
|
|
17 ['Base 6', 6, [], '1972', '#V6', 'VII #V6'],
|
|
18 ['Base 7', 7, [], '1972', '#V6', 'xivCDXII #V6'],
|
|
19 ['Bitwise divide 1', 2, ['bitwise-divide'], 'sick', '#-65535', 'I #-65535'],
|
|
20 ['Bitwise divide 2', 2, [], 'sick', '#-65535', 'II #-65535'],
|
|
21 ['Wimp', 2, ['wimp'], '1972', '#V6', '7 #V6'],
|
|
22 );
|
|
23
|
|
24 my $maxtest = 2 + @tests;
|
|
25 print "1..$maxtest\n";
|
|
26
|
|
27 my @l = map { "-I$_" } @INC;
|
|
28
|
|
29 my $testnum = 1;
|
|
30 my ($pid, $read, $write) = run_calculator('expr', '1972');
|
|
31 print $read "#1\n"; flush $read;
|
|
32 my $line = <$write>;
|
|
33 chomp $line;
|
|
34 while ($line =~ /loading compiler/i) {
|
|
35 $line = <$write>;
|
|
36 chomp $line;
|
|
37 }
|
|
38 print $line =~ /\sI\s*#1$/ ? "" : "not ", "ok ", $testnum++, "\n";
|
|
39
|
|
40 for my $test (@tests) {
|
|
41 my ($name, $base, $option, $lang, $in, $out) = @$test;
|
|
42 print $read "`l$lang+", join(' ', @$option), "\n";
|
|
43 print $read "`b$base\n";
|
|
44 print $read "$in\n";
|
|
45 flush $read;
|
|
46 $line = <$write>;
|
|
47 defined $line or die "Calculator: end of input\n";
|
|
48 chomp $line;
|
|
49 my $dash = 0;
|
|
50 while ($line =~ / changed to |Option .* has been |loading compiler/i
|
|
51 || $line eq ''
|
|
52 || $line =~ /====/
|
|
53 || $dash)
|
|
54 {
|
|
55 $dash = ! $dash if $line =~ /====/;
|
|
56 $line = <$write>;
|
|
57 defined $line or die "Calculator: end of input\n";
|
|
58 chomp $line;
|
|
59 }
|
|
60 my $ok = 1;
|
|
61 $line =~ s/\s+/ /g;
|
|
62 $line =~ s/^ //;
|
|
63 $line =~ s/ $//;
|
|
64 if ($out ne $line) {
|
|
65 print STDERR "FAIL $name ($out ne $line)\n";
|
|
66 $ok = 0;
|
|
67 }
|
|
68 print $ok ? '' : "not ", "ok ", $testnum++, "\n";
|
|
69 }
|
|
70
|
|
71 close $read;
|
|
72 $ok = 1;
|
|
73 while (<$write>) {
|
|
74 chomp;
|
|
75 next if $_ eq '' || / changed to |Option .* has been |loading compiler/i;
|
|
76 print STDERR "FAIL (extra line $_)\n" if $ok;
|
|
77 $ok = 0;
|
|
78 }
|
|
79 print $ok ? '' : "not ", "ok ", $testnum++, "\n";
|
|
80 close $write;
|
|
81
|