Hi Mattias! On Wed, Jul 11, 2018 at 09:39:23PM +0200, Mattias Andrée wrote: > The following utilities are tested: > - basename(1) > - dirname(1) > - echo(1) > - false(1) > - link(1) > - printenv(1) > - sleep(1) > - test(1) > - time(1) > - true(1) > - tty(1) > - uname(1) > - unexpand(1) > - unlink(1) > - whoami(1) > - yes(1) > > Some tests contain "#ifdef TODO", these tests current > fail, but there are patches submitted for most of them. > There are not patches submitted for fixing the > "#ifdef TODO"s in expand.test.c and unexpand.test.c. > > Signed-off-by: Mattias Andrée <[email protected]>
Sorry for not getting around to looking at this earlier.
I definitely think we should have unit tests for sbase (and other
projects?) as soon as possible. What concerns me with your approach is
that we have about 700 lines of C code in testing-common.{c,h} of which
I feel quite a bit could be dropped.
I have written some (crappy and probably non-portable) shell script
functions to check the stdout and stderr of a process. It's about 40
lines. I also converted your tests for dirname to use these functions
(both files attached. The test coverage is not exactly the same but
relatively similar).
I wonder if we couldn't use some cleaned-up version of the shell script
functions for the easy test cases that only check stdout and stderr
output and your custom C code for the more specialised test cases (like
'tty').
What do you think?
Cheers,
Silvan
> ---
> Makefile | 45 ++++-
> basename.test.c | 68 +++++++
> dirname.test.c | 55 ++++++
> echo.test.c | 51 ++++++
> expand.test.c | 92 ++++++++++
> false.test.c | 32 ++++
> link.test.c | 58 ++++++
> printenv.test.c | 79 ++++++++
> sleep.test.c | 53 ++++++
> test-common.c | 560
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> test-common.h | 219 ++++++++++++++++++++++
> test.test.c | 408 +++++++++++++++++++++++++++++++++++++++++
> time.test.c | 218 ++++++++++++++++++++++
> true.test.c | 31 ++++
> tty.test.c | 44 +++++
> uname.test.c | 283 ++++++++++++++++++++++++++++
> unexpand.test.c | 97 ++++++++++
> unlink.test.c | 56 ++++++
> whoami.test.c | 38 ++++
> yes.test.c | 131 +++++++++++++
> 20 files changed, 2614 insertions(+), 4 deletions(-)
>
> [snip]
test-common.sh
Description: Bourne shell script
#! /bin/sh source ./test-common.sh # "test name" "command to execute" "expected output" check_stdout "dirname-noarg" "./dirname" "" && \ check_stderr "dirname-noarg-stderr" "./dirname" "usage: ./dirname path\n" && \ check_stdout "dirname-non-existing" "./dirname a b c" "" && \ check_stdout "dirname-slash" "./dirname /" "/\n" && \ check_stdout "dirname-dashes-slash" "./dirname -- /" "/\n" && \ check_stdout "dirname-dashes-slash-a" "./dirname -- /a" "/\n" && \ check_stdout "dirname-doublequotes" "./dirname \"\"" ".\n" && \ check_stdout "dirname-slashes" "./dirname ///" "/\n" && \ check_stdout "dirname-a/b" "./dirname a/b" "a\n" && \ check_stdout "dirname-a/b/" "./dirname a/b/" "a\n" && \ check_stdout "dirname-a/b//" "./dirname a/b//" "a\n" && \ check_stdout "dirname-a" "./dirname a" ".\n" && \ check_stdout "dirname-a/" "./dirname a/" ".\n" && \ check_stdout "dirname-/a/b/c" "./dirname /a/b/c" "/a/b\n" && \ check_stdout "dirname-//a/b/c" "./dirname //a/b/c" "//a/b\n"
