X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fnoerr%2Ftest%2Frun.c;h=48086a24d542e98dccaa33548748850f5d464b83;hb=1fe2fa08d37090fff67edd444dadacd11ff8eebf;hp=6d3c6837cd228b857f3b11ab589dd0f2aa00aca7;hpb=650c775ff00cccd03fc84e7789a03c51d9839004;p=ccan diff --git a/ccan/noerr/test/run.c b/ccan/noerr/test/run.c index 6d3c6837..48086a24 100644 --- a/ccan/noerr/test/run.c +++ b/ccan/noerr/test/run.c @@ -1,6 +1,6 @@ -#include "noerr/noerr.h" -#include "tap/tap.h" -#include "noerr/noerr.c" +#include +#include +#include #include #include #include @@ -9,11 +9,11 @@ int main(int argc, char *argv[]) { - /* tempnam(3) is generally a bad idea, but OK here. */ - char *name = tempnam(NULL, "noerr"); + const char *name = "noerr.file"; int fd; + FILE *fp; - plan_tests(12); + plan_tests(16); /* Should fail to unlink. */ ok1(unlink(name) != 0); ok1(errno == ENOENT); @@ -44,5 +44,24 @@ int main(int argc, char *argv[]) ok1(unlink_noerr(name) == 0); ok1(errno == 100); + /* Test failing fclose */ + fp = fopen(name, "wb"); + assert(fp); + close(fileno(fp)); + ok1(fclose_noerr(fp) == EBADF); + + /* Test successful fclose */ + fp = fopen(name, "wb"); + assert(fp); + + errno = 100; + ok1(fclose_noerr(fp) == 0); + ok1(errno == 100); + unlink(name); + + errno = 101; + free_noerr(malloc(7)); + ok1(errno == 101); + return exit_status(); }