Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit c0a35c5

Browse files
author
Jiri Jurica
committed
Pridan skript na spousteni testu, pridany testy pro scanner, opraven bug se zacyklenym vracenim eol u scanneru
1 parent c5dc8ba commit c0a35c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+248
-65
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ tokstack.o: tokstack.c
3737

3838
clean:
3939
rm -f *.o *.out *.gch
40+
41+
test:
42+
tests/runtest.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CMakeLists.txt not found in /home/jirkaj/Git/ifj-compilator

scanner.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ int getToken(token_t *loadedToken)
259259
static bool useLastChar = false;
260260

261261
// Step for calling this function after EOF token was send.
262-
if (lastChar == EOF) return setTokenType(loadedToken, TOK_endOfLine);
262+
if (lastChar == EOF) return setTokenType(loadedToken, TOK_endOfFile);
263263
if (useLastChar)
264264
{
265265
currChar = lastChar;

tests/expr/returnvalues

+30-30
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
test1 0
2-
test2 0
3-
test3 3
4-
test4 0
5-
test5 0
6-
test6 0
7-
test7 0
8-
test8 0
9-
test9 2
10-
test10 0
11-
test11 0
12-
test12 4
13-
test13 0
14-
test14 0
15-
test15 0
16-
test16 0
17-
test17 0
18-
test18 0
19-
test19 0
20-
test20 4
21-
test21 0
22-
test22 0
23-
test23 2
24-
test24 0
25-
test25 0
26-
test26 2
27-
test27 0
28-
test28 0
29-
test29 4
30-
test30 4
1+
test1 0
2+
test2 0
3+
test3 3
4+
test4 0
5+
test5 0
6+
test6 0
7+
test7 0
8+
test8 0
9+
test9 2
10+
test10 0
11+
test11 0
12+
test12 4
13+
test13 0
14+
test14 0
15+
test15 0
16+
test16 0
17+
test17 0
18+
test18 0
19+
test19 0
20+
test20 4
21+
test21 0
22+
test22 0
23+
test23 2
24+
test24 0
25+
test25 0
26+
test26 2
27+
test27 0
28+
test28 0
29+
test29 4
30+
test30 4

tests/expr/test1.ref

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
15
1+
15

tests/runtest.sh

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
red='\033[1;31m'
4+
green='\033[1;32m'
5+
nc='\033[0m'
6+
7+
compiler="./compiler"
8+
interpreter="tests/ic17int"
9+
instructionFile=$(mktemp)
10+
outputFile=$(mktemp)
11+
12+
echo "ICAgICAgICAgICAgICAgICBfX189PT09LV8gIF8tPT09PV9fXwogICAgICAgICAgIF8tLV5eXiMjIyMjLy8gICAgICBcXCMjIyMjXl5eLS1fCiAgICAgICAgXy1eIyMjIyMjIyMjIy8vICggICAgKSBcXCMjIyMjIyMjIyNeLV8KICAgICAgIC0jIyMjIyMjIyMjIyMvLyAgfFxeXi98ICBcXCMjIyMjIyMjIyMjIy0KICAgICBfLyMjIyMjIyMjIyMjIy8vICAgKEA6OkApICAgXFwjIyMjIyMjIyMjIyNcXwogICAgLyMjIyMjIyMjIyMjIyMoKCAgICAgXFwvLyAgICAgKSkjIyMjIyMjIyMjIyMjXAogICAtIyMjIyMjIyMjIyMjIyMjXFwgICAgKG9vKSAgICAvLyMjIyMjIyMjIyMjIyMjIy0KICAtIyMjIyMjIyMjIyMjIyMjIyNcXCAgLyBWViBcICAvLyMjIyMjIyMjIyMjIyMjIyMjLQogLSMjIyMjIyMjIyMjIyMjIyMjIyNcXC8gICAgICBcLy8jIyMjIyMjIyMjIyMjIyMjIyMjLQpfIy98IyMjIyMjIyMjIy9cIyMjIyMjKCAgIC9cICAgKSMjIyMjIy9cIyMjIyMjIyMjI3xcI18KfC8gfCMvXCMvXCMvXC8gIFwjL1wjI1wgIHwgIHwgIC8jIy9cIy8gIFwvXCMvXCMvXCN8IFx8CmAgIHwvICBWICBWICBgICAgViAgXCNcfCB8ICB8IHwvIy8gIFYgICAnICBWICBWICBcfCAgJwogICBgICAgYCAgYCAgICAgIGAgICAvIHwgfCAgfCB8IFwgICAnICAgICAgJyAgJyAgICcKICAgICAgICAgICAgICAgICAgICAoICB8IHwgIHwgfCAgKQogICAgICAgICAgICAgICAgICAgX19cIHwgfCAgfCB8IC9fXwogICAgICAgICAgICAgICAgICAodnZ2KFZWVikoVlZWKXZ2dikKCg==" | base64 -d
13+
14+
printf "IFJ TESTING\n\n"
15+
16+
for testDir in `find tests/ -maxdepth 1 -type d | sort | tail -n +2`; do
17+
if [ ! -f "$testDir/returnvalues" ]; then # Pokud neni v testech return value, slozka se preskoci
18+
continue
19+
fi
20+
21+
printf "[ == %s == ]\n" `echo "$testDir" | cut -d/ -f2` # Nazev kolekce testu
22+
23+
for t in `find "$testDir" -type f -regex ".*test[0-9]*" | sort -V`; do
24+
testName=`echo $t | cut -d/ -f3`
25+
expectedReturnCode=`grep "^$testName " $testDir/returnvalues | cut -d' ' -f2`
26+
$compiler < "$t" > "$instructionFile" 2>/dev/null
27+
returnCode=$?
28+
29+
if [ $expectedReturnCode -eq $returnCode ]; then
30+
if [ $expectedReturnCode -eq 0 -a ! -f "${t}.ref" ]; then
31+
continue # Ocekava se, ze pokud se kod v poradku zkompiluje, bude ve slozce soubor na porovnani vysledku interpreteru
32+
elif [ $expectedReturnCode -eq 0 ]; then
33+
$interpreter "$instructionFile" > "$outputFile" 2>/dev/null
34+
diff "$outputFile" "${t}.ref" > /dev/null 2>&1
35+
if [ $? -eq 0 ]; then # Porovnani vystupu interpreteru
36+
result="${green}OK${nc}"
37+
else
38+
result="${red}FAIL${nc}"
39+
fi
40+
else # Shoduji se navratove kody compilatoru a nejsou 0
41+
result="${green}OK${nc}"
42+
fi
43+
else # Neshoduji se navratove kody compilatoru
44+
result="${red}FAIL${nc}"
45+
fi
46+
47+
printf "$testName $result\n"
48+
49+
50+
done
51+
echo
52+
done
53+
54+
rm $instructionFile
55+
rm $outputFile
Binary file not shown.

tests/scanner/code.bsa

-23
This file was deleted.

tests/scanner/code2.bsa

-9
This file was deleted.

tests/scanner/code4.bsa

-1
This file was deleted.

tests/scanner/inst

Whitespace-only changes.

tests/scanner/returnvalues

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
test1 0
2+
test2 0
3+
test3 0
4+
test4 0
5+
test5 2
6+
test6 1
7+
test7 0
8+
test8 2
9+
test9 0
10+
test10 0
11+
test11 0
12+
test12 0
13+
test13 0
14+
test14 0
15+
test15 1
16+
test16 1
17+
test17 3
18+
test18 3
19+
test19 0
20+
test20 0
21+
test21 0
22+
test22 0
23+
test23 0
24+
test24 0
25+
test25 0
26+
test26 0
27+
test27 2
28+
test28 2
29+
test29 2

tests/scanner/test1

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'pripustna varianta identifikatoru
2+
scope
3+
dim aHoj as integer
4+
end scope

tests/scanner/test1.ref

Whitespace-only changes.

tests/scanner/test10

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'mozny double
2+
scope
3+
dim ahoj as double = 1.654
4+
end scope

tests/scanner/test10.ref

Whitespace-only changes.

tests/scanner/test11

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'mozny double
2+
scope
3+
dim ahoj as double = 1e2
4+
end scope

tests/scanner/test11.ref

Whitespace-only changes.

tests/scanner/test12

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'mozny double
2+
scope
3+
dim ahoj as double = 1e+2
4+
end scope

tests/scanner/test12.ref

Whitespace-only changes.

tests/scanner/test13

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'mozny double
2+
scope
3+
dim ahoj as double = 2.4E6
4+
end scope

tests/scanner/test13.ref

Whitespace-only changes.

tests/scanner/test14

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'mozny double
2+
scope
3+
dim ahoj as double = 2.4E-9
4+
end scope

tests/scanner/test14.ref

Whitespace-only changes.

tests/scanner/test15

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'nepodporovany zapis desetinneho cisla
2+
scope
3+
dim ahoj as double = 0.
4+
end scope

tests/scanner/test16

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'nepodporovany zapis desetinneho cisla
2+
scope
3+
dim ahoj as double = .0
4+
end scope

tests/scanner/test17

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'chybny zapis double
2+
scope
3+
dim ahoj as double = 1+e2
4+
end scope

tests/scanner/test18

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'chybny zapis double
2+
scope
3+
dim ahoj as double = 1C2
4+
end scope

tests/scanner/test19

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'vypis stringu
2+
scope
3+
print !"";
4+
end scope

tests/scanner/test19.ref

Whitespace-only changes.

tests/scanner/test2

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'pripustna varianta identifikatoru
2+
scope
3+
dim _1234 as integer
4+
end scope

tests/scanner/test2.ref

Whitespace-only changes.

tests/scanner/test20

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'vypis stringu
2+
scope
3+
print !"abc";
4+
end scope

tests/scanner/test20.ref

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
abc

tests/scanner/test21

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'vypis i s jednoduchou escape sekvenci
2+
scope
3+
print !"\"";
4+
end scope

tests/scanner/test21.ref

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"

tests/scanner/test22

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'vypis i s nekolika escape sekvencemi
2+
scope
3+
print !"\n\\ \"";
4+
end scope

tests/scanner/test22.ref

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
\ "

tests/scanner/test23

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'vypis s nekolika escape sekvencemi
2+
scope
3+
print !"\n\t\065";
4+
end scope

tests/scanner/test23.ref

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
A

tests/scanner/test24

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'vypis s nekolika escape sekvencemi
2+
scope
3+
print !"Ahoj\nSve'te\\ \034";
4+
end scope

tests/scanner/test24.ref

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Ahoj
2+
Sve'te\ "

tests/scanner/test25

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'vypis s nekolika escape sekvencemi
2+
scope
3+
print !"\065\104\111\106\044\032\080\101\116\101\114\101\033\010";
4+
end scope

tests/scanner/test25.ref

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ahoj, Petere!

tests/scanner/test26

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'vypis s primim eol, ktere by melo fungovat
2+
scope
3+
print !"A
4+
hoj";
5+
end scope

tests/scanner/test26.ref

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A
2+
hoj

tests/scanner/test27

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'vypis s chybou
2+
scope
3+
print !"\";
4+
end scope

tests/scanner/test28

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'vypis s chybou
2+
scope
3+
print !"ah;
4+
end scope

tests/scanner/test29

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'vypis s chybou
2+
scope
3+
print "hoj";
4+
end scope

tests/scanner/test3

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'pripustna varianta identifikatoru
2+
scope
3+
dim _lipo as integer
4+
end scope

tests/scanner/test3.ref

Whitespace-only changes.

tests/scanner/test4

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'pripustna varianta identifikatoru
2+
scope
3+
dim _ as integer
4+
end scope

tests/scanner/test4.ref

Whitespace-only changes.

tests/scanner/test5

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'nepripustna varianta identifikatoru
2+
scope
3+
dim 21yolo as integer
4+
end scope

tests/scanner/test6

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'nepripustna varianta identifikatoru
2+
scope
3+
dim #!@@%#! as integer
4+
end scope

tests/scanner/test7

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'vhodny integer
2+
scope
3+
dim ahoj as integer = 1234
4+
end scope

tests/scanner/test7.ref

Whitespace-only changes.

tests/scanner/test8

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'dle zadani nepripustna zaporna celociselna hodnota
2+
scope
3+
dim ahoj as integer = -650
4+
end scope

tests/scanner/test9

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'mozny double
2+
scope
3+
dim ahoj as double = 0.0
4+
end scope

tests/scanner/test9.ref

Whitespace-only changes.

0 commit comments

Comments
 (0)