File: tests.sh

package info (click to toggle)
rolldice 1.16-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, stretch, trixie
  • size: 128 kB
  • ctags: 59
  • sloc: ansic: 376; sh: 51; makefile: 28
file content (96 lines) | stat: -rwxr-xr-x 2,149 bytes parent folder | download
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#! /bin/bash
# Released under GPL licence v2 or upper
#
# When executed ($ ./tests.sh), no errors should occur in the
# two first sections.  The third one should result in only error messages,
# each one different. Segfault or default error messages must not appear.
#
# The following lines are the expected results:
#	Use argv
#2 
#3 
#Roll #1: (2) = 2 
#Roll #1: (1) = 1 
#Roll #1: (1) = 1 
#2 
#2 
#	Use stdin
#1 
#1 
#4 
#Roll #1: (1) = 1 
#Roll #1: (1) = 1 
#Roll #1: (2 1) + 2 = 5 
#	Error messages handle numbers that are too large
#rolldice: Requested number of dice faces is too large
#rolldice: Requested number of dropped dice is too large
#rolldice: Requested number of rolled dice is too large
#rolldice: Requested multiplier is too large
#rolldice: Requested add modifier is too large
#rolldice: Requested minus modifier is too large


function check_result {
    OUTPUT=`../rolldice $1`
    EXIT_VAL=$?
    TEST_SUCCESS=true
    
    if [[ $EXIT_VAL != 0 ]]
        then
            echo ${1}": ERROR (return value)"
            TEST_SUCCESS=false
    fi

    if echo ${OUTPUT} | grep -q -v $2
        then
            echo ${1}": ERROR ("${OUTPUT}")"
            TEST_SUCCESS=false
    fi

    if $TEST_SUCCESS;
        then
            echo ${1}": OK"
    fi
}

function check_error {
    OUTPUT=`../rolldice $1`
    EXIT_VAL=$?

    # 65 == EX_DATAERR /* data format error */
    if [[ $EXIT_VAL != 65 ]] 
        then
            echo ${1}": ERROR ("$EXIT_VAL" instead of 65)"
    fi
    
}

echo -e "\tResult between right limits"
check_result "1d2" "^[12]"
check_result "1d2+1" "^[23]"
check_result "1d2*2" "^[24]"
check_result "1d2-1" "^[01]"


echo -e "\tUse argv"
../rolldice 1d2
../rolldice 1d2+1
../rolldice -s 1d2
../rolldice -s -u 1d2
../rolldice -s -r 1d2
../rolldice 1d2 1d3
../rolldice 1d%
../rolldice 1d%+1

echo -e "\tUse stdin"
cat rollfile | ../rolldice
cat rollfile | ../rolldice -s 

echo -e "\tError messages handle numbers that are too large"
check_error "1d123456789"
check_error "2d3s123456789"
check_error "123456789x2d2"
check_error "2d2*123456789"
check_error "2d2+123456789"
check_error "2d2-123456789"