Skip to content
Snippets Groups Projects
Commit bc92ac31 authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

Add support for comparing OCaml files via ocamlobjinfo. (Closes: #910542)

parent fa35199d
No related branches found
No related tags found
No related merge requests found
Pipeline #22054 failed
......@@ -44,6 +44,7 @@ Build-Depends:
llvm <!nocheck>,
lz4 <!nocheck> | liblz4-tool <!nocheck>,
mono-utils <!nocheck>,
ocaml-nox <!nocheck>,
odt2txt <!nocheck>,
# oggvideotools [!s390x] <!nocheck>,
openssh-client <!nocheck>,
......
......@@ -83,6 +83,7 @@ class ComparatorManager(object):
('xz.XzFile',),
('apk.ApkFile',),
('odt.OdtFile',),
('ocaml.OcamlInterfaceFile',),
('docx.DocxFile',),
('zip.ZipFile',),
('zip.MozillaZipFile',),
......
# -*- coding: utf-8 -*-
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2018 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffoscope is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import re
from diffoscope.tools import tool_required
from diffoscope.difference import Difference
from .utils.file import File
from .utils.command import Command
class Ocamlobjinfo(Command):
@tool_required('ocamlobjinfo')
def cmdline(self):
return ('ocamlobjinfo', self.path)
def filter(self, line):
val = line.decode('utf-8')
if val.startswith('File '):
return b''
return line
class OcamlInterfaceFile(File):
DESCRIPTION = "OCaml interface files"
FILE_TYPE_RE = re.compile(r'^OCaml interface file ')
def compare_details(self, other, source=None):
return [Difference.from_command(
Ocamlobjinfo,
self.path,
other.path,
source="ocamlobjinfo",
)]
......@@ -170,6 +170,9 @@ EXTERNAL_TOOLS = {
'debian': 'binutils-multiarch',
'arch': 'binutils',
},
'ocamlobjinfo': {
'debian': 'ocaml-nox',
},
'odt2txt': {
'debian': 'odt2txt',
'arch': 'odt2txt',
......
# -*- coding: utf-8 -*-
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2018 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffoscope is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import pytest
from diffoscope.comparators.ocaml import OcamlInterfaceFile
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
from ..utils.nonexisting import assert_non_existing
cmi1 = load_fixture('test1.cmi')
cmi2 = load_fixture('test2.cmi')
def test_identification(cmi1):
assert isinstance(cmi1, OcamlInterfaceFile)
@pytest.fixture
def differences(cmi1, cmi2):
return cmi1.compare(cmi2).details
def test_no_differences(cmi1):
difference = cmi1.compare(cmi1)
assert difference is None
@skip_unless_tools_exist('ocamlobjinfo')
def test_diff(differences):
expected_diff = get_data('ocaml_expected_diff')
assert differences[0].unified_diff == expected_diff
@skip_unless_tools_exist('ocamlobjinfo')
def test_compare_non_existing(monkeypatch, cmi1):
assert_non_existing(monkeypatch, cmi1, has_null_source=False)
@@ -1,5 +1,14 @@
Unit name: Uchar
Interfaces imported:
84838649f9351de166bfa8b9f2c84db4 Uchar
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
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment