#!/usr/bin/python # Copyright (c) 2011, Benjamin Drung # # 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", "debian", "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()