repl: enabled back and added automated tests

fixed typos and macos errors
pull/1557/head
Henrixounez 2019-08-10 00:20:36 +02:00 committed by Alexander Medvednikov
parent fdb1433c24
commit 7879bde8bb
13 changed files with 121 additions and 2 deletions

View File

@ -25,6 +25,7 @@ test: v
find . -name '*_test.v' -print0 | xargs -0 -n1 ./v find . -name '*_test.v' -print0 | xargs -0 -n1 ./v
echo "Building V examples..." echo "Building V examples..."
find examples -name '*.v' -print0 | xargs -0 -n1 ./v find examples -name '*.v' -print0 | xargs -0 -n1 ./v
bash ./compiler/tests/repl/repl.sh
clean: clean:
-rm -f v.c v*.c v.c.out v vprod thirdparty/**/*.o -rm -f v.c v*.c v.c.out v vprod thirdparty/**/*.o

View File

@ -1292,8 +1292,6 @@ fn new_v(args[]string) *V {
} }
fn run_repl() []string { fn run_repl() []string {
println('REPL is temporarily disabled, sorry')
exit(1)
println('V $Version') println('V $Version')
println('Use Ctrl-C or `exit` to exit') println('Use Ctrl-C or `exit` to exit')
file := '.vrepl.v' file := '.vrepl.v'

View File

@ -0,0 +1,14 @@
# V REPL Tests Script
### How to write a new test
- Create a new file named `*.repl`
- Write the input to be given to REPL
- Add `===output===`
- Write the output expected
### Example :
```
a := 1
println(a)
===output===
1

View File

@ -0,0 +1,4 @@
arr := ['1', '2', '3', '4']
println(arr)
===output===
["1", "2", "3", "4"]

View File

@ -0,0 +1,3 @@
println(a)
===output===
V panic: .vrepl.v:2 undefined: `a`

View File

@ -0,0 +1,5 @@
a := 'Hello'
b := 'World'
println('$a $b')
===output===
Hello World

View File

@ -0,0 +1,10 @@
name := 'Bob'
age := 20
large_number := i64(9999999999)
println(name)
println(age)
println(large_number)
===output===
Bob
20
9999999999

View File

@ -0,0 +1,7 @@
println('Hello World')
println('Foo Bar')
println('dlroW olleH')
===output===
Hello World
Foo Bar
dlroW olleH

View File

@ -0,0 +1,5 @@
===output===

View File

@ -0,0 +1 @@
===output===

View File

@ -0,0 +1,3 @@
println('hello world')
===output===
hello world

View File

@ -0,0 +1,64 @@
#!/bin/sh
score=0
total=0
debug=0
if [ "$1" = "-h" ]; then
echo "V REPL Tests Script"
echo
echo "-d for debug extra outputs"
echo
echo "Reads test files '*.repl_test' and execute them"
echo "See README.md for details on how to write tests"
exit 0
fi
if [ "$1" = "-d" ]; then
debug=1
fi
test_command() {
if [ $debug -eq 1 ]; then
echo -en "Testing $1: "
fi
file=`cat $1`
output_start=`echo -e "$file" | grep -n '===output===' | cut -f1 -d:`
if [ $output_start -gt 1 ]; then
input=`echo -en "$file" | head -n $((output_start - 1))`
else
input=""
fi
output=`echo -en "$file" | tail -n +$((output_start + 1))`
result=`echo -en "$input" | ./v | tail -n +3 | sed 's/>>> //g'`
if [ "$output" = "$result" ]; then
score=$(($score + 1))
if [ $debug -eq 1 ]; then
echo -e "\033[32mOK\033[0m"
fi
else
if [ $debug -eq 0 ]; then
echo -en "REPL: "
fi
echo -e "\033[31mKO\033[0m"
echo -e "\033[1mGot :\033[0m\n$result"
echo -e "\033[1mExpected :\033[0m\n$output"
fi
total=$(($total + 1))
rm -f .vrepl .vrepl_temp
}
for file in `ls compiler/tests/repl/*.repl`; do
test_command $file
done
echo -e "\033[1mREPL SCORE:" $score "/" $total "\033[0m"
if [ $score != $total ]; then
exit 1
fi

View File

@ -0,0 +1,4 @@
a := 1
println(a)
===output===
1