From 14f13ff55ab7c70cfcd2831705254760b3b407d8 Mon Sep 17 00:00:00 2001 From: Henrixounez Date: Sun, 18 Aug 2019 17:21:48 +0200 Subject: [PATCH] tests: v implementation of repl tests --- compiler/tests/repl/default_printing.repl | 2 +- compiler/tests/repl/repl.sh | 64 ----------------------- compiler/tests/repl/repl_test.v | 25 +++++++++ 3 files changed, 26 insertions(+), 65 deletions(-) delete mode 100755 compiler/tests/repl/repl.sh create mode 100644 compiler/tests/repl/repl_test.v diff --git a/compiler/tests/repl/default_printing.repl b/compiler/tests/repl/default_printing.repl index 321911bcc3..b1de4b4f5b 100644 --- a/compiler/tests/repl/default_printing.repl +++ b/compiler/tests/repl/default_printing.repl @@ -4,4 +4,4 @@ num string ===output=== 1 -Hello \ No newline at end of file +Hello diff --git a/compiler/tests/repl/repl.sh b/compiler/tests/repl/repl.sh deleted file mode 100755 index 6aa5f014de..0000000000 --- a/compiler/tests/repl/repl.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/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 diff --git a/compiler/tests/repl/repl_test.v b/compiler/tests/repl/repl_test.v new file mode 100644 index 0000000000..017d1e7560 --- /dev/null +++ b/compiler/tests/repl/repl_test.v @@ -0,0 +1,25 @@ +import os + +fn test_repl() { + test_files := os.walk_ext('.', '.repl') + + for file in test_files { + content := os.read_file(file) or { + assert false + break + } + input := content.all_before('===output===\n').replace('$', '\\$') + output := content.all_after('===output===\n') + r := os.exec('echo "$input" | ./v') or { + assert false + break + } + result := r.output.replace('>>> ', '').replace('>>>', '').all_after('Use Ctrl-C or `exit` to exit\n') + assert result == output + if result != output { + println(file) + println('Got : $result') + println('Expected : $output') + } + } +} \ No newline at end of file