summaryrefslogtreecommitdiff
path: root/03_code2/test.sh
blob: 649b8a6db125ba56b9ce07b5133bb61df208c06b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
cat > temp.c <<EOF
#include <stdio.h>
#include <stdlib.h>
EOF
cat code2.c >> temp.c
gcc -Wall -Werror -pedantic -std=gnu99 temp.c -o code2 2>errors.txt
if [ "$?" = "0" ]
    then
    echo "Your code appears to have legal syntax!"
    echo "Here is what I get when I run it..."
    echo "-----------------"
    ./code2
    echo "-----------------"
    echo "Here is what I would expect the answers to be:"
    echo "----------------"
    cat <<EOF 
Here is a triangle with height 4
*
**
***
****
That triangle had 10 total stars
Here is a triangle with height 7
*
**
***
****
*****
******
*******
That triangle had 28 total stars
EOF
    echo "---------------"
    else
    echo "Oh no, the syntax of your code is not correct!"
    mesg=`grep error errors.txt | head -1`
    ln=`echo "$mesg" | cut -f2 -d":"`
    let ln=${ln}-2
    echo "I discovered the problem on line $ln "
    echo "(though the problem may be earlier and I just got confused)"
    echo "Here is my best attempt to describe what is wrong:"
    echo "$mesg" | cut -f5 -d":"
    fi
rm -f errors.txt temp.c code2