bison: add test
Closes Homebrew/homebrew#35330. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
parent
eea3a4e39b
commit
bf4fa3d19d
1 changed files with 28 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue