File: runtests

package info (click to toggle)
game-data-packager 37
  • links: PTS, VCS
  • area: contrib
  • in suites: jessie, jessie-kfreebsd
  • size: 512 kB
  • ctags: 97
  • sloc: sh: 235; makefile: 109
file content (120 lines) | stat: -rwxr-xr-x 3,732 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh

. ./lib/game-data-packager-shared

if [ ! -f /usr/share/shunit2/shunit2 ]; then
    echo "you need to install shunit2 to run tests" >&2
    exit 1
fi

## verify_file(file)
##      ensures file is a file, or complains on stderr
##      and causes the program to exit.
test_verify_file_yes() {
  ./tests/lib/verify_file "tests/runtests"
  assertEquals $? 0
}
test_verify_file_no() {
  ./tests/lib/verify_file "tests/does_not_exist"
  assertNotEquals $? 0
}

## verify_directory(dir)
##      ensures dir is a directory, or complains on stderr
##      and causes the program to exit.
test_verify_dir_yes() {
  ./tests/lib/verify_directory "tests"
  assertEquals $? 0
}
test_verify_dir_yes() {
  ./tests/lib/verify_directory "tests/does_not_exist"
  assertNotEquals $? 0
}

## verify_md5sum(file,sum)
##      calculates the md5sum of file and compares it to sum.
##      if the sum doesn't match, complains on stderr and causes the program
##      to exit.
test_md5sum_yes() {
  ./tests/lib/verify_md5sum "tests/testfile" "5d41402abc4b2a76b9719d911017c592"
  assertEquals $? 0
} 
test_md5sum_no() {
  ./tests/lib/verify_md5sum "tests/testfile" "incorrect"
  assertNotEquals $? 0
} 

## die(string,retcode)
##      end the program, complaining with string on stderr
##      and returning retcode if supplied, 2 if not.
test_die() {
  # XXX: capture stderr and ensure it matches diestring
  ./tests/lib/die "diestring" 6
  assertEquals $? 6
  ./tests/lib/die "diestring" 42
  assertEquals $? 42
}

test_require_program() {
  ./tests/lib/require_program "sh" dash
  assertEquals $? 0
  ./tests/lib/require_program "does-not-exist" nopackage
  assertEquals $? 2
}

## slipstream(deb,relpath,file1,file2...)
##      insert file1,file2... into the deb, under the
##      path 'relpath', relative to the package root, e.g.:
##          slipstream(deb, 'usr/share/doc', 'README', 'copyright')
##              => /usr/share/doc/README
##              => /usr/share/doc/copyright
##      prerequisites:
##        * $WORKDIR must be defined to a directory within which
##          slipstream can do it's work (somewhere writeable)
test_slipstream() {
    debsrc="./tests/empty.deb"
    wd=`mktemp -td game-data-packager.tests.XXXXXX`
    deb="$wd/empty.deb"
    file="`readlink -f tests/testfile`"

    cp -p "$debsrc" "$deb"
    WORKDIR="$wd"
    COMPRESS=no
    slipstream "$deb" "foo/bar/baz" "$file"
    dpkg-deb -c "$deb" | grep "/foo/bar/baz/testfile$" >/dev/null
    assertEquals $? 0

    rm "$deb"
    rmdir "$wd"
}

### procedures we are still to write tests for:

## slipstream_permcheck(deb)
##      ensures that the file deb can be written to and
##      that the current working directory is writeable
## slipstream_unpack(deb)
##      unpacks the deb file into "./slipstream_unpacked"
##      and the control data into "./DEBIAN"
## slipstream_file(file,destpath)
##      copies the file into "./slipstream_unpacked/$destpath",
##      calculates the files md5sum and adds it to the md5sums
##      file in the control area.
##  slipstream_instsize
##      calculates the installed size of the deb, (based on
##      the contents of the ./slipstream_unpacked directory)
##      and writes the result to the control file in the
##      control area.
## slipstream_repack(deb)
##      writes a new debian package over deb, packing
##      the files from ./slipstream_unpacked inside,
##      using the control area in ./DEBIAN
## slipstream_cleanup()
##      removes the ./slipstream_unpacked directory.
## install_deb(deb)
##      uses sudo and dpkg to install the supplied .deb file
## unravel(path)
##      convert 'path' from relative to absolute
##      if it does not begin with a slash.

. /usr/share/shunit2/shunit2