bison@2.7: add test
This commit is contained in:
parent
5a00d5806e
commit
df0af97e1b
1 changed files with 28 additions and 0 deletions
|
@ -12,4 +12,32 @@ class BisonAT27 < Formula
|
|||
"--prefix=#{prefix}"
|
||||
system "make", "install"
|
||||
end
|
||||
|
||||
test do
|
||||
(testpath/"test.y").write <<-EOS.undent
|
||||
%{ #include <iostream>
|
||||
using namespace std;
|
||||
extern void yyerror (char *s);
|
||||
extern int yylex ();
|
||||
%}
|
||||
%start prog
|
||||
%%
|
||||
prog: // empty
|
||||
| prog expr '\\n' { cout << "pass"; exit(0); }
|
||||
;
|
||||
expr: '(' ')'
|
||||
| '(' expr ')'
|
||||
| expr expr
|
||||
;
|
||||
%%
|
||||
char c;
|
||||
void yyerror (char *s) { cout << "fail"; exit(0); }
|
||||
int yylex () { cin.get(c); return c; }
|
||||
int main() { yyparse(); }
|
||||
EOS
|
||||
system "#{bin}/bison", "test.y"
|
||||
system ENV.cxx, "test.tab.c", "-o", "test"
|
||||
assert_equal "pass", shell_output("echo \"((()(())))()\" | ./test")
|
||||
assert_equal "fail", shell_output("echo \"())\" | ./test")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue