diff --git a/e2e/binary/ptx/BUILD.bazel b/e2e/binary/ptx/BUILD.bazel index bc07933d5bc603ce523bf0bb98fc508b92922340..5d9f60a0149d7db1f6bb62bfe9bb97d29de3d651 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 0000000000000000000000000000000000000000..56810465ce8d9045ddcdba0ee298abf56a040880 --- /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 0000000000000000000000000000000000000000..5d5b8b48ad7b0938b626ec33252505626deaeaa6 --- /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 0000000000000000000000000000000000000000..b3d45d7c3032d91247bd9517af3c803122e6929f --- /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) diff --git a/e2e/binary/sed/BUILD.bazel b/e2e/binary/sed/BUILD.bazel index da498a72fcdebf70e5ee41ff0e4067021ba62cd2..6281c1584203385f21dac41535aadf46bdd9ec06 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 0000000000000000000000000000000000000000..a8286341b1ca31b7bfb8c3ef839f891f8aaa5a99 --- /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 diff --git a/e2e/binary/shuf/BUILD.bazel b/e2e/binary/shuf/BUILD.bazel index 169b514b8a9623d2aa22c1087416b7d0c7a0411d..20f6515ec58903ac32e4e4452f91f70d742ac52b 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 0000000000000000000000000000000000000000..39f90ca2fe757f9cbce79ca9ac9cecd94fa0972e --- /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) diff --git a/e2e/binary/sleep/BUILD.bazel b/e2e/binary/sleep/BUILD.bazel index 38501238eb12d57f102b5671874b35aaf9f5e741..13c08e10cf5fb65ac6847e20b307f1ea8b50ce4a 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 0000000000000000000000000000000000000000..1492c793e4563b88d73ecf6b2a540bcc8a68bcfb --- /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 diff --git a/e2e/binary/sort/BUILD.bazel b/e2e/binary/sort/BUILD.bazel index e6adee6452430b24b99b6644575a37afce281864..e3fb046acd9d0188cb1b4f018d43b1ffb12d98ec 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 0000000000000000000000000000000000000000..95f8033de238e27d4cdc2b8c866570c23cda3546 --- /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 0000000000000000000000000000000000000000..d987518d7bb50677d1819b769944b1f27a4d40f3 --- /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 0000000000000000000000000000000000000000..76a8c52f97611c5a95199dadbd41393524e35437 --- /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) diff --git a/e2e/binary/stat/BUILD.bazel b/e2e/binary/stat/BUILD.bazel index 8b9cdb99bd1e9aeac6c7b97d25ff65d483c6ee39..29887617bc74a5732b1617675325fd9334e7072a 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 0000000000000000000000000000000000000000..990bb162c18eb148e989f9442313a5fe6c8bc909 --- /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