mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
repl: enabled back and added automated tests
fixed typos and macos errors
This commit is contained in:
parent
fdb1433c24
commit
7879bde8bb
1
Makefile
1
Makefile
@ -25,6 +25,7 @@ test: v
|
||||
find . -name '*_test.v' -print0 | xargs -0 -n1 ./v
|
||||
echo "Building V examples..."
|
||||
find examples -name '*.v' -print0 | xargs -0 -n1 ./v
|
||||
bash ./compiler/tests/repl/repl.sh
|
||||
|
||||
clean:
|
||||
-rm -f v.c v*.c v.c.out v vprod thirdparty/**/*.o
|
||||
|
@ -1292,8 +1292,6 @@ fn new_v(args[]string) *V {
|
||||
}
|
||||
|
||||
fn run_repl() []string {
|
||||
println('REPL is temporarily disabled, sorry')
|
||||
exit(1)
|
||||
println('V $Version')
|
||||
println('Use Ctrl-C or `exit` to exit')
|
||||
file := '.vrepl.v'
|
||||
|
14
compiler/tests/repl/README.md
Normal file
14
compiler/tests/repl/README.md
Normal 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
|
4
compiler/tests/repl/arr_decl.repl
Normal file
4
compiler/tests/repl/arr_decl.repl
Normal file
@ -0,0 +1,4 @@
|
||||
arr := ['1', '2', '3', '4']
|
||||
println(arr)
|
||||
===output===
|
||||
["1", "2", "3", "4"]
|
3
compiler/tests/repl/error.repl
Normal file
3
compiler/tests/repl/error.repl
Normal file
@ -0,0 +1,3 @@
|
||||
println(a)
|
||||
===output===
|
||||
V panic: .vrepl.v:2 undefined: `a`
|
5
compiler/tests/repl/interpolation.repl
Normal file
5
compiler/tests/repl/interpolation.repl
Normal file
@ -0,0 +1,5 @@
|
||||
a := 'Hello'
|
||||
b := 'World'
|
||||
println('$a $b')
|
||||
===output===
|
||||
Hello World
|
10
compiler/tests/repl/multiple_decl.repl
Normal file
10
compiler/tests/repl/multiple_decl.repl
Normal file
@ -0,0 +1,10 @@
|
||||
name := 'Bob'
|
||||
age := 20
|
||||
large_number := i64(9999999999)
|
||||
println(name)
|
||||
println(age)
|
||||
println(large_number)
|
||||
===output===
|
||||
Bob
|
||||
20
|
||||
9999999999
|
7
compiler/tests/repl/multiple_println.repl
Normal file
7
compiler/tests/repl/multiple_println.repl
Normal file
@ -0,0 +1,7 @@
|
||||
println('Hello World')
|
||||
println('Foo Bar')
|
||||
println('dlroW olleH')
|
||||
===output===
|
||||
Hello World
|
||||
Foo Bar
|
||||
dlroW olleH
|
5
compiler/tests/repl/newlines.repl
Normal file
5
compiler/tests/repl/newlines.repl
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
|
||||
|
||||
===output===
|
1
compiler/tests/repl/nothing.repl
Normal file
1
compiler/tests/repl/nothing.repl
Normal file
@ -0,0 +1 @@
|
||||
===output===
|
3
compiler/tests/repl/println.repl
Normal file
3
compiler/tests/repl/println.repl
Normal file
@ -0,0 +1,3 @@
|
||||
println('hello world')
|
||||
===output===
|
||||
hello world
|
64
compiler/tests/repl/repl.sh
Executable file
64
compiler/tests/repl/repl.sh
Executable 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
|
4
compiler/tests/repl/var_decl.repl
Normal file
4
compiler/tests/repl/var_decl.repl
Normal file
@ -0,0 +1,4 @@
|
||||
a := 1
|
||||
println(a)
|
||||
===output===
|
||||
1
|
Loading…
Reference in New Issue
Block a user