File: appendtest

package info (click to toggle)
makeself 2.5.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 308 kB
  • sloc: sh: 2,139; makefile: 20
file content (98 lines) | stat: -rw-r--r-- 2,559 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
#!/bin/bash
set -eu
THIS="$(readlink -f "$0")"
THISDIR="$(dirname "${THIS}")"
SRCDIR="$(dirname "${THISDIR}")"
SUT="${SRCDIR}/makeself.sh"
WHAT="$(basename "${THIS}")"

# FIXME: These tests need to check that the concatenation of archives works


readonly archive_dir_create="$(mktemp -dt archive_dir_create.XXXXXX)"
readonly archive_dir_append="$(mktemp -dt archive_dir_append.XXXXXX)"
touch "${archive_dir_create}/fee"
touch "${archive_dir_create}/fie"
touch "${archive_dir_append}/foe"
touch "${archive_dir_append}/fum"

evalAssert() {
    eval "$@"
    assertEquals "$?" "0"
}

# $1 : file_name
doInfoListCheckExec() {
    evalAssert "$1" --info
    evalAssert "$1" --list
    evalAssert "$1" --check
    evalAssert "$1"
}

# $1 : file_name
# rest : content basenames
assertFileContains() {
    local file_name=""
    file_name="$(readlink -f "$1")"
    shift
    local target="${file_name}.d"
    rm -rf "${target}"
    mkdir -p "${target}"
    evalAssert "${file_name}" --target "${target}"
    assertEquals "$(find "${target}" -type f -exec basename -a {} + | sort)" "$(echo -e "$@" | sort)"
    rm -rf "${target}"
}

# $@ : makeself options
doTestOpts() {
    local stem=""
    stem="$(printf '%s' "${WHAT}" "$@" | tr -sc '[:alnum:]_.-' '_')"
    local file_name=""
    file_name="${stem}.run"

    evalAssert "${SUT}" "$@" --sha256 \
        "${archive_dir_create}" \
        "${file_name}" \
        "${stem}" \
        "echo ${stem}"
    file_name="$(readlink -f ${file_name})"
    doInfoListCheckExec "${file_name}"
    assertFileContains "${file_name}" "fee\nfie"

    evalAssert "${SUT}" "$@" --sha256 \
        --append "${archive_dir_append}" \
        "${file_name}"
    doInfoListCheckExec "${file_name}"
    assertFileContains "${file_name}" "fee\nfie\nfoe\nfum"

    rm -f "${file_name}"
}

# $1 : compression option
doTestComp() {
    if ! command -v "${1#--*}" >/dev/null 2>&1; then
        echo "WARNING: missing command: ${1#--*}" >&2
        return 0
    fi
    doTestOpts "$1"
}

################################################################################

testDefault() { doTestOpts; }

testNocomp() { doTestOpts --nocomp; }

testBase64() { doTestComp --base64; }
testBzip2() { doTestComp --bzip2; }
testCompress() { doTestComp --compress; }
testGzip() { doTestComp --gzip; }
testLz4() { doTestComp --lz4; }
testLzo() { doTestComp --lzo; }
testPbzip2() { doTestComp --pbzip2; }
testPigz() { doTestComp --pigz; }
testXz() { doTestComp --xz; }
testZstd() { doTestComp --zstd; }

# Load and run shUnit2.
source "./shunit2/shunit2"