Skip to content
Commits on Source (3)
......@@ -21,13 +21,32 @@ import pytest
import subprocess
from diffoscope.comparators.ocaml import OcamlInterfaceFile
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.utils.specialize import specialize
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tool_is_at_least
from ..utils.nonexisting import assert_non_existing
cmi1 = load_fixture('test1.cmi')
cmi2 = load_fixture('test2.cmi')
def ocaml_fixture(prefix):
@pytest.fixture
def cmi(tmpdir):
input_ = str(tmpdir.join('{}.mli'.format(prefix)))
output = str(tmpdir.join('{}.cmi'.format(prefix)))
with open(input_, 'w') as f:
pass
subprocess.check_call(('ocamlc', '-c', input_))
return specialize(FilesystemFile(output))
return cmi
cmi1 = ocaml_fixture('test1')
cmi2 = ocaml_fixture('test2')
def ocaml_version():
......
@@ -1,5 +1,14 @@
Unit name: Uchar
@@ -1,5 +1,5 @@
-Unit name: Test1
+Unit name: Test2
Interfaces imported:
84838649f9351de166bfa8b9f2c84db4 Uchar
- b5f47409a5d1c32a864ea3d2fbed44db Test1
+ 9ee19396ca59dbe57206a9a88d98a7d5 Test2
07ea9e20ae94d62c35cfecbe7d66d3ea Pervasives
cbd5f2d6b649925222e1e9fb63b89db6 CamlinternalFormatBasics
+Cmt unit name: Uchar
+Cmt interfaces imported:
+ cbd5f2d6b649925222e1e9fb63b89db6 CamlinternalFormatBasics
+ 07ea9e20ae94d62c35cfecbe7d66d3ea Pervasives
+ 84838649f9351de166bfa8b9f2c84db4 Uchar
+Source file: uchar.mli
+Compilation flags: ../ocamlc -strict-sequence -absname -w +a-4-9-41-42-44-45-48 -g -warn-error A -bin-annot -nostdlib -safe-string -strict-formats -c uchar.mli
+Load path:
+cmt interface digest: 84838649f9351de166bfa8b9f2c84db4
......@@ -27,6 +27,8 @@ import subprocess
from distutils.spawn import find_executable
from distutils.version import LooseVersion
from diffoscope.tools import get_package_provider
def file_version():
return (
......@@ -89,7 +91,7 @@ def skipif(*args, **kwargs):
def skip_unless_tools_exist(*required):
return skipif(
tools_missing(*required),
reason="requires {}".format(" and ".join(required)),
reason=reason(*required),
tools=required,
check_env_for_missing_tools=True,
)
......@@ -97,7 +99,7 @@ def skip_unless_tools_exist(*required):
def skip_if_tool_version_is(tool, actual_ver, target_ver, vcls=LooseVersion):
if tools_missing(tool):
return skipif(True, reason="requires {}".format(tool), tools=(tool,))
return skipif(True, reason=reason(tool), tools=(tool,))
if callable(actual_ver):
actual_ver = actual_ver()
return skipif(
......@@ -111,13 +113,13 @@ def skip_if_tool_version_is(tool, actual_ver, target_ver, vcls=LooseVersion):
def skip_unless_tool_is_at_least(tool, actual_ver, min_ver, vcls=LooseVersion):
if tools_missing(tool) and module_is_not_importable(tool):
return skipif(True, reason="requires {}".format(tool), tools=(tool,))
return skipif(True, reason=reason(tool), tools=(tool,))
if callable(actual_ver):
actual_ver = actual_ver()
return skipif(
vcls(str(actual_ver)) < vcls(str(min_ver)),
reason="requires {} >= {} ({} detected)".format(
tool, min_ver, actual_ver
reason="{} >= {} ({} detected)".format(
reason(tool), min_ver, actual_ver
),
tools=(tool,),
)
......@@ -125,13 +127,13 @@ def skip_unless_tool_is_at_least(tool, actual_ver, min_ver, vcls=LooseVersion):
def skip_unless_tool_is_at_most(tool, actual_ver, max_ver, vcls=LooseVersion):
if tools_missing(tool) and module_is_not_importable(tool):
return skipif(True, reason="requires {}".format(tool), tools=(tool,))
return skipif(True, reason=reason(tool), tools=(tool,))
if callable(actual_ver):
actual_ver = actual_ver()
return skipif(
vcls(str(actual_ver)) > vcls(str(max_ver)),
reason="requires {} <= {} ({} detected)".format(
tool, max_ver, actual_ver
reason="{} <= {} ({} detected)".format(
reason(tool), max_ver, actual_ver
),
tools=(tool,),
)
......@@ -141,14 +143,14 @@ def skip_unless_tool_is_between(
tool, actual_ver, min_ver, max_ver, vcls=LooseVersion
):
if tools_missing(tool):
return skipif(True, reason="requires {}".format(tool), tools=(tool,))
return skipif(True, reason=reason(tool), tools=(tool,))
if callable(actual_ver):
actual_ver = actual_ver()
return skipif(
(vcls(str(actual_ver)) < vcls(str(min_ver)))
or (vcls(str(actual_ver)) > vcls(str(max_ver))),
reason="requires {} >= {} >= {} ({} detected)".format(
min_ver, tool, max_ver, actual_ver
reason="{} min {} >= {} ({} detected)".format(
reason(tool), min_ver, max_ver, actual_ver
),
tools=(tool,),
)
......@@ -194,10 +196,24 @@ def module_is_not_importable(x):
def skip_unless_module_exists(name):
return skipif(
module_is_not_importable(name),
reason="requires {} module".format(name),
reason="requires {} Python module".format(name),
tools=('{}_module'.format(name)),
)
def skip_unless_file_version_is_at_least(version):
return skip_unless_tool_is_at_least('file', file_version, version)
def reason(*tools):
xs = []
for x in tools:
provider = get_package_provider(x)
if provider is None:
xs.append(x)
continue
xs.append('{} (try installing {})'.format(x, provider))
return "requires {}".format(" and ".join(xs))