Skip to content

Commit c4a3509

Browse files
authored
Merge pull request #60 from haya14busa/test-js-py
Run tests with generated python and javascript vimlparser
2 parents 8f207d5 + ac0fba9 commit c4a3509

File tree

7 files changed

+77
-13
lines changed

7 files changed

+77
-13
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ matrix:
1616
- MAKE_TARGET=test
1717
- env:
1818
- VIM_VERSION=installed
19-
- MAKE_TARGET="clean_compiled check"
19+
- MAKE_TARGET="clean_compiled check js/test py/test"
2020

2121
install:
2222
- |

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ check: all
1919

2020
test:
2121
test/run.sh
22+
23+
js/test: js/vimlparser.js
24+
test/run_command.sh node js/vimlparser.js
25+
26+
py/test: py/vimlparser.py
27+
test/run_command.sh python py/vimlparser.py

js/vimlfunc.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ function main() {
2020
var r = new StringReader(viml_readfile(fpath));
2121
var p = new VimLParser(neovim);
2222
var c = new Compiler();
23-
var lines = c.compile(p.parse(r))
24-
for (var i in lines) {
25-
process.stdout.write(lines[i] + "\n");
23+
try {
24+
var lines = c.compile(p.parse(r));
25+
for (var i in lines) {
26+
process.stdout.write(lines[i] + "\n");
27+
}
28+
} catch (e) {
29+
process.stdout.write(e + '\n');
2630
}
2731
}
2832

js/vimlparser.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ function main() {
2020
var r = new StringReader(viml_readfile(fpath));
2121
var p = new VimLParser(neovim);
2222
var c = new Compiler();
23-
var lines = c.compile(p.parse(r))
24-
for (var i in lines) {
25-
process.stdout.write(lines[i] + "\n");
23+
try {
24+
var lines = c.compile(p.parse(r));
25+
for (var i in lines) {
26+
process.stdout.write(lines[i] + "\n");
27+
}
28+
} catch (e) {
29+
process.stdout.write(e + '\n');
2630
}
2731
}
2832

py/vimlfunc.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
def main():
99
use_neovim = sys.argv[1] == '--neovim'
10-
10+
1111
r = StringReader(viml_readfile(sys.argv[-1]))
1212
p = VimLParser(use_neovim)
1313
c = Compiler()
14-
for line in c.compile(p.parse(r)):
15-
print(line)
14+
try:
15+
for line in c.compile(p.parse(r)):
16+
print(line)
17+
except VimLParserException as e:
18+
print(e)
19+
sys.exit(1)
1620

1721
class VimLParserException(Exception):
1822
pass

py/vimlparser.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
def main():
99
use_neovim = sys.argv[1] == '--neovim'
10-
10+
1111
r = StringReader(viml_readfile(sys.argv[-1]))
1212
p = VimLParser(use_neovim)
1313
c = Compiler()
14-
for line in c.compile(p.parse(r)):
15-
print(line)
14+
try:
15+
for line in c.compile(p.parse(r)):
16+
print(line)
17+
except VimLParserException as e:
18+
print(e)
19+
sys.exit(1)
1620

1721
class VimLParserException(Exception):
1822
pass

test/run_command.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
if [ $# -eq 0 ]; then
4+
echo "USAGE: ./test/run_command.sh <vimlparser command>"
5+
echo " Example: ./test/run_command.sh python3 py/vimlparser.py"
6+
exit 1
7+
fi
8+
vimlparser=$@
9+
10+
exit_status=0
11+
12+
test_file() {
13+
local vimfile=$1
14+
local base=$(basename "$vimfile" ".vim")
15+
local okfile="test/${base}.ok"
16+
local outfile="test/${base}.out"
17+
18+
if [[ -f "test/${base}.skip" ]]; then
19+
return
20+
fi
21+
22+
local neovim=""
23+
if [[ $vimfile =~ "test_neo" ]]; then
24+
neovim="--neovim"
25+
fi
26+
27+
rm -f ${outfile}
28+
29+
${vimlparser} ${neovim} ${vimfile} &> ${outfile}
30+
31+
diffout=$(diff -u ${outfile} ${okfile})
32+
if [ -n "$diffout" ]; then
33+
exit_status=1
34+
echo "${diffout}"
35+
fi
36+
}
37+
38+
for f in test/test*.vim; do
39+
test_file ${f}
40+
done
41+
42+
exit $exit_status

0 commit comments

Comments
 (0)