31 Commits
Author SHA1 Message Date
Shannon Booth ebc8829df7 tests: check the result of _wmktemp_s rather than errno
_wmktemp_s reports a failure through its (positive) errno_t return
value, so comparing it against zero from below never caught an error.
2026-08-01 18:50:32 +02:00
Shannon Booth cd41a57bb4 tests: probe fixture files through the test library
Tests reach for the filesystem helpers exported by the patching code to
check that a file exists or to make a directory for a fixture. Route
those checks through helpers in the library the tests already link, so
that the tests do not care how the patching code spells its filesystem
access.

This keeps a later change to those helpers out of every test file.
2026-08-01 18:50:32 +02:00
Shannon Booth e51ad98033 system: make Windows API conversions explicit
Windows reports errors and process metadata with DWORD while the
standard error and test-process interfaces use int. Keep unavoidable
conversions in private Win32 helpers and use explicit casts for the
remaining API boundaries.
2026-08-01 15:33:12 +02:00
Shannon Booth 1f1d6c5a92 tests: make byte conversion explicit in diagnostics
Read strings through their char representation before converting each
value to an unsigned byte. This keeps escaping independent of whether
plain char is signed.
2026-08-01 15:33:12 +02:00
Shannon Booth dd7cd56772 tests: make the poll descriptor count conversion explicit
The process helper polls at most stdout and stderr, so its descriptor
count always fits nfds_t. Express that conversion explicitly instead of
relying on platform specific type widths.
2026-08-01 15:33:12 +02:00
Shannon Booth c68791ca53 tests: avoid relying on system error text
System error messages vary across standard libraries and locales. Make
the test suite portable in such situations.
2026-08-01 13:53:10 +02:00
Shannon Booth 8897bb9e82 tests: create the temporary test directory in the test library
Making a temporary directory is only ever done to give a test somewhere
to run. Keeping it in the library the tests already link means the
patching code does not carry an entry point nothing in it uses.
2026-08-01 12:03:54 +02:00
Shannon Booth 859367ccf8 tests: add skip helper for if symbolic link capability is unavailable
So other tests can easily skip tests under this condition.
2026-08-01 12:03:54 +02:00
Shannon Booth 6a6259c729 tests: declare compatibility per test
GNU comparison was controlled per test executable. That kept process
tests in test_unit from being compared, while enabling comparison there
would also run its unit tests twice.

Introduce COMPAT_TEST for cases that run against both sb_patch and GNU
patch. Keep PATCH_TEST for project-specific behavior and TEST for unit
coverage. Mark stable GNU differences as expected compatibility failures.
Keep host-dependent ed behavior project-only because GNU delegates those
scripts to an external editor.

Merge the normal and conditional PTY tests into one patch_tests runner
now that executable boundaries no longer control GNU comparison. Keep
test_oom separate because it runs patch_oom.
2026-07-25 09:53:53 +02:00
Shannon Booth 970ca705a2 tests: support skipping tests at runtime
Add skip_test(reason), which aborts the running test and reports it as
skipped rather than passed or failed. The single test runner exits with 77
for a skip, and CTest is told via SKIP_RETURN_CODE 77 to mark it skipped.
run_all_tests counts and prints skips separately.

This lets tests that require a capability the environment may lack (such as
creating symbolic links without privilege) opt out cleanly instead of
failing.
2026-07-24 16:58:20 +02:00
Shannon Booth 951a9b2542 tests: improve assertion output to better show whitespace differences 2026-04-05 12:46:57 +02:00
Shannon Booth d9dc72f445 patch: add initial support for quoting-style
We have a really naive implementation for quoting with this initial pass
- but that is to be improved! For now, just begin with the basic
plumbing so that the option exists.
2023-03-18 22:47:33 +13:00
Shannon Booth 72230fabd1 tests: fix failing tests incorrectly passing 2023-03-12 17:29:19 +13:00
Shannon Booth 7b69cff537 cmdline: add support for POSIXLY_CORRECT environment variable
This serves as the alternative way of putting patch into POSIX mode.
2023-03-12 15:44:19 +13:00
Shannon Booth aa5a4dc617 tests: put patch/test.h under a Patch namespace 2023-03-12 15:44:19 +13:00
Shannon Booth 8b150e5fec tests: fix xfail tests passing on an unexpected pass 2023-02-06 16:51:42 +13:00
Shannon Booth 68e08c5d39 tests: add ability for patch specific xfail
This is intended to be used when there is some test case that we are
failing on but other patch programs successfully pass.
2023-02-06 16:51:42 +13:00
Shannon Booth 3c4c9c0920 tests: add ability for expected failure compatibility tests
These are intended to be used when a test is failing in our
compatibility test (due to a bug), but this implementation is working as
expected.
2023-01-30 15:05:02 +13:00
Shannon Booth 287a6cb315 applier: fix --ifdef behaviour on line added and then removed
I was juts trying to add test coverage to this piece of code, and then
realised that the implementation was actually broken for this case! diff
does not seem to really produce diffs that have lines added before
removals, but support this anyway since it's still a valid patch file.
2023-01-21 14:10:24 +13:00
Shannon Booth 06c42617c0 tests: improve assertion result on failure 2023-01-21 14:08:17 +13:00
Shannon Booth a8330de664 patch: fix various compiler warnings
Mostly ones complaining about sign conversion.
2023-01-08 15:35:24 +13:00
Shannon Booth 4654087842 tests: improve error output on a failure to exec on fork
We were not really doing this correctly beforehand. To improve error
output, try and write something to a pipe to indicate an error then
abort so that the process does not return normally.
2023-01-05 13:44:53 +13:00
Shannon Booth 8aad315b2d tests: add some useful output when running tests
Output to stdout the start of the test, the success/fail/disablement of
that test, as well as the time that it takes to run that test.

Furthermore, when running the full test suite, say how many tests are
going to be run, and give a summary at the end with the time taken and
pass/fail.
2023-01-05 13:44:53 +13:00
Shannon Booth bd0045922c cmdline: fix a repeated option in error message for amibiguous cmdline 2023-01-05 13:44:53 +13:00
Shannon Booth 600de4a15b cmdline: adjust and test some error messages on a bad cmdline
Move these closer to what is observed with running the exact same
commandline with GNU patch, and test that we are throwing exceptions
with match the output message.
2023-01-05 13:44:53 +13:00
Shannon Booth 7741f97e6f tests: fix expected failure test cases not failing on a pass
The logic was resulting in them passing no matter what!
2023-01-04 19:26:46 +13:00
Shannon Booth f953e4678e tests: fix EXPECT_THROW macro not asserting on exception not thrown
Which is really the entire point of this macro! Luckily things are not
are not really broken and exceptions are being thrown where expected.
2023-01-04 19:26:46 +13:00
Shannon Booth 063a797955 tests: add an error message when unable to find test
To prevent me from spending as long as I did running the wrong test
binary!
2023-01-04 10:42:35 +13:00
Shannon Booth 6e9e380874 tests: ignore cognitive complexity clang tidy warnings for tests
The complexity is going to be high due to the number of if statement
checks that the tests are asserting. Even ignoring this, we don't really
care about this warnings for tests in the first place.
2023-01-04 10:42:35 +13:00
Shannon Booth da463f3914 tests: align pty_spawn api closer to process class
Which should hopefully make it much easier to use.
2023-01-03 17:28:57 +13:00
Shannon Booth af40b24b12 tests: put test library headers under a patch folder
For much better symmetry with product code.
2022-12-27 14:26:45 -08:00