bison: add test

Closes Homebrew/homebrew#35330.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Xu Cheng 2014-12-29 12:15:49 +08:00 committed by Mike McQuaid
parent eea3a4e39b
commit bf4fa3d19d

View file

@ -18,4 +18,32 @@ class Bison < 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