summaryrefslogtreecommitdiff
path: root/tests/dh_xul-ext/test
blob: 02085b84f4a925b52a0fde8894491c305ace9601 (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
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
#!/usr/bin/python

# Copyright (c) 2011, Benjamin Drung <bdrung@debian.org>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

import os
import sys
import subprocess

TESTS = ("all", "all_environment", "debian", "default-to-compatible", "ubuntu")

class TestError(Exception):
    pass

def escape_arg(arg):
    "Shell-escpae arg, if necessary"
    if ' ' not in arg:
        return arg
    return '"%s"' % arg.replace('\\', r'\\').replace('"', r'\"')

def fail(message):
    print >> sys.stderr, "dh_xul-ext test error: " + message
    sys.exit(1)

def check_call(cmd, cwd=None):
    return_code = subprocess.call(cmd, cwd=cwd)
    if return_code != 0:
        raise TestError("'" + " ".join(escape_arg(cmd)) + "' returned " + 
                        str(return_code) + ".")

def compare_files(file1, file2):
    actual = open(file1).read().strip()
    expected = open(file2).read().strip()
    if actual != expected:
        raise TestError("Actual substvars files differs from expected file.\n"
                        "Expected content:\n" + expected + "\n" + \
                        "Actual content:\n" + actual)

def test_dh_xul_ext(test):
    basedir = os.path.dirname(__file__)
    testdir = os.path.join(basedir, test)
    clean_cmd = ["fakeroot", "debian/rules", "clean"]
    check_call(clean_cmd, cwd=testdir)
    try:
        cmd = ["fakeroot", "debian/rules", "install"]
        check_call(cmd, cwd=testdir)
        substvars = os.path.join(testdir, "debian",
                                 "xul-ext-test-package.substvars")
        expected = os.path.join(basedir, "expected_result", test + ".substvars")
        compare_files(substvars, expected)
    finally:
        check_call(clean_cmd, cwd=testdir)

def main():
    errors = 0
    for test in TESTS:
        try:
            test_dh_xul_ext(test)
        except TestError, error:
            errors += 1
            print >> sys.stderr, "dh_xul-ext error in " + test + " test: " + \
                                 str(error)
    if errors > 0:
        sys.exit(1)

if __name__ == "__main__":
    main()