Skip to content
Commits on Source (3)
......@@ -452,14 +452,34 @@ class File(object, metaclass=abc.ABCMeta):
cmd = ' '.join(e.cmd)
if difference is None:
return None
output = '<none>'
if e.output:
output = '\n{}'.format(
re.sub(r'^', ' ', e.output, flags=re.MULTILINE)
)
# Include either stderr (prefered) or stdout in the hexdump
# difference
suffix = None
for prefix, val in (
("Standard output", e.stdout),
("Standard error", e.stderr),
):
if not val:
continue
suffix = ' {}:\n{}'.format(
prefix,
re.sub(
r'^',
' ',
val.decode('utf-8'),
flags=re.MULTILINE,
),
).strip()
# Truncate output
max_len = 250
if len(suffix) > max_len:
suffix = '{} [...]'.format(suffix[:max_len])
difference.add_comment(
"Command `{}` exited with return code {}. Output: {}".format(
cmd, e.returncode, output
"Command `{}` exited with return code {}.{}".format(
cmd, e.returncode, suffix or " (No output)"
)
)
except RequiredToolNotFound as e:
......
......@@ -23,7 +23,11 @@ import subprocess
from diffoscope.comparators.squashfs import SquashfsFile
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from ..utils.tools import (
skip_unless_tools_exist,
skip_unless_tool_is_at_least,
skip_unless_root,
)
from ..utils.nonexisting import assert_non_existing
......@@ -50,6 +54,7 @@ def test_no_differences(squashfs1):
assert difference is None
@skip_unless_root
def test_no_warnings(capfd, squashfs1, squashfs2):
_ = squashfs1.compare(squashfs2)
_, err = capfd.readouterr()
......@@ -61,12 +66,14 @@ def differences(squashfs1, squashfs2):
return squashfs1.compare(squashfs2).details
@skip_unless_root
@skip_unless_tool_is_at_least('unsquashfs', unsquashfs_version, '4.4')
def test_superblock(differences):
expected_diff = get_data('squashfs_superblock_expected_diff')
assert differences[0].unified_diff == expected_diff
@skip_unless_root
@skip_unless_tools_exist('unsquashfs')
def test_symlink(differences):
assert differences[2].comment == 'symlink'
......@@ -74,6 +81,7 @@ def test_symlink(differences):
assert differences[2].unified_diff == expected_diff
@skip_unless_root
@skip_unless_tools_exist('unsquashfs')
def test_compressed_files(differences):
assert differences[3].source1 == '/text'
......@@ -82,6 +90,7 @@ def test_compressed_files(differences):
assert differences[3].unified_diff == expected_diff
@skip_unless_root
@skip_unless_tools_exist('unsquashfs')
def test_compare_non_existing(monkeypatch, squashfs1):
assert_non_existing(monkeypatch, squashfs1)
......@@ -201,3 +201,8 @@ def skip_unless_module_exists(name):
def skip_unless_file_version_is_at_least(version):
return skip_unless_tool_is_at_least('file', file_version, version)
skip_unless_root = pytest.mark.skipif(
os.geteuid() != 0, reason="requires root/fakeroot"
)