Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Automated examples testing to prevent regression #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions examples/actor_example.mochi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<class '__main__.Message'>
__main__
foo
actor1 (<eventlet.greenthread.GreenThread object at 0x7f3204f5faf8>,)
bar 2000
foo 1000
foo 1000
bar 2000
Message! mefafsg pvector(['value'])
remote! pvector([pvector([3000])])
remo Message(tag=3000, value=1000)
Unsupported message! pmap({'x': pvector([1, 2, 3])})
Unsupported message! pset([1, pvector([2, 1, 2, 3])])
Unsupported message! pbag([1, pvector([2, 1, 2, 3])])
aaa
^CTraceback (most recent call last):
File "/home/mochiuser/.pyenv/versions/venv343mochi/bin/mochi", line 9, in <module>
load_entry_point('mochi==0.2.4.2', 'console_scripts', 'mochi')()
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/mochi/core/main.py", line 225, in main
load_file(args.file, global_env)
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/mochi/core/main.py", line 50, in load_file
return exec(compile_file(path), env)
File "examples/actor_example.mochi", line 63, in <module>
wait_all()
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/mochi/actor/actor.py", line 262, in wait_all
_actor_pool.waitall()
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/eventlet/greenpool.py", line 120, in waitall
self.no_coros_running.wait()
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/eventlet/event.py", line 121, in wait
return hubs.get_hub().switch()
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/eventlet/hubs/hub.py", line 294, in switch
return self.greenlet.switch()
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/eventlet/hubs/hub.py", line 346, in run
self.wait(sleep_time)
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/eventlet/hubs/poll.py", line 85, in wait
presult = self.do_poll(seconds)
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/eventlet/hubs/epolls.py", line 62, in do_poll
return self.poll.poll(seconds)
KeyboardInterrupt
2 changes: 2 additions & 0 deletions examples/aif.mochi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
empty
10
5 changes: 5 additions & 0 deletions examples/bind.mochi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
12
None
24
None
32
29 changes: 29 additions & 0 deletions examples/etc.mochi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
3
fa
200
faf
True
(4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 96, 100, 104, 108, 112, 116, 120)
pvector([2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60])
12 10
1200
pvector([2, 3])
pvector([2, 3])
pmap({'a': 3})
lll
100
fafa
finally
true
0.0025186538696289062 5
afaf
(2, 4, 6)
afaf
(2, 4, 6)
(2, 3)
<function _gs126.<locals>.fafa at 0x7fbd67d047b8>
10000
3000
2
1
['1 * 3 + (2 + 3)\n', 'x = 1 * 3 + (2 + 3)\n', 'x\n', 'type\n', 'True\n', 'if False:\n', ' z = "aiueo"\n', ' z + "kakiku"\n', 'elif False:\n', ' 100000\n', 'elif False:\n', ' 200000\n', 'else:\n', ' print "False!"\n', '\n', 'if True:\n', ' w = "aiueo"\n', ' w + "kakiku"\n', 'else:\n', ' "fafa"\n', '\n', ';[]\n', '# The semicolon at the beginning of the line is to avoid to combine "if" with "[]".\n', '[1]\n', '[1, 2]\n', '[w, 2, 3]\n', '\n', 'print([1, 2, 3][2])\n', '\n', 'def f():\n', ' print("f" + "a")\n', '\n', '\n', '(x) -> x\n', '\n', 'ff = (x, y) -> x\n', '\n', 'f()\n', 'print(200)\n', 'ff(1, 2)\n', '1 ^ ff(2) ^ ff(3)\n', '1 |> ff(2) |> ff(3)\n', '{}\n', '{"x" : 3}\n', '{"x" : 3, "y" : 1 + 1}\n', '{"y" + "z" : 3, "y" : 1 + 1}\n', '{x : 3}\n', '#zzz = cases 10:\n', '# | 10 => print(100000)\n', '# | _ => "else!"\n', '#\n', '#zzz\n', '\n', 'fff = match [1, 2, 3]:\n', ' [1, 2, 3]: True\n', '\n', 'print("faf")\n', 'print(fff)\n', '\n', 'match {"x": [1, 2, 3]}:\n', ' {"x": [1, _, y]}: y\n', '\n', '#case {"x": (1, 2, 3)}\n', '# {"x": 100}\n', '# {"x": z} :\n', '\n', '# xyz = if True: 0 else: 100\n', '\n', '# xyz\n', '\n', '[z1, &z2] = [1, 2, 3, 4, 5]\n', 'z2\n', '\n', 'get(z2, 0, 2)\n', '\n', '[item * 2 for item in range(1, 31)] |> map(-> $1 * 2) |> tuple() |> print()\n', '[item * 2 for item in range(1, 31)] |> print()\n', '\n', '"faf".__str__()\n', 'if 21 + -20 == 1 and True:\n', ' zz = (-> $1 + $2)(100, 200)\n', 'else:\n', ' zz2 = (-> $1 + $2)(100, 20)\n', '\n', '1 + 1\n', '3 + 2\n', '\n', 'print(str(1) + str(2), 10)\n', '\n', 'tuple(map(-> $1 + 10 if True else $1 + 20, [1, 2, 3]))\n', '\n', 'match ["faa", 200]:\n', ' ["aaa", xx]: print(xx + 200)\n', ' ["faa", xxx]: print(xxx + 1000)\n', '\n', 'def fr(x, y):\n', ' [x + 1, y()]\n', '\n', 'fr2 = flip(fr)\n', 'print(fr2(-> 1 + 2, 1))\n', 'print(fr(1, -> 1 + 2))\n', '\n', '\n', '#record Node(x, y)\n', '\n', '#r = Node(10, 20)\n', '#case r:\n', '# Node(x, 20) => x\n', '\n', '#record Node2(value, left, right)\n', '\n', 'data BinTree:\n', ' Leaf(value)\n', ' Node(value, left, right)\n', '\n', 'Leaf(20)\n', 'Node(1, 2, 3)\n', 'Node(1, 2, 3)\n', 'Node(10, 15, 40)\n', 'Node(20, 100, Leaf(40))\n', '\n', '\n', 'import flask\n', 'from PIL import Image\n', '\n', 'module fafa:\n', ' export a, b, lll\n', ' a = 100\n', ' b = {"a" : 3}\n', ' c = 300\n', ' def lll():\n', ' print("lll")\n', '\n', 'print(fafa.b)\n', '\n', 'fafa.lll()\n', '\n', 'import flask\n', '\n', 'def xxxx():\n', ' try:\n', ' print(100)\n', ' raise Exception("fafa")\n', ' except Exception as e:\n', ' print(e)\n', ' except Exception as b:\n', ' print(b)\n', ' finally:\n', ' print("finally")\n', '\n', 'xxxx()\n', 'if True:\n', ' print("true")\n', 'else:\n', ' print("fafa")\n', '\n', '\n', 'from time import time\n', '\n', '#def tak(x, y, z):\n', '# if x <= y:\n', '# z\n', '# else:\n', '# tak(tak(x - 1, y, z), tak(y - 1, z, x), tak(z - 1, x, y))\n', '\n', 'def tak(x, y, z):\n', ' if x <= y:\n', ' return z\n', ' else:\n', ' return tak(tak(x - 1, y, z), tak(y - 1, z, x), tak(z - 1, x, y))\n', '\n', 'start = time()\n', 'res = tak(10, 5, 0)\n', 'print(time() - start, res)\n', '\n', 'map(-> $1 * 2, [1, 2, 3])\n', 'print("afaf")\n', 'print(tuple(map(-> $1 * 2, [1, 2, 3])))\n', 'print("afaf")\n', 'map((item) -> item * 2, [1, 2, 3]) |> tuple() |> print()\n', '\n', '#fffff = x, y -> print(x, y)\n', '#fffff(10, 20)\n', '#print([int(1), 2, "a" + "b"], [2, 4, 6])\n', '\n', '\n', 'def vagrgs(a, &rest):\n', ' print(rest)\n', '\n', 'vagrgs(1, 2, 3)\n', '\n', 'require "etc_inner.mochi"\n', '\n', 'print(TestB.fafa)\n', 'TestB.fafa()\n', '\n', 'def fafa():\n', ' x = 3000\n', ' x\n', '\n', 'print(fafa())\n', '\n', 'def print_mochi_py:\n', ' 0:\n', " with open('./etc.mochi', 'r') as f:\n", ' print(f.readlines())\n', ' n:\n', " with open('./etc.mochi', 'r') as f:\n", ' f.readlines()\n', ' print(n)\n', ' print_mochi_py(n - 1)\n', '\n', 'print_mochi_py(2)']
Empty file added examples/etc_inner.mochi.out
Empty file.
4 changes: 4 additions & 0 deletions examples/fact.mochi.out

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions examples/fact_pattern.mochi.out

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/fizzbuzz.mochi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pvector([1, 2, 'fizz', 4, 'buzz', 'fizz', 7, 8, 'fizz', 'buzz', 11, 'fizz', 13, 14, 'fizzbuzz', 16, 17, 'fizz', 19, 'buzz', 'fizz', 22, 23, 'fizz', 'buzz', 26, 'fizz', 28, 29, 'fizzbuzz'])
2 changes: 2 additions & 0 deletions examples/flask_demo.mochi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
^C
12 changes: 12 additions & 0 deletions examples/flask_restful.mochi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Traceback (most recent call last):
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/mochi/core/main.py", line 225, in main
load_file(args.file, global_env)
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/mochi/core/main.py", line 50, in load_file
return exec(compile_file(path), env)
File "flask_restful.mochi", line 0, in <module>
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/flask/exthook.py", line 81, in load_module
reraise(exc_type, exc_value, tb.tb_next)
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/flask/_compat.py", line 32, in reraise
raise value.with_traceback(tb)
File "/home/mochiuser/workdir/examples/flask_restful.mochi", line 7, in <module>
ImportError: cannot import name 'Resource'
5 changes: 5 additions & 0 deletions examples/keyword_arguments.mochi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
6
pmap({'a': 1, 'b': 2})

6
pmap({'a': 1, 'b': 2})
3 changes: 3 additions & 0 deletions examples/macro_example.mochi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pvector([1, 2, 3])
False
pvector([4, 6])
Empty file added examples/sida.mochi.out
Empty file.
1 change: 1 addition & 0 deletions examples/tak.mochi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
23.061758756637573 1
112 changes: 112 additions & 0 deletions examples/testexamples
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/sh
# Test whether example output changed (regression introduced).
#
# This script uses by default mochidocker wrapper to have a 100% reproducible
# run-time environment. This can be overriden to use a real mochi command
# (instead of the Docker wrapper). The ability to override the mochi command
# can also be used to force a different Docker image by using --dockerimg with
# mochidocker.
#
# The test performed is really stupid and simple right now: if the new .out
# file is different than the committed one, we conclude the test failed
# (assuming some code change has introduced a regression, which changed the
# .out file content).
#
# If we modify the example file, we have to rebuild/regenerate the matching
# .out file.

CURRENT_DIR="`pwd`"
cd "`dirname "$0"`"
THIS_DIR="`pwd`"
THIS_FILE="`basename "$0"`"
cd ..
MOCHI_CHECKOUT_ROOT="`pwd`"
cd "$CURRENT_DIR"


# these examples do not terminate on their own
EXCLUDE_LIST="
actor_example.mochi
flask_demo.mochi
"

# --dockerdevel to use code in current checkout, not old code in the docker
# image
DEFAULT_MOCHI_CMD="../bin/mochidocker --dockerdevel"


showusage() {
echo "Usage: $THIS_FILE [options]


Ex:
Test all examples
\$ $THIS_FILE

Test all exaples using a different mochi command than the default one
\$ $THIS_FILE --mochicmd \"path/to/mochi\"

Rebuild all the .out files
\$ $THIS_FILE --rebuild


Options:
--mochicmd cmd Alternate mochi command, default: $DEFAULT_MOCHI_CMD
--rebuild Rebuild all the .out files
--help Show this help
"
}


MOCHI_CMD="$DEFAULT_MOCHI_CMD"
REBUILD_MODE=""
while [ -n "$1" ]; do
case "$1" in
--mochicmd) shift
MOCHI_CMD="$1"; shift
;;
--rebuild) shift
REBUILD_MODE=1
;;
--help) shift
showusage
exit
;;
*)
showusage
echo "ERROR: invalid option '$1'" 1>&2
exit 2
;;
esac
done


TMPDIR="`mktemp -d`"
EXIT_CODE=0

cd "$THIS_DIR"
for f in *.mochi; do
if [ -z "`echo "$EXCLUDE_LIST" | grep $f`" ]; then
OUT_FILE="${f}.out"
if [ -n "$REBUILD_MODE" ]; then
echo "Rebuilding $OUT_FILE"
$MOCHI_CMD "$f" >& "$OUT_FILE"
if [ $? -ne 0 ]; then
echo "ERROR: $OUT_FILE rebuild failed"
# set EXIT_CODE to failed as soon as one example rebuild failed
EXIT_CODE=1
fi
else
$MOCHI_CMD "$f" >& "$TMPDIR/$OUT_FILE"
diff "$OUT_FILE" "$TMPDIR/$OUT_FILE"
if [ $? -ne 0 ]; then
echo "ERROR: $f changed"
# set EXIT_CODE to failed as soon as one example output changed
EXIT_CODE=1
fi
fi
fi
done

rm -rf "$TMPDIR"
exit $EXIT_CODE
7 changes: 7 additions & 0 deletions examples/timer.mochi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Traceback (most recent call last):
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/mochi/core/main.py", line 225, in main
load_file(args.file, global_env)
File "/home/mochiuser/.pyenv/versions/venv343mochi/lib/python3.4/site-packages/mochi/core/main.py", line 50, in load_file
return exec(compile_file(path), env)
File "timer.mochi", line 0, in <module>
ImportError: No module named 'rx'
10 changes: 10 additions & 0 deletions examples/trailing_closure.mochi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1
2
3
pvector([2, 4, 6])
100
200
300
100
200
300
12 changes: 12 additions & 0 deletions examples/urlopen.mochi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
神奈川県 横浜 の天気
今日 晴のち曇
明日 曇のち雨

東京都 東京 の天気
今日 晴のち曇
明日 曇のち雨

福岡県 久留米 の天気
今日 曇のち雨
明日 雨のち晴

4 changes: 4 additions & 0 deletions examples/yield.mochi.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1
2
3