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.
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.
Read strings through their char representation before converting each
value to an unsigned byte. This keeps escaping independent of whether
plain char is signed.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.