Skip to content

Commit

Permalink
Merge pull request #36 from ErwannLesech/funct_test
Browse files Browse the repository at this point in the history
test<funct_test>: Adding new tests on echo
  • Loading branch information
majerugo authored Jan 13, 2024
2 parents d013ae1 + 648a68c commit 7b7c927
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/builtin/echo/echo10.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo titi ; echo -la else fi if
1 change: 1 addition & 0 deletions tests/builtin/echo/echo11.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo ' ' ; echo else titi ls -n
1 change: 1 addition & 0 deletions tests/builtin/echo/echo12.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo tata echo # fi if ' -la -n
1 change: 1 addition & 0 deletions tests/builtin/echo/echo13.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo fi -e ls tata ls -E
2 changes: 2 additions & 0 deletions tests/builtin/echo/echo14.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

echo if elif toto -E tata fi
2 changes: 2 additions & 0 deletions tests/builtin/echo/echo15.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo
echo elif -la # -la # '
2 changes: 2 additions & 0 deletions tests/builtin/echo/echo9.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo
echo titi -n ls -n toto
7 changes: 7 additions & 0 deletions tests/builtin/echo/testsuite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ run_test echo5.test
run_test echo6.test
run_test echo7.test
run_test echo8.test
run_test echo9.test
run_test echo10.test
run_test echo11.test
run_test echo12.test
run_test echo13.test
run_test echo14.test
run_test echo15.test
42 changes: 42 additions & 0 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import subprocess

executable_path = '/home/ugopc/ING1/42sh/42-Sh/src/42sh'

l = [ "if", "else", "elif", "fi", ";", "'", "echo", "ls", "-n", "-e" ,"-E", "-la", "#", "titi", "tata", "toto", "\n", " ", "\t" ]
import random
error = 0
number_of_test = 1000
for i in range(number_of_test):
str = ""
for j in range(10):
str += l[random.randint(0, len(l) - 1)] + " "
ref_res = subprocess.run("echo " + '"' + str + '"' + " | bash --posix", shell=True, capture_output=True, text=True)
res = subprocess.run(executable_path + " -c " + '"' +str + '"', shell=True, capture_output=True, text=True)

if ref_res.stdout != res.stdout and res.returncode == 0 and ref_res.returncode == 0:
error += 1
# print("=== Error match stdout ===")
# print("Input: " + str)
f = open("test.txt", "a")
f.write('"' + str + '"\n')
# print("res: " + res.stdout)
# print("ref_res: " + ref_res.stdout)
f.close()

if ref_res.returncode != res.returncode:
error += 1
# print("=== Error return code ===")
# print("Input: " + str)
# print("")
# print("result of 42sh: " + res.stdout)
# print("")
# print("result of bash --posix: " + ref_res.stdout)
# print("")
# print("return code of 42sh: ", end="")
# print(res.returncode)
# print("return code of bash --posix: ", end="")
# print(ref_res.returncode)
# print("")
print("Accuracy: ", end="")
print((number_of_test - error) / number_of_test * 100, end="")
print("%")

0 comments on commit 7b7c927

Please sign in to comment.