Skip to content

Commit

Permalink
Added several tests
Browse files Browse the repository at this point in the history
  • Loading branch information
envenomator committed Feb 25, 2024
1 parent 7499991 commit f4a2270
Show file tree
Hide file tree
Showing 81 changed files with 386 additions and 463 deletions.
3 changes: 2 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ for FILE in *; do
cd "$FILE"
printf $FORMAT $FILE
if [ -f "test.sh" ]; then
test_number=0
./test.sh > ./test.output
testresult=$?
if [ $testresult -eq 1 ]; then
echo -e "${RED}FAIL${NOCOLOR}"
echo -e " ${RED}FAIL${NOCOLOR}"
failed=$((failed+1))
else
if [ $testresult -eq 2 ]; then
Expand Down
1 change: 1 addition & 0 deletions tests/Conditional_asm/test.output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All (1) files assembled succesfully
34 changes: 34 additions & 0 deletions tests/Conditional_asm/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# Positive test - assembler needs to pass all tests in all subfolders
# return 0 on succesfull tests (all passed)
# return 1 on issue during test (one or more tests didn't pass correctly)
# return 2 on error in test SETUP
#

test_number=0
tests_successfull=0

cd tests
rm -f *.bin
for FILE in *; do
if [ -f "$FILE" ]; then
test_number=$((test_number+1))
../$ASMBIN $FILE -b FF > ../asm.output
if [ $? -eq 1 ]; then
echo "Error in" \'$FILE\'
else
tests_successfull=$((tests_successfull+1))
fi
fi
done
rm -f *.bin
cd ..

rm -f asm.output
if [ $test_number -eq $tests_successfull ]; then
echo "All ($test_number) files assembled succesfully"
exit 0
else
exit 1
fi
exit 0
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
TEST: EQU 1

.if TEST
ld a,1
.else
ld a,2
.endif

TEST: EQU 1

.if TEST
ld a,1
.else
ld a,2
.endif

8 changes: 4 additions & 4 deletions tests/Errors_labels/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# return 2 on error in test SETUP
#

negtest_number=0
test_number=0
negtest_failed_successfull=0

cd tests
rm -f *.bin
for FILE in *; do
if [ -f "$FILE" ]; then
negtest_number=$((negtest_number+1))
test_number=$((test_number+1))
../$ASMBIN $FILE -b FF > ../asm.output
if [ $? -eq 0 ]; then
echo "Failed to detect error in" \'$FILE\'
Expand All @@ -25,8 +25,8 @@ rm -f *.bin
cd ..

rm -f asm.output
if [ $negtest_number -eq $negtest_failed_successfull ]; then
echo "Detected all errors succesfully"
if [ $test_number -eq $negtest_failed_successfull ]; then
echo "Detected all ($test_number) errors succesfully"
exit 0
else
exit 1
Expand Down
34 changes: 34 additions & 0 deletions tests/Errors_literals/test copy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# Negative test - assembler needs to fail tests in all subfolders
# return 0 on succesfull test (all failed)
# return 1 on issue during test (one or more tests didn't fail correctly)
# return 2 on error in test SETUP
#

test_number=0
negtest_failed_successfull=0

cd tests
rm -f *.bin
for FILE in *; do
if [ -f "$FILE" ]; then
test_number=$((test_number+1))
../$ASMBIN $FILE -b FF > ../asm.output
if [ $? -eq 0 ]; then
echo "Failed to detect error in" \'$FILE\'
else
negtest_failed_successfull=$((negtest_failed_successfull+1))
fi
fi
done
rm -f *.bin
cd ..

rm -f asm.output
if [ $test_number -eq $negtest_failed_successfull ]; then
echo "Detected all ($test_number) errors succesfully"
exit 0
else
exit 1
fi
exit 0
2 changes: 1 addition & 1 deletion tests/Errors_literals/test.output
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Detected all errors succesfully
Detected all (5) errors succesfully
8 changes: 4 additions & 4 deletions tests/Errors_literals/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# return 2 on error in test SETUP
#

negtest_number=0
test_number=0
negtest_failed_successfull=0

cd tests
rm -f *.bin
for FILE in *; do
if [ -f "$FILE" ]; then
negtest_number=$((negtest_number+1))
test_number=$((test_number+1))
../$ASMBIN $FILE -b FF > ../asm.output
if [ $? -eq 0 ]; then
echo "Failed to detect error in" \'$FILE\'
Expand All @@ -25,8 +25,8 @@ rm -f *.bin
cd ..

rm -f asm.output
if [ $negtest_number -eq $negtest_failed_successfull ]; then
echo "Detected all errors succesfully"
if [ $test_number -eq $negtest_failed_successfull ]; then
echo "Detected all ($test_number) errors succesfully"
exit 0
else
exit 1
Expand Down
8 changes: 4 additions & 4 deletions tests/Errors_macros/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# return 2 on error in test SETUP
#

negtest_number=0
test_number=0
negtest_failed_successfull=0

cd tests
rm -f *.bin
for FILE in *; do
if [ -f "$FILE" ]; then
negtest_number=$((negtest_number+1))
test_number=$((test_number+1))
../$ASMBIN $FILE -b FF > ../asm.output
if [ $? -eq 0 ]; then
echo "Failed to detect error in" \'$FILE\'
Expand All @@ -25,8 +25,8 @@ rm -f *.bin
cd ..

rm -f asm.output
if [ $negtest_number -eq $negtest_failed_successfull ]; then
echo "Detected all errors succesfully"
if [ $test_number -eq $negtest_failed_successfull ]; then
echo "Detected all ($test_number) errors succesfully"
exit 0
else
exit 1
Expand Down
8 changes: 4 additions & 4 deletions tests/Errors_opcodes/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# return 2 on error in test SETUP
#

negtest_number=0
test_number=0
negtest_failed_successfull=0

cd tests
rm -f *.bin
for FILE in *; do
if [ -f "$FILE" ]; then
negtest_number=$((negtest_number+1))
test_number=$((test_number+1))
../$ASMBIN $FILE -b FF > ../asm.output
if [ $? -eq 0 ]; then
echo "Failed to detect error in" \'$FILE\'
Expand All @@ -25,8 +25,8 @@ rm -f *.bin
cd ..

rm -f asm.output
if [ $negtest_number -eq $negtest_failed_successfull ]; then
echo "Detected all errors succesfully"
if [ $test_number -eq $negtest_failed_successfull ]; then
echo "Detected all ($test_number) errors succesfully"
exit 0
else
exit 1
Expand Down
8 changes: 4 additions & 4 deletions tests/Errors_registers/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# return 2 on error in test SETUP
#

negtest_number=0
test_number=0
negtest_failed_successfull=0

cd tests
rm -f *.bin
for FILE in *; do
if [ -f "$FILE" ]; then
negtest_number=$((negtest_number+1))
test_number=$((test_number+1))
../$ASMBIN $FILE -b FF > ../asm.output
if [ $? -eq 0 ]; then
echo "Failed to detect error in" \'$FILE\'
Expand All @@ -25,8 +25,8 @@ rm -f *.bin
cd ..

rm -f asm.output
if [ $negtest_number -eq $negtest_failed_successfull ]; then
echo "Detected all errors succesfully"
if [ $test_number -eq $negtest_failed_successfull ]; then
echo "Detected all ($test_number) errors succesfully"
exit 0
else
exit 1
Expand Down
8 changes: 4 additions & 4 deletions tests/Errors_strings/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# return 2 on error in test SETUP
#

negtest_number=0
test_number=0
negtest_failed_successfull=0

cd tests
rm -f *.bin
for FILE in *; do
if [ -f "$FILE" ]; then
negtest_number=$((negtest_number+1))
test_number=$((test_number+1))
../$ASMBIN $FILE -b FF > ../asm.output
if [ $? -eq 0 ]; then
echo "Failed to detect error in" \'$FILE\'
Expand All @@ -25,8 +25,8 @@ rm -f *.bin
cd ..

rm -f asm.output
if [ $negtest_number -eq $negtest_failed_successfull ]; then
echo "Detected all errors succesfully"
if [ $test_number -eq $negtest_failed_successfull ]; then
echo "Detected all ($test_number) errors succesfully"
exit 0
else
exit 1
Expand Down
34 changes: 34 additions & 0 deletions tests/Errors_value_operators/test copy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# Negative test - assembler needs to fail tests in all subfolders
# return 0 on succesfull test (all failed)
# return 1 on issue during test (one or more tests didn't fail correctly)
# return 2 on error in test SETUP
#

test_number=0
negtest_failed_successfull=0

cd tests
rm -f *.bin
for FILE in *; do
if [ -f "$FILE" ]; then
test_number=$((test_number+1))
../$ASMBIN $FILE -b FF > ../asm.output
if [ $? -eq 0 ]; then
echo "Failed to detect error in" \'$FILE\'
else
negtest_failed_successfull=$((negtest_failed_successfull+1))
fi
fi
done
rm -f *.bin
cd ..

rm -f asm.output
if [ $test_number -eq $negtest_failed_successfull ]; then
echo "Detected all ($test_number) errors succesfully"
exit 0
else
exit 1
fi
exit 0
3 changes: 3 additions & 0 deletions tests/Errors_value_operators/test.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Failed to detect error in 'illegal_shift_left.s'
Failed to detect error in 'illegal_shift_right.s'
Failed to detect error in 'illegal_unary_times.s'
34 changes: 34 additions & 0 deletions tests/Errors_value_operators/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# Negative test - assembler needs to fail tests in all subfolders
# return 0 on succesfull test (all failed)
# return 1 on issue during test (one or more tests didn't fail correctly)
# return 2 on error in test SETUP
#

test_number=0
negtest_failed_successfull=0

cd tests
rm -f *.bin
for FILE in *; do
if [ -f "$FILE" ]; then
test_number=$((test_number+1))
../$ASMBIN $FILE -b FF > ../asm.output
if [ $? -eq 0 ]; then
echo "Failed to detect error in" \'$FILE\'
else
negtest_failed_successfull=$((negtest_failed_successfull+1))
fi
fi
done
rm -f *.bin
cd ..

rm -f asm.output
if [ $test_number -eq $negtest_failed_successfull ]; then
echo "Detected all ($test_number) errors succesfully"
exit 0
else
exit 1
fi
exit 0
1 change: 1 addition & 0 deletions tests/Errors_value_operators/tests/illegal_shift_left.s
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ld a, 8 < 2
1 change: 1 addition & 0 deletions tests/Errors_value_operators/tests/illegal_shift_right.s
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ld a, 8 > 2
1 change: 1 addition & 0 deletions tests/Labels/test.output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All (11) files assembled succesfully
34 changes: 34 additions & 0 deletions tests/Labels/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# Positive test - assembler needs to pass all tests in all subfolders
# return 0 on succesfull tests (all passed)
# return 1 on issue during test (one or more tests didn't pass correctly)
# return 2 on error in test SETUP
#

test_number=0
tests_successfull=0

cd tests
rm -f *.bin
for FILE in *; do
if [ -f "$FILE" ]; then
test_number=$((test_number+1))
../$ASMBIN $FILE -b FF > ../asm.output
if [ $? -eq 1 ]; then
echo "Error in" \'$FILE\'
else
tests_successfull=$((tests_successfull+1))
fi
fi
done
rm -f *.bin
cd ..

rm -f asm.output
if [ $test_number -eq $tests_successfull ]; then
echo "All ($test_number) files assembled succesfully"
exit 0
else
exit 1
fi
exit 0
6 changes: 6 additions & 0 deletions tests/Labels/tests/back_reference.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
back:
ld a,b
jp back
newlabel:
ld a,b
jp back
Loading

0 comments on commit f4a2270

Please sign in to comment.