[Pkg-ocaml-maint-commits] [menhir] 09/09: as-installed package test
Ralf Treinen
treinen at moszumanska.debian.org
Mon Jun 19 20:19:45 UTC 2017
This is an automated email from the git hooks/post-receive script.
treinen pushed a commit to branch master
in repository menhir.
commit 3163380ef3659f70bf8bf3554e78bb60f5ebee5e
Author: Ralf Treinen <treinen at free.fr>
Date: Mon Jun 19 22:12:43 2017 +0200
as-installed package test
---
debian/changelog | 3 ++-
debian/tests/calc/.merlin | 1 +
debian/tests/calc/README | 9 +++++++++
debian/tests/calc/calc.ml | 28 ++++++++++++++++++++++++++
debian/tests/calc/lexer.mll | 48 ++++++++++++++++++++++++++++++++++++++++++++
debian/tests/calc/parser.mly | 33 ++++++++++++++++++++++++++++++
debian/tests/calcdemo | 18 +++++++++++++++++
debian/tests/control | 2 ++
8 files changed, 141 insertions(+), 1 deletion(-)
diff --git a/debian/changelog b/debian/changelog
index cc1aa70..48dc820 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -7,8 +7,9 @@ menhir (20170607.dfsg-1) unstable; urgency=medium
- simplify (drop useless CURDIR)
- generate tarball with version "+dfsg" instead of ".dfsg"
* Add myself as uploader
+ * Add as-installed package test
- -- Ralf Treinen <treinen at debian.org> Mon, 19 Jun 2017 21:37:55 +0200
+ -- Ralf Treinen <treinen at debian.org> Mon, 19 Jun 2017 22:11:44 +0200
menhir (20160808+dfsg-1) unstable; urgency=medium
diff --git a/debian/tests/calc/.merlin b/debian/tests/calc/.merlin
new file mode 100644
index 0000000..1a1fd25
--- /dev/null
+++ b/debian/tests/calc/.merlin
@@ -0,0 +1 @@
+B _build
diff --git a/debian/tests/calc/README b/debian/tests/calc/README
new file mode 100644
index 0000000..f6f0223
--- /dev/null
+++ b/debian/tests/calc/README
@@ -0,0 +1,9 @@
+This example is the 'calc' demo from the upstream distribution.
+
+This tiny program reads arithmetic expressions from the standard input
+channel. Each expression is expected to be complete when the current line
+ends. Its value is then displayed on the standard output channel. This
+code is adapted from ocamlyacc's documentation.
+
+We compile the parser using Menhir's code back-end. For an example of using
+Menhir's table back-end, see the calc-incremental/ and calc-inspection/.
diff --git a/debian/tests/calc/calc.ml b/debian/tests/calc/calc.ml
new file mode 100644
index 0000000..d5de4c8
--- /dev/null
+++ b/debian/tests/calc/calc.ml
@@ -0,0 +1,28 @@
+let process (line : string) =
+ let linebuf = Lexing.from_string line in
+ try
+ (* Run the parser on this line of input. *)
+ Printf.printf "%d\n%!" (Parser.main Lexer.token linebuf)
+ with
+ | Lexer.Error msg ->
+ Printf.fprintf stderr "%s%!" msg
+ | Parser.Error ->
+ Printf.fprintf stderr "At offset %d: syntax error.\n%!" (Lexing.lexeme_start linebuf)
+
+let process (optional_line : string option) =
+ match optional_line with
+ | None ->
+ ()
+ | Some line ->
+ process line
+
+let rec repeat channel =
+ (* Attempt to read one line. *)
+ let optional_line, continue = Lexer.line channel in
+ process optional_line;
+ if continue then
+ repeat channel
+
+let () =
+ repeat (Lexing.from_channel stdin)
+
diff --git a/debian/tests/calc/lexer.mll b/debian/tests/calc/lexer.mll
new file mode 100644
index 0000000..437eb0c
--- /dev/null
+++ b/debian/tests/calc/lexer.mll
@@ -0,0 +1,48 @@
+{
+ open Parser
+
+ exception Error of string
+
+}
+
+(* This rule looks for a single line, terminated with '\n' or eof.
+ It returns a pair of an optional string (the line that was found)
+ and a Boolean flag (false if eof was reached). *)
+
+rule line = parse
+| ([^'\n']* '\n') as line
+ (* Normal case: one line, no eof. *)
+ { Some line, true }
+| eof
+ (* Normal case: no data, eof. *)
+ { None, false }
+| ([^'\n']+ as line) eof
+ (* Special case: some data but missing '\n', then eof.
+ Consider this as the last line, and add the missing '\n'. *)
+ { Some (line ^ "\n"), false }
+
+(* This rule analyzes a single line and turns it into a stream of
+ tokens. *)
+
+and token = parse
+| [' ' '\t']
+ { token lexbuf }
+| '\n'
+ { EOL }
+| ['0'-'9']+ as i
+ { INT (int_of_string i) }
+| '+'
+ { PLUS }
+| '-'
+ { MINUS }
+| '*'
+ { TIMES }
+| '/'
+ { DIV }
+| '('
+ { LPAREN }
+| ')'
+ { RPAREN }
+| _
+ { raise (Error (Printf.sprintf "At offset %d: unexpected character.\n" (Lexing.lexeme_start lexbuf))) }
+
diff --git a/debian/tests/calc/parser.mly b/debian/tests/calc/parser.mly
new file mode 100644
index 0000000..eeb104f
--- /dev/null
+++ b/debian/tests/calc/parser.mly
@@ -0,0 +1,33 @@
+%token <int> INT
+%token PLUS MINUS TIMES DIV
+%token LPAREN RPAREN
+%token EOL
+
+%left PLUS MINUS /* lowest precedence */
+%left TIMES DIV /* medium precedence */
+%nonassoc UMINUS /* highest precedence */
+
+%start <int> main
+
+%%
+
+main:
+| e = expr EOL
+ { e }
+
+expr:
+| i = INT
+ { i }
+| LPAREN e = expr RPAREN
+ { e }
+| e1 = expr PLUS e2 = expr
+ { e1 + e2 }
+| e1 = expr MINUS e2 = expr
+ { e1 - e2 }
+| e1 = expr TIMES e2 = expr
+ { e1 * e2 }
+| e1 = expr DIV e2 = expr
+ { e1 / e2 }
+| MINUS e = expr %prec UMINUS
+ { - e }
+
diff --git a/debian/tests/calcdemo b/debian/tests/calcdemo
new file mode 100755
index 0000000..8a3d38c
--- /dev/null
+++ b/debian/tests/calcdemo
@@ -0,0 +1,18 @@
+#!/bin/sh -e
+
+this=calc
+indir=debian/tests
+outdir=${ADT_ARTIFACTS:-/tmp}/${this}
+mkdir -p ${outdir}
+
+cp ${indir}/${this}/* ${outdir}
+cd ${outdir}
+ocamlbuild -quiet -use-ocamlfind -use-menhir -menhir "menhir --infer" \
+ calc.byte
+[ $(echo "(1 + 2 * 10) * 2" | ./calc.byte) -eq '42' ]
+
+if [ -x /usr/bin/ocamlopt ]
+then ocamlbuild -quiet -use-ocamlfind -use-menhir -menhir "menhir --infer" \
+ calc.native
+[ $(echo "(1 + 2 * 10) * 2" | ./calc.native) -eq '42' ]
+fi
diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..81227bc
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,2 @@
+Tests: calcdemo
+Depends: ocaml-nox, libfindlib-ocaml
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ocaml-maint/packages/menhir.git
More information about the Pkg-ocaml-maint-commits
mailing list