diff --git a/e2e/binary/chmod/BUILD.bazel b/e2e/binary/chmod/BUILD.bazel index ad95dedc98bba9cc64ed574e9c7fcb3d5ce9ac4d..1307113f5bec2ac12703cbe182e16a2589117044 100644 --- a/e2e/binary/chmod/BUILD.bazel +++ b/e2e/binary/chmod/BUILD.bazel @@ -1,11 +1,31 @@ -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 `chmod` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["mode.py"], + data = [ + "@ape//ape:chmod", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "chmod", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:chmod"], + src = "@ape//ape:chmod", + args = ["--version"], + visibility = ["//:__subpackages__"], +) + +test_suite( + name = "chmod", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/chmod/mode.py b/e2e/binary/chmod/mode.py new file mode 100644 index 0000000000000000000000000000000000000000..b5d41248dddfdf049859e2bd0c9a11c1cc6da24c --- /dev/null +++ b/e2e/binary/chmod/mode.py @@ -0,0 +1,26 @@ +from __future__ import annotations + + +from pathlib import Path +from subprocess import PIPE, run + +from binary import Tool + + +def test_mode(tool: Tool, tmp_path: Path) -> None: + binary = tool("chmod") + filepath = tmp_path / "secret.txt" + + filepath.touch() + + assert 0o100644 == filepath.stat().st_mode + + cmd = (binary, "og-rw,-x,u-w", filepath) + run(cmd, check=True, timeout=30, stdout=PIPE) + + assert 0o100400 == filepath.stat().st_mode + + cmd = (binary, "777", filepath) + run(cmd, check=True, timeout=30, stdout=PIPE) + + assert 0o100777 == filepath.stat().st_mode diff --git a/e2e/binary/chown/BUILD.bazel b/e2e/binary/chown/BUILD.bazel index 0c9034caa8fa5cfc364204c4d5455f0fc2bd01bb..2327ba65feaeddc695ab2f902fa268a895edcfd6 100644 --- a/e2e/binary/chown/BUILD.bazel +++ b/e2e/binary/chown/BUILD.bazel @@ -1,11 +1,33 @@ -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 `chown` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["own.py"], + data = [ + "fixture.txt", + "@ape//ape:chown", + ], + tags = ["requires-fakeroot"], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "chown", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:chown"], + src = "@ape//ape:chown", + args = ["--version"], + visibility = ["//:__subpackages__"], +) + +test_suite( + name = "chown", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/chown/fixture.txt b/e2e/binary/chown/fixture.txt new file mode 100644 index 0000000000000000000000000000000000000000..ce013625030ba8dba906f756967f9e9ca394464a --- /dev/null +++ b/e2e/binary/chown/fixture.txt @@ -0,0 +1 @@ +hello diff --git a/e2e/binary/chown/own.py b/e2e/binary/chown/own.py new file mode 100644 index 0000000000000000000000000000000000000000..1c247d4ff15e6f851bb615514b2f70b68f1724fa --- /dev/null +++ b/e2e/binary/chown/own.py @@ -0,0 +1,24 @@ +from __future__ import annotations + + +from pathlib import Path +from subprocess import run + +from binary import Relative, Tool + + +def test_owner(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("chown") + filepath = tmp_path / "random.txt" + fixture = relative("fixture.txt") + + filepath.touch() + + uid = fixture.stat().st_uid + gid = fixture.stat().st_gid + + cmd = (binary, f"{uid}:{gid}", filepath) + run(cmd, check=True, timeout=30) + + assert uid == filepath.stat().st_uid + assert gid == filepath.stat().st_gid diff --git a/e2e/binary/python/BUILD.bazel b/e2e/binary/python/BUILD.bazel index bd0c823c44fe3ccb7439c1669e28894ff8ea7930..9fbab89af1be84c7c5cf58a88e99c4449392a4a2 100644 --- a/e2e/binary/python/BUILD.bazel +++ b/e2e/binary/python/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 `python` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["python.py"], + data = [ + "hello.py", + "@ape//ape:python", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "python", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:python"], + src = "@ape//ape:python", + args = ["--version"], + visibility = ["//:__subpackages__"], +) + +test_suite( + name = "python", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/python/hello.py b/e2e/binary/python/hello.py new file mode 100644 index 0000000000000000000000000000000000000000..1d1fe875174881dba2ea9adcf37c5e373cb1c939 --- /dev/null +++ b/e2e/binary/python/hello.py @@ -0,0 +1,11 @@ +import sys + + +def main() -> int: + print("Hello!", end="") + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/e2e/binary/python/python.py b/e2e/binary/python/python.py new file mode 100644 index 0000000000000000000000000000000000000000..9086ecf74f4e4322dadce5cb5df03f6895cf28b4 --- /dev/null +++ b/e2e/binary/python/python.py @@ -0,0 +1,30 @@ +from __future__ import annotations + +from subprocess import PIPE, run + +from binary import Relative, Tool + + +def test_script(tool: Tool, relative: Relative) -> None: + binary = tool("python") + hello = relative("hello.py") + + cmd = (binary, hello) + r = run(cmd, check=True, timeout=30, stdout=PIPE, text=True) + + assert 0 == r.returncode + assert "Hello!" == r.stdout + + +def test_command(tool: Tool) -> None: + binary = tool("python") + + cmd = ( + binary, + "-c", + "print('Hello!', end='')", + ) + r = run(cmd, check=True, timeout=30, stdout=PIPE, text=True) + + assert 0 == r.returncode + assert "Hello!" == r.stdout diff --git a/e2e/binary/tidy/BUILD.bazel b/e2e/binary/tidy/BUILD.bazel index 53c8ad35d07a4863aad274684e4b409a578941ba..34cd32d4b2b65552f5630aa6da4cc3529d3227ed 100644 --- a/e2e/binary/tidy/BUILD.bazel +++ b/e2e/binary/tidy/BUILD.bazel @@ -1,11 +1,34 @@ -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 `tidy` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["pretty.py"], + data = [ + "config.txt", + "expected.txt", + "fixture.txt", + "@ape//ape:tidy", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "tidy", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:tidy"], + src = "@ape//ape:tidy", + args = ["--version"], + visibility = ["//:__subpackages__"], +) + +test_suite( + name = "tidy", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/tidy/config.txt b/e2e/binary/tidy/config.txt new file mode 100644 index 0000000000000000000000000000000000000000..9a5e5c65cf49e04a4cb1d4eaf47b569b7ac0e2ba --- /dev/null +++ b/e2e/binary/tidy/config.txt @@ -0,0 +1,6 @@ +indent: auto +indent-spaces: 2 +quiet: no +tidy-mark: no +output-html: yes +drop-empty-elements: no diff --git a/e2e/binary/tidy/expected.txt b/e2e/binary/tidy/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..28b3bd8132bc240c0b77c8598048812025466b58 --- /dev/null +++ b/e2e/binary/tidy/expected.txt @@ -0,0 +1,7 @@ + + + +HTML Tidy + +

+ diff --git a/e2e/binary/tidy/fixture.txt b/e2e/binary/tidy/fixture.txt new file mode 100644 index 0000000000000000000000000000000000000000..faad8aad7bcad6d501f59ee04122ba95bb2277ec --- /dev/null +++ b/e2e/binary/tidy/fixture.txt @@ -0,0 +1,4 @@ + +HTML Tidy + + diff --git a/e2e/binary/tidy/pretty.py b/e2e/binary/tidy/pretty.py new file mode 100644 index 0000000000000000000000000000000000000000..48211cb8a00c9ee665e1e72bcd75f675782720ed --- /dev/null +++ b/e2e/binary/tidy/pretty.py @@ -0,0 +1,26 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run + +from binary import Diff, Relative, Tool + + +def test_tidy(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("tidy") + fixture = relative("fixture.txt") + expected = relative("expected.txt") + config = relative("config.txt") + output = tmp_path / "output.txt" + + args = ( + "-config", + config, + fixture, + ) + + cmd = (binary, *args) + with open(output, "w") as stream: + run(cmd, check=True, timeout=30, stdout=stream) + + assert Diff(expected) == Diff(output) diff --git a/e2e/binary/touch/BUILD.bazel b/e2e/binary/touch/BUILD.bazel index 2903f461b6b57b068602396d0fccbafc11ff29c6..206225c3564a89c10342b65cd8a33e965cdd10dc 100644 --- a/e2e/binary/touch/BUILD.bazel +++ b/e2e/binary/touch/BUILD.bazel @@ -1,11 +1,31 @@ -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 `touch` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["touch.py"], + data = [ + "@ape//ape:touch", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "touch", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:touch"], + src = "@ape//ape:touch", + args = ["--version"], + visibility = ["//:__subpackages__"], +) + +test_suite( + name = "touch", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/touch/touch.py b/e2e/binary/touch/touch.py new file mode 100644 index 0000000000000000000000000000000000000000..3c07eed67a901fe65744d9f68265db242cce0ed4 --- /dev/null +++ b/e2e/binary/touch/touch.py @@ -0,0 +1,33 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import PIPE, run + +from binary import Tool + + +def test_touch(tool: Tool, tmp_path: Path) -> None: + binary = tool("touch") + filepath = tmp_path / "touch.txt" + + cmd = (binary, "--date", "Sun, 29 Feb 2004 16:21:42 -0800", filepath) + run(cmd, check=True, timeout=30, stdout=PIPE) + + assert filepath.is_file() + + s = filepath.stat() + + assert s.st_atime == 1078100502 + assert s.st_mtime == 1078100502 + assert s.st_size == 0 + + ctime = s.st_ctime + + cmd = (binary, filepath) + run(cmd, check=True, timeout=30, stdout=PIPE) + + s = filepath.stat() + + assert s.st_ctime >= ctime + assert s.st_atime > 1078100502 + assert s.st_mtime > 1078100502