From c34a3a15e28551bd22d38befbb0d543e1524e841 Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Mon, 29 Dec 2014 12:15:49 +0800 Subject: bison: add test Closes #35330. Signed-off-by: Mike McQuaid --- Library/Formula/bison.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'Library/Formula') diff --git a/Library/Formula/bison.rb b/Library/Formula/bison.rb index 87b2d6a95..e7a43cf09 100644 --- a/Library/Formula/bison.rb +++ b/Library/Formula/bison.rb @@ -18,4 +18,32 @@ class Bison < Formula "--prefix=#{prefix}" system "make", "install" end + + test do + (testpath/"test.y").write <<-EOS.undent + %{ #include + 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 -- cgit v1.2.3