diff --git a/e2e/binary/BUILD.bazel b/e2e/binary/BUILD.bazel index 12a2bf99e80503c8c7960482add9ac8c8c7d20e8..ede035ea54f5c456ab5ecf10210c8c69c79debe8 100644 --- a/e2e/binary/BUILD.bazel +++ b/e2e/binary/BUILD.bazel @@ -12,8 +12,9 @@ build_test( py_library( name = "pytest", srcs = [ + "__init__.py", "conftest.py", - "diff.py", + "difference.py", "relative.py", "runfile.py", "tool.py", diff --git a/e2e/binary/__init__.py b/e2e/binary/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..f79c189427d55c4680385037f927f24f87a82dec --- /dev/null +++ b/e2e/binary/__init__.py @@ -0,0 +1,7 @@ +from __future__ import annotations + +from binary.difference import Diff +from binary.relative import Relative +from binary.tool import Tool + +__all__ = ("Diff", "Tool", "Relative") diff --git a/e2e/binary/b2sum/digest.py b/e2e/binary/b2sum/digest.py index 987f41f859bcd6bf02184664d529d799a04ce8f0..bfe47245312de2896e10083c72c68afe90faf7b0 100644 --- a/e2e/binary/b2sum/digest.py +++ b/e2e/binary/b2sum/digest.py @@ -3,9 +3,7 @@ from __future__ import annotations from pathlib import Path from subprocess import run -from binary.diff import Diff -from binary.relative import Relative -from binary.tool import Tool +from binary import Diff, Relative, Tool def test_digest(tool: Tool, relative: Relative, tmp_path: Path) -> None: diff --git a/e2e/binary/brotli/roundtrip.py b/e2e/binary/brotli/roundtrip.py index af04d8fb261c5e28914631e0a999a2684ae03c8c..e9f67d1998d148b338e15c3366f3492dfc1c971d 100644 --- a/e2e/binary/brotli/roundtrip.py +++ b/e2e/binary/brotli/roundtrip.py @@ -4,9 +4,7 @@ from pathlib import Path from shutil import copyfileobj from subprocess import PIPE, Popen -from binary.diff import Diff -from binary.relative import Relative -from binary.tool import Tool +from binary import Diff, Relative, Tool def test_roundtrip(tool: Tool, relative: Relative, tmp_path: Path) -> None: diff --git a/e2e/binary/bzip2/roundtrip.py b/e2e/binary/bzip2/roundtrip.py index f2feaa654beba1a1815c97f29dee16004a6fc543..5ef47ea53145904318470871a1d772998eb0a8d4 100644 --- a/e2e/binary/bzip2/roundtrip.py +++ b/e2e/binary/bzip2/roundtrip.py @@ -4,9 +4,7 @@ from pathlib import Path from shutil import copyfileobj from subprocess import PIPE, Popen -from binary.diff import Diff -from binary.relative import Relative -from binary.tool import Tool +from binary import Diff, Relative, Tool def test_roundtrip(tool: Tool, relative: Relative, tmp_path: Path) -> None: diff --git a/e2e/binary/cmp/BUILD.bazel b/e2e/binary/cmp/BUILD.bazel index 02947c538a7a987cdf9ea2d4d3441cb6e0212f57..5e657eae152c7c7663598831b73f3400dc5cce2d 100644 --- a/e2e/binary/cmp/BUILD.bazel +++ b/e2e/binary/cmp/BUILD.bazel @@ -1,11 +1,33 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") -# TODO: write an _actual_ test for `cmp` +py_pytest_test( + name = "text", + size = "small", + srcs = ["text.py"], + data = [ + "a.txt", + "b.txt", + "expected.txt", + "@ape//ape:cmp", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "cmp", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:cmp"], + src = "@ape//ape:cmp", + args = ["--version"], +) + +test_suite( + name = "cmp", + tests = [ + ":text", + ":version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/cmp/a.txt b/e2e/binary/cmp/a.txt new file mode 100644 index 0000000000000000000000000000000000000000..d47fbf508c628c4e64c26511ec80caee66b35307 --- /dev/null +++ b/e2e/binary/cmp/a.txt @@ -0,0 +1,5 @@ +Hello, world! + +This is some text. + +This is some other text. diff --git a/e2e/binary/cmp/b.txt b/e2e/binary/cmp/b.txt new file mode 100644 index 0000000000000000000000000000000000000000..00a57ad52b904e6ea8b005658dbe7e0557d0beaf --- /dev/null +++ b/e2e/binary/cmp/b.txt @@ -0,0 +1,8 @@ +Hello, world? + +This is text. + + +This is some text. + +This is more text. diff --git a/e2e/binary/cmp/expected.txt b/e2e/binary/cmp/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..7c963fafd7a75cff6fb19ceea3f470c7c5be6f10 --- /dev/null +++ b/e2e/binary/cmp/expected.txt @@ -0,0 +1 @@ +binary/cmp/a.txt binary/cmp/b.txt differ: char 13, line 1 diff --git a/e2e/binary/cmp/text.py b/e2e/binary/cmp/text.py new file mode 100644 index 0000000000000000000000000000000000000000..fe9e7b81bc1e93dc2618fc3b4baa388c9273a390 --- /dev/null +++ b/e2e/binary/cmp/text.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run +from tarfile import REGTYPE, TarFile + +from binary import Diff, Relative, Tool + + +def test_normal(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("cmp") + a = relative("a.txt") + b = relative("b.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, str(a), str(b)) + with open(output, "w", encoding="utf-8") as stream: + result = run(cmd, timeout=30, stdout=stream) + assert 1 == result.returncode + + with open(expected) as a, open(output) as b: + assert a.read() == b.read() diff --git a/e2e/binary/conftest.py b/e2e/binary/conftest.py index 4c98c8bca9adeec8bf68f24568d96ca40d1123c6..f85f9f59e437a5c7ce5d4d2ffca51c494675093c 100644 --- a/e2e/binary/conftest.py +++ b/e2e/binary/conftest.py @@ -2,12 +2,14 @@ from __future__ import annotations from pytest import fixture -from .diff import Diff -from .diff import repr as diff +from .difference import Diff +from .difference import repr as diff from .relative import Relative from .runfile import Runfile, SupportsRlocation, create from .tool import Tool +__all__ = ("Diff", "Relative", "Tool", "Runfile") + @fixture def runfiles() -> SupportsRlocation: diff --git a/e2e/binary/diff/BUILD.bazel b/e2e/binary/diff/BUILD.bazel index a4d660690422768205df253440db8d7f863df8f8..45fa9b5cd435f2cffe483b2c9d49902eaca4830c 100644 --- a/e2e/binary/diff/BUILD.bazel +++ b/e2e/binary/diff/BUILD.bazel @@ -1,11 +1,33 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") -# TODO: write an _actual_ test for `diff` +py_pytest_test( + name = "normal", + size = "small", + srcs = ["normal.py"], + data = [ + "a.txt", + "b.txt", + "expected.txt", + "@ape//ape:diff", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "diff", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:diff"], + src = "@ape//ape:diff", + args = ["--version"], +) + +test_suite( + name = "diff", + tests = [ + ":normal", + ":version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/diff/a.txt b/e2e/binary/diff/a.txt new file mode 100644 index 0000000000000000000000000000000000000000..d47fbf508c628c4e64c26511ec80caee66b35307 --- /dev/null +++ b/e2e/binary/diff/a.txt @@ -0,0 +1,5 @@ +Hello, world! + +This is some text. + +This is some other text. diff --git a/e2e/binary/diff/b.txt b/e2e/binary/diff/b.txt new file mode 100644 index 0000000000000000000000000000000000000000..00a57ad52b904e6ea8b005658dbe7e0557d0beaf --- /dev/null +++ b/e2e/binary/diff/b.txt @@ -0,0 +1,8 @@ +Hello, world? + +This is text. + + +This is some text. + +This is more text. diff --git a/e2e/binary/diff/expected.txt b/e2e/binary/diff/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..cb9c196e8d72211010723e95f7426f51cc5930f2 --- /dev/null +++ b/e2e/binary/diff/expected.txt @@ -0,0 +1,11 @@ +1c1,4 +< Hello, world! +--- +> Hello, world? +> +> This is text. +> +5c8 +< This is some other text. +--- +> This is more text. diff --git a/e2e/binary/diff/normal.py b/e2e/binary/diff/normal.py new file mode 100644 index 0000000000000000000000000000000000000000..cb9a993140c28317a6628da0cbbc3a700ddc788d --- /dev/null +++ b/e2e/binary/diff/normal.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run +from tarfile import REGTYPE, TarFile + +from binary import Diff, Relative, Tool + + +def test_normal(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("diff") + a = relative("a.txt") + b = relative("b.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, str(a), str(b)) + with open(output, "w", encoding="utf-8") as stream: + result = run(cmd, timeout=30, stdout=stream) + assert 1 == result.returncode + + with open(expected) as a, open(output) as b: + assert a.read() == b.read() diff --git a/e2e/binary/diff3/BUILD.bazel b/e2e/binary/diff3/BUILD.bazel index 57ddfd71a14b20479eb65ad35e11f37cb932c12c..26e6bf0241232fbab6ebff9d153096e55dadfb1b 100644 --- a/e2e/binary/diff3/BUILD.bazel +++ b/e2e/binary/diff3/BUILD.bazel @@ -1,11 +1,35 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") -# TODO: write an _actual_ test for `diff3` +py_pytest_test( + name = "threeway", + size = "small", + srcs = ["threeway.py"], + data = [ + "a.txt", + "b.txt", + "c.txt", + "expected.txt", + "@ape//ape:diff", + "@ape//ape:diff3", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "diff3", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:diff3"], + src = "@ape//ape:diff3", + args = ["--version"], +) + +test_suite( + name = "diff3", + tests = [ + ":threeway", + ":version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/diff3/a.txt b/e2e/binary/diff3/a.txt new file mode 100644 index 0000000000000000000000000000000000000000..d47fbf508c628c4e64c26511ec80caee66b35307 --- /dev/null +++ b/e2e/binary/diff3/a.txt @@ -0,0 +1,5 @@ +Hello, world! + +This is some text. + +This is some other text. diff --git a/e2e/binary/diff3/b.txt b/e2e/binary/diff3/b.txt new file mode 100644 index 0000000000000000000000000000000000000000..00a57ad52b904e6ea8b005658dbe7e0557d0beaf --- /dev/null +++ b/e2e/binary/diff3/b.txt @@ -0,0 +1,8 @@ +Hello, world? + +This is text. + + +This is some text. + +This is more text. diff --git a/e2e/binary/diff3/c.txt b/e2e/binary/diff3/c.txt new file mode 100644 index 0000000000000000000000000000000000000000..13a7ca44c3f7e4555fc476a274294ab353c1d2f1 --- /dev/null +++ b/e2e/binary/diff3/c.txt @@ -0,0 +1,5 @@ +Hello, Earth! + +This is some words. + +This is some other text. diff --git a/e2e/binary/diff3/expected.txt b/e2e/binary/diff3/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3d3ec2a1e51b34ccf4e29af97ff1493342ead17a --- /dev/null +++ b/e2e/binary/diff3/expected.txt @@ -0,0 +1,23 @@ +==== +1:1c + Hello, world! +2:1c + Hello, world? +3:1c + Hello, Earth! +==== +1:3c + This is some text. +2:3c + This is text. +3:3c + This is some words. +====2 +1:5c +3:5c + This is some other text. +2:5,8c + + This is some text. + + This is more text. diff --git a/e2e/binary/diff3/threeway.py b/e2e/binary/diff3/threeway.py new file mode 100644 index 0000000000000000000000000000000000000000..252e15022e69f0d409df30290650bca8f247894c --- /dev/null +++ b/e2e/binary/diff3/threeway.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run +from tarfile import REGTYPE, TarFile + +from binary import Diff, Relative, Tool + + +def test_threeway(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("diff3") + diff = tool("diff") + a = relative("a.txt") + b = relative("b.txt") + c = relative("c.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, "--diff-program", str(diff), str(a), str(b), str(c)) + with open(output, "w", encoding="utf-8") as stream: + result = run(cmd, timeout=30, stdout=stream, check=True) + + with open(expected) as a, open(output) as b: + assert a.read() == b.read() diff --git a/e2e/binary/diff.py b/e2e/binary/difference.py similarity index 100% rename from e2e/binary/diff.py rename to e2e/binary/difference.py diff --git a/e2e/binary/gzip/roundtrip.py b/e2e/binary/gzip/roundtrip.py index 68a3d112c098188ce95252e4a39a242925a70b0e..3e83ebb5ff3e457d342b017ec0b1747df6032f17 100644 --- a/e2e/binary/gzip/roundtrip.py +++ b/e2e/binary/gzip/roundtrip.py @@ -4,9 +4,7 @@ from pathlib import Path from shutil import copyfileobj from subprocess import PIPE, Popen -from binary.diff import Diff -from binary.relative import Relative -from binary.tool import Tool +from binary import Diff, Relative, Tool def test_roundtrip(tool: Tool, relative: Relative, tmp_path: Path) -> None: diff --git a/e2e/binary/pigz/roundtrip.py b/e2e/binary/pigz/roundtrip.py index af06be6a35f4ae55f106ba8e198a2d1f1c3483ba..a1ee0d78c4a1893c5a24ad05ceb550a38dd5e934 100644 --- a/e2e/binary/pigz/roundtrip.py +++ b/e2e/binary/pigz/roundtrip.py @@ -4,9 +4,7 @@ from pathlib import Path from shutil import copyfileobj from subprocess import PIPE, Popen -from binary.diff import Diff -from binary.relative import Relative -from binary.tool import Tool +from binary import Diff, Relative, Tool def test_roundtrip(tool: Tool, relative: Relative, tmp_path: Path) -> None: diff --git a/e2e/binary/sdiff/BUILD.bazel b/e2e/binary/sdiff/BUILD.bazel index b176048402eb928b5ea36bef031150709be0a86c..db219d129b94873b3d2fac0efee2f9d37fc4f45e 100644 --- a/e2e/binary/sdiff/BUILD.bazel +++ b/e2e/binary/sdiff/BUILD.bazel @@ -1,11 +1,34 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") -# TODO: write an _actual_ test for `sdiff` +py_pytest_test( + name = "diff", + size = "small", + srcs = ["diff.py"], + data = [ + "a.txt", + "b.txt", + "expected.txt", + "@ape//ape:diff", + "@ape//ape:sdiff", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "sdiff", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:sdiff"], + src = "@ape//ape:sdiff", + args = ["--version"], +) + +test_suite( + name = "sdiff", + tests = [ + ":diff", + ":version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/sdiff/a.txt b/e2e/binary/sdiff/a.txt new file mode 100644 index 0000000000000000000000000000000000000000..d47fbf508c628c4e64c26511ec80caee66b35307 --- /dev/null +++ b/e2e/binary/sdiff/a.txt @@ -0,0 +1,5 @@ +Hello, world! + +This is some text. + +This is some other text. diff --git a/e2e/binary/sdiff/b.txt b/e2e/binary/sdiff/b.txt new file mode 100644 index 0000000000000000000000000000000000000000..00a57ad52b904e6ea8b005658dbe7e0557d0beaf --- /dev/null +++ b/e2e/binary/sdiff/b.txt @@ -0,0 +1,8 @@ +Hello, world? + +This is text. + + +This is some text. + +This is more text. diff --git a/e2e/binary/sdiff/diff.py b/e2e/binary/sdiff/diff.py new file mode 100644 index 0000000000000000000000000000000000000000..0402883f1c8271105802ae94cf99c5d7159c2e74 --- /dev/null +++ b/e2e/binary/sdiff/diff.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run +from tarfile import REGTYPE, TarFile + +from binary import Diff, Relative, Tool + + +def test_diff(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("sdiff") + diff = tool("diff") + a = relative("a.txt") + b = relative("b.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, f"--diff-program={diff}", "--width=80", str(a), str(b)) + with open(output, "w", encoding="utf-8") as stream: + result = run(cmd, timeout=30, stdout=stream) + assert 1 == result.returncode + + with open(expected) as a, open(output) as b: + assert a.read() == b.read() diff --git a/e2e/binary/sdiff/expected.txt b/e2e/binary/sdiff/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..47e69649d1cd825f53355ff5f01be3ba3e18a46e --- /dev/null +++ b/e2e/binary/sdiff/expected.txt @@ -0,0 +1,8 @@ +Hello, world! | Hello, world? + > + > This is text. + > + +This is some text. This is some text. + +This is some other text. | This is more text. diff --git a/e2e/binary/xz/roundtrip.py b/e2e/binary/xz/roundtrip.py index dc7688636f849c1f3d8b4e9b52869cadf633f2b6..f2c3cda260bcf8a7a94eb1dee2cd5c1771f59f40 100644 --- a/e2e/binary/xz/roundtrip.py +++ b/e2e/binary/xz/roundtrip.py @@ -4,9 +4,7 @@ from pathlib import Path from shutil import copyfileobj from subprocess import PIPE, Popen -from binary.diff import Diff -from binary.relative import Relative -from binary.tool import Tool +from binary import Diff, Relative, Tool def test_roundtrip(tool: Tool, relative: Relative, tmp_path: Path) -> None: diff --git a/e2e/binary/zstd/roundtrip.py b/e2e/binary/zstd/roundtrip.py index 71d2b3e89ff9c2ca831dc9e69b16a8a8640fc0e0..3d633609d319d64338bdfe30cf98b39735b29700 100644 --- a/e2e/binary/zstd/roundtrip.py +++ b/e2e/binary/zstd/roundtrip.py @@ -4,9 +4,7 @@ from pathlib import Path from shutil import copyfileobj from subprocess import PIPE, Popen -from binary.diff import Diff -from binary.relative import Relative -from binary.tool import Tool +from binary import Diff, Relative, Tool def test_roundtrip(tool: Tool, relative: Relative, tmp_path: Path) -> None: