It was several lines repeated each time, and it saves having to check
they're all identical. The original test pressed on if the MIME
parameter's value was an empty string; preserve that as it's spotted
later on.
David Levine [Sun, 13 Nov 2016 19:50:08 +0000 (14:50 -0500)]
Replaced docs/COMPLETION-BASH with etc/bash_completions_nmh.
It's generated from man/mh-chart.man, which in turn is generated.
Automake doesn't like generated files in docs, hence the move to
etc. And the new filename better fits usage, I think.
Did not provide support for completing message numbers. It can
be fooled by programs that take multiple switches with +
arguments.
COMPLETION-BASH was broken with current bash, anyway.
Ralph Corderoy [Sat, 12 Nov 2016 18:40:46 +0000 (18:40 +0000)]
m_getfld: Shuffle `delim' assignments slightly.
Document end state of the four pointers to parts of the delimiter.
fdelimlen can be, wrongly, one less without causing problems because a
second check uses edelimlen. The only side effect is an extra iteration
through m_getfld().
Ralph Corderoy [Sat, 12 Nov 2016 00:39:23 +0000 (00:39 +0000)]
m_getfld: Replace matchc() with memmem(3).
libc is more likely to find one lump of memory inside another quicker
than a home-grown quadratic emulation of the VAX's MATCHC instruction.
memmem() isn't POSIX, but exists on Linux and FreeBSD. This will see if
the buildbot is happy.
Ralph Corderoy [Sat, 12 Nov 2016 00:31:36 +0000 (00:31 +0000)]
m_getfld: Remove never-true test in matchc().
Now the fdelimlen doesn't include the NUL it is never true. I didn't
understand how it could ever be true but gcov on the test suite was
showing 22e6 tests had three positives; that's what put me on to
fdelimlen's overshoot.
Ralph Corderoy [Fri, 11 Nov 2016 23:23:11 +0000 (23:23 +0000)]
m_getfld: Shorten fdelimlen by one; it was too long.
The fdelimlen bytes starting at fdelim included a NUL at the end, e.g. 7
for "\nFrom \0". Other code seems not to expect this and has
conditional bits to work around it, perhaps without understanding why.
All the tests still pass, including with valgrind.
Ralph Corderoy [Fri, 11 Nov 2016 00:38:29 +0000 (00:38 +0000)]
dlocaltime(): Only call tzset(3) once.
This avoids the stat(2) of /etc/localtime per message scan if TZ isn't
set in the environment; that's the default case on this Linux system.
I can't see a way the TZ environment variable is likely to change
between messages, or that it's intended an invocation of scan(1), say,
copes with the timezone shifting underneath it by /etc/localtime being
changed.
Ralph Corderoy [Tue, 1 Nov 2016 11:11:11 +0000 (11:11 +0000)]
test: Remove the " # gcov" comment from check_exit calls.
Now the command is passed to check_exit, that is sufficient to indicate
it's for coverage uses only, and a candidate to be fleshed out into a
test that checks the output.
Ralph Corderoy [Tue, 1 Nov 2016 00:05:42 +0000 (00:05 +0000)]
anno: Stop segmentation violation on `-number 0'.
If atoi(3) returned zero, either because `0' was given or the number
could not be parsed, then the error message dereferenced an invalid
pointer. Found when trying to increase coverage with check_exit.
The tests aren't getting 100% coverage and the nested assignments make
it harder to see what's happening, and what needs to happen to gain
coverage. Hoist invariants so it's clear they're such to the reader and
not just the compiler.
Ralph Corderoy [Mon, 31 Oct 2016 17:18:11 +0000 (17:18 +0000)]
test/common.sh.in: Add test_exit() for $? checking.
The stdout and stderr of the command being tested are saved but ignored,
only regurgitated if the test fails. The test is stated as a fragment
of a test(1) condition, e.g. '-eq 1'. This is mainly intended for the
quick one-liners to increase gcov coverage and thus valgrind's scope.
Over time, better tests that check more of the command's behaviour can
replace these, keeping the coverage level.
Ralph Corderoy [Sun, 30 Oct 2016 20:41:29 +0000 (20:41 +0000)]
Get coverage of quite a few of the `ambiguous switch' case.
Typically by adding a `foo -', discarding stdout and stderr, and
expecting it to exit non-zero. A `# gcov' comment states its purpose,
and makes it easier to see if they can be deleted in time as other
coverage tests improve.
Ralph Corderoy [Sun, 30 Oct 2016 13:45:40 +0000 (13:45 +0000)]
Add trunccpy(), and the convenience TRUNCCPY().
truncpy copies at most size - 1 chars from non-NULL src to non-NULL
dst, and ensures dst is NUL terminated. If size is zero then it
aborts as dst cannot be NUL terminated.
It's to be used when truncation is intended and correct, e.g.
reporting a possibly very long external string back to the user. One
of its advantages over strncpy(3) is it doesn't pad in the common
case of no truncation.
Ralph Corderoy [Sat, 29 Oct 2016 23:03:34 +0000 (00:03 +0100)]
Fix test-header-parsing test script.
It was using sh's backticks that chomped the last linefeed!
Add comment referencing the commit that fixed the code this is testing.
Have fewer test cases, sticking to just one or two character headers
with empty or one-character bodies. Avoids slowing the tests too much
and the fixed bug was to do with hashing one-character headers.