浏览代码

Merge branch 'bats'

Add Bash Automated Testing System to run non-regression tests.
DricomDragon 5 年之前
父节点
当前提交
650e614724
共有 5 个文件被更改,包括 78 次插入34 次删除
  1. 16 1
      README.md
  2. 0 9
      ans.txt
  3. 62 0
      test.bats
  4. 0 15
      test.sh
  5. 0 9
      test.txt

+ 16 - 1
README.md

@@ -4,6 +4,8 @@ ECN lab about syntaxic analysis
 
 ## Dependencies
 
+### To make binary
+
 You need **GCC**, **flex** and **bison**.
 
 You can install them on debian based systems with :
@@ -12,6 +14,17 @@ You can install them on debian based systems with :
 sudo apt install flex bison
 ```
 
+### To run tests
+
+Tests are using [Bash Automated Testing System](https://github.com/bats-core/bats-core/)
+
+
+You can install them on debian based systems with :
+
+```
+sudo apt install bats
+```
+
 ## How to compile
 
 ```
@@ -21,6 +34,8 @@ make
 
 ## How to test
 
+You need to compile prior to test.
+
 ```
-./test.sh
+./test.bats
 ```

+ 0 - 9
ans.txt

@@ -1,9 +0,0 @@
-3
--1
-7
-9
-6
-0
-9
-6
-1

+ 62 - 0
test.bats

@@ -0,0 +1,62 @@
+#!/usr/bin/bats
+
+@test "Print one number" {
+    result="$(echo '42=' | ./eval.out)"
+    [ "$result" = "42" ]
+}
+
+@test "Basic addition" {
+	result="$(echo '1+2=' | ./eval.out)"
+	[ "$result" = "3" ]
+}
+
+@test "Basic substraction" {
+	result="$(echo '1-2=' | ./eval.out)"
+	[ "$result" = "-1" ]
+}
+
+@test "Multiplication priority over addition" {
+	result="$(echo '1+2*3=' | ./eval.out)"
+	[ "$result" = "7" ]
+}
+
+@test "Parenthesis priority" {
+	result="$(echo '(1+2)*3=' | ./eval.out)"
+	[ "$result" = "9" ]
+}
+
+@test "Three operands with addition" {
+	result="$(echo '1+2+3=' | ./eval.out)"
+	[ "$result" = "6" ]
+}
+
+@test "Two parenthesis blocks" {
+	result="$(echo '(1 - 1) + (2 - 2) =' | ./eval.out)"
+	[ "$result" = "0" ]
+}
+
+@test "Addition, substraction and multiplication" {
+	result="$(echo '1 + 7 - 4 * 2 =' | ./eval.out)"
+	[ "$result" = "0" ]
+}
+
+@test "Negative result" {
+	result="$(echo '6 - 14=' | ./eval.out)"
+	[ "$result" = "-8" ]
+}
+
+@test "Minus unary operand" {
+	result="$(echo '-4=' | ./eval.out)"
+	[ "$result" = "-4" ]
+}
+
+@test "Basic division" {
+	result="$(echo '42 / 7 =' | ./eval.out)"
+	[ "$result" = "6" ]
+}
+
+@test "Basic truncated division" {
+	result="$(echo '16 / 3 =' | ./eval.out)"
+	[ "$result" = "5" ]
+}
+

+ 0 - 15
test.sh

@@ -1,15 +0,0 @@
-#!/bin/sh
-
-echo "Executing tests ..."
-cat test.txt | ./eval.out > ans.out.txt
-echo "Done."
-echo "Show diff ..."
-diff ans.txt ans.out.txt
-
-# Test equality
-if [ $status ]
-then
-	echo 'All tests are OK.'
-else
-	echo 'Failure !!!'
-fi

+ 0 - 9
test.txt

@@ -1,9 +0,0 @@
-1+2=
-1-2=
-1+2*3=
-(1+2)*3=
-1+2+3=
-(1 - 1) + (2 - 2) =
-1 + 4 * 2 =
-42 / 7 =
-5 / 3 =