From 63fa25f291c41f29ba62ae38692c8681dedf522a Mon Sep 17 00:00:00 2001 From: Sebastian Birunt Date: Thu, 12 Jun 2025 09:16:59 +0200 Subject: [PATCH 1/6] test: add `stat` tests Add tests for `stat` command. --- e2e/binary/stat/BUILD.bazel | 31 +++++++++++++++++++++++++------ e2e/binary/stat/stat.py | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/stat/stat.py diff --git a/e2e/binary/stat/BUILD.bazel b/e2e/binary/stat/BUILD.bazel index 8b9cdb99..29887617 100644 --- a/e2e/binary/stat/BUILD.bazel +++ b/e2e/binary/stat/BUILD.bazel @@ -1,11 +1,30 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") -# TODO: write an _actual_ test for `stat` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["stat.py"], + data = [ + "@ape//ape:stat", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "stat", +native_test( + name = "native", size = "small", - tags = ["stub"], - targets = ["@ape//ape:stat"], + src = "@ape//ape:stat", + args = ["--version"], +) + +test_suite( + name = "stat", + tests = [ + "native", + "pytest", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/stat/stat.py b/e2e/binary/stat/stat.py new file mode 100644 index 00000000..990bb162 --- /dev/null +++ b/e2e/binary/stat/stat.py @@ -0,0 +1,21 @@ +from __future__ import annotations + +from subprocess import run +from pathlib import Path + +from binary.tool import Tool + + +def test_stat(tool: Tool, tmp_path: Path) -> None: + binary = tool("stat") + input_path = tmp_path / "input_file" + + with open(input_path, "w") as file: + file.write("hello") + + cmd = (binary, "--format=%A", input_path) + result = run(cmd, check=True, timeout=30, capture_output=True, text=True) + + actual = result.stdout.strip() + expected = "-rw-r--r--" + assert actual == expected -- GitLab From caa96703639855ec949529da9a660d557121d929 Mon Sep 17 00:00:00 2001 From: Sebastian Birunt Date: Thu, 12 Jun 2025 10:00:40 +0200 Subject: [PATCH 2/6] test: add `sed` tests Add tests for `sed` command. --- e2e/binary/sed/BUILD.bazel | 31 +++++++++++++++++++++++++------ e2e/binary/sed/sed.py | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/sed/sed.py diff --git a/e2e/binary/sed/BUILD.bazel b/e2e/binary/sed/BUILD.bazel index da498a72..6281c158 100644 --- a/e2e/binary/sed/BUILD.bazel +++ b/e2e/binary/sed/BUILD.bazel @@ -1,11 +1,30 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") -# TODO: write an _actual_ test for `sed` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["sed.py"], + data = [ + "@ape//ape:sed", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "sed", +native_test( + name = "native", size = "small", - tags = ["stub"], - targets = ["@ape//ape:sed"], + src = "@ape//ape:sed", + args = ["--version"], +) + +test_suite( + name = "sed", + tests = [ + "native", + "pytest", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/sed/sed.py b/e2e/binary/sed/sed.py new file mode 100644 index 00000000..a8286341 --- /dev/null +++ b/e2e/binary/sed/sed.py @@ -0,0 +1,21 @@ +from __future__ import annotations + +from subprocess import run +from pathlib import Path + +from binary.tool import Tool + + +def test_sed(tool: Tool, tmp_path: Path) -> None: + binary = tool("sed") + input_path = tmp_path / "input_file" + + with open(input_path, "w") as file: + file.write("hello world") + + cmd = (binary, "s/world/bazel/g", input_path) + result = run(cmd, check=True, timeout=30, capture_output=True, text=True) + + actual = result.stdout.strip() + expected = "hello bazel" + assert actual == expected -- GitLab From 3a5da8cacd18d6a0be0f1bf1d4ce4c22363aad53 Mon Sep 17 00:00:00 2001 From: Sebastian Birunt Date: Thu, 12 Jun 2025 10:16:19 +0200 Subject: [PATCH 3/6] test: add `shuf` tests Add tests for `shuf` command. --- e2e/binary/shuf/BUILD.bazel | 31 +++++++++++++++++++++++++------ e2e/binary/shuf/shuf.py | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/shuf/shuf.py diff --git a/e2e/binary/shuf/BUILD.bazel b/e2e/binary/shuf/BUILD.bazel index 169b514b..20f6515e 100644 --- a/e2e/binary/shuf/BUILD.bazel +++ b/e2e/binary/shuf/BUILD.bazel @@ -1,11 +1,30 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") -# TODO: write an _actual_ test for `shuf` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["shuf.py"], + data = [ + "@ape//ape:shuf", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "shuf", +native_test( + name = "native", size = "small", - tags = ["stub"], - targets = ["@ape//ape:shuf"], + src = "@ape//ape:shuf", + args = ["--version"], +) + +test_suite( + name = "shuf", + tests = [ + "native", + "pytest", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/shuf/shuf.py b/e2e/binary/shuf/shuf.py new file mode 100644 index 00000000..39f90ca2 --- /dev/null +++ b/e2e/binary/shuf/shuf.py @@ -0,0 +1,21 @@ +from __future__ import annotations + +from subprocess import run + +from binary.tool import Tool + + +def test_shuf(tool: Tool) -> None: + binary = tool("shuf") + shuf_min = 5 + shuf_max = 15 + + cmd = (binary, "-i", f"{shuf_min}-{shuf_max}") + result = run(cmd, check=True, timeout=30, capture_output=True, text=True) + + numbers = [int(x) for x in result.stdout.splitlines()] + + assert shuf_min == min(numbers) + assert shuf_max == max(numbers) + assert 11 == len(numbers) + assert 110 == sum(numbers) -- GitLab From 060d9dc39a79fcc64ae9be4c920f3b737888ab00 Mon Sep 17 00:00:00 2001 From: Sebastian Birunt Date: Thu, 12 Jun 2025 10:27:38 +0200 Subject: [PATCH 4/6] test: add `sleep` tests Add tests for `sleep` command. --- e2e/binary/sleep/BUILD.bazel | 31 +++++++++++++++++++++++++------ e2e/binary/sleep/sleep.py | 18 ++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/sleep/sleep.py diff --git a/e2e/binary/sleep/BUILD.bazel b/e2e/binary/sleep/BUILD.bazel index 38501238..13c08e10 100644 --- a/e2e/binary/sleep/BUILD.bazel +++ b/e2e/binary/sleep/BUILD.bazel @@ -1,11 +1,30 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") -# TODO: write an _actual_ test for `sleep` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["sleep.py"], + data = [ + "@ape//ape:sleep", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "sleep", +native_test( + name = "native", size = "small", - tags = ["stub"], - targets = ["@ape//ape:sleep"], + src = "@ape//ape:sleep", + args = ["--version"], +) + +test_suite( + name = "sleep", + tests = [ + "native", + "pytest", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/sleep/sleep.py b/e2e/binary/sleep/sleep.py new file mode 100644 index 00000000..1492c793 --- /dev/null +++ b/e2e/binary/sleep/sleep.py @@ -0,0 +1,18 @@ +from __future__ import annotations + +from subprocess import run +from time import monotonic as time + +from binary.tool import Tool + + +def test_sleep(tool: Tool) -> None: + binary = tool("sleep") + delay = 0.1 + + start = time() + cmd = (binary, f"{delay}") + run(cmd, check=True, timeout=30) + + elapsed = time() - start + assert delay <= elapsed -- GitLab From 23219d467de52a5a8df0b17f76c9c2dc0c2f25c3 Mon Sep 17 00:00:00 2001 From: Sebastian Birunt Date: Thu, 12 Jun 2025 10:41:07 +0200 Subject: [PATCH 5/6] test: add `sort` tests Add tests for `sort` command. --- e2e/binary/sort/BUILD.bazel | 33 +++++++++++++++++++++++++++------ e2e/binary/sort/expected.txt | 14 ++++++++++++++ e2e/binary/sort/fixture.txt | 14 ++++++++++++++ e2e/binary/sort/sort.py | 19 +++++++++++++++++++ 4 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/sort/expected.txt create mode 100644 e2e/binary/sort/fixture.txt create mode 100644 e2e/binary/sort/sort.py diff --git a/e2e/binary/sort/BUILD.bazel b/e2e/binary/sort/BUILD.bazel index e6adee64..e3fb046a 100644 --- a/e2e/binary/sort/BUILD.bazel +++ b/e2e/binary/sort/BUILD.bazel @@ -1,11 +1,32 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") -# TODO: write an _actual_ test for `sort` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["sort.py"], + data = [ + "expected.txt", + "fixture.txt", + "@ape//ape:sort", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "sort", +native_test( + name = "native", size = "small", - tags = ["stub"], - targets = ["@ape//ape:sort"], + src = "@ape//ape:sort", + args = ["--version"], +) + +test_suite( + name = "sort", + tests = [ + "native", + "pytest", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/sort/expected.txt b/e2e/binary/sort/expected.txt new file mode 100644 index 00000000..95f8033d --- /dev/null +++ b/e2e/binary/sort/expected.txt @@ -0,0 +1,14 @@ +1 +101 +1010 +15 +23 +25 +3 +3 +44 +555 +61 +69 +7 +86 diff --git a/e2e/binary/sort/fixture.txt b/e2e/binary/sort/fixture.txt new file mode 100644 index 00000000..d987518d --- /dev/null +++ b/e2e/binary/sort/fixture.txt @@ -0,0 +1,14 @@ +69 +7 +15 +44 +23 +25 +101 +3 +86 +555 +61 +1010 +1 +3 diff --git a/e2e/binary/sort/sort.py b/e2e/binary/sort/sort.py new file mode 100644 index 00000000..76a8c52f --- /dev/null +++ b/e2e/binary/sort/sort.py @@ -0,0 +1,19 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run + +from binary import Diff, Relative, Tool + + +def test_sort(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("sort") + fixture = relative("fixture.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, fixture) + with open(output, "w") as stream: + run(cmd, check=True, timeout=30, stdout=stream) + + assert Diff(expected) == Diff(output) -- GitLab From f4c5a4db52daeaae4b64257e62737559c5ec4360 Mon Sep 17 00:00:00 2001 From: Sebastian Birunt Date: Thu, 12 Jun 2025 10:49:11 +0200 Subject: [PATCH 6/6] test: add `ptx` test Add tests for `sort` command. --- e2e/binary/ptx/BUILD.bazel | 33 +++++++++++++++++++++++++++------ e2e/binary/ptx/expected.txt | 8 ++++++++ e2e/binary/ptx/fixture.txt | 1 + e2e/binary/ptx/ptx.py | 19 +++++++++++++++++++ 4 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/ptx/expected.txt create mode 100644 e2e/binary/ptx/fixture.txt create mode 100644 e2e/binary/ptx/ptx.py diff --git a/e2e/binary/ptx/BUILD.bazel b/e2e/binary/ptx/BUILD.bazel index bc07933d..5d9f60a0 100644 --- a/e2e/binary/ptx/BUILD.bazel +++ b/e2e/binary/ptx/BUILD.bazel @@ -1,11 +1,32 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") -# TODO: write an _actual_ test for `ptx` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["ptx.py"], + data = [ + "expected.txt", + "fixture.txt", + "@ape//ape:ptx", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "ptx", +native_test( + name = "native", size = "small", - tags = ["stub"], - targets = ["@ape//ape:ptx"], + src = "@ape//ape:ptx", + args = ["--version"], +) + +test_suite( + name = "ptx", + tests = [ + "native", + "pytest", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/ptx/expected.txt b/e2e/binary/ptx/expected.txt new file mode 100644 index 00000000..56810465 --- /dev/null +++ b/e2e/binary/ptx/expected.txt @@ -0,0 +1,8 @@ + αcτµαlly pδrτα blε εxεcµταblε + αlly pδrταblε εxεcµτα blε αcτµ + αblε α cτµαlly pδrταblε εxεcµτ + αcτµαlly pδrταblε εxε cµταblε + αcτµα lly pδrταblε εxεcµταblε + αcτµαlly pδrταblε εxεcµταblε + αcτµαlly pδ rταblε εxεcµταblε + αcτµαlly pδrταblε ε xεcµταblε diff --git a/e2e/binary/ptx/fixture.txt b/e2e/binary/ptx/fixture.txt new file mode 100644 index 00000000..5d5b8b48 --- /dev/null +++ b/e2e/binary/ptx/fixture.txt @@ -0,0 +1 @@ +αcτµαlly pδrταblε εxεcµταblε diff --git a/e2e/binary/ptx/ptx.py b/e2e/binary/ptx/ptx.py new file mode 100644 index 00000000..b3d45d7c --- /dev/null +++ b/e2e/binary/ptx/ptx.py @@ -0,0 +1,19 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run + +from binary import Diff, Relative, Tool + + +def test_ptx(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("ptx") + fixture = relative("fixture.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, fixture) + with open(output, "w") as stream: + run(cmd, check=True, timeout=30, stdout=stream) + + assert Diff(expected) == Diff(output) -- GitLab