]> git.ozlabs.org Git - ccan/blobdiff - ccan/noerr/test/run.c
noerr: don't use tempnam
[ccan] / ccan / noerr / test / run.c
index 6d3c6837cd228b857f3b11ab589dd0f2aa00aca7..503ba81c52fe74e3f48b2a40d54bb9288e9b9d71 100644 (file)
@@ -1,6 +1,6 @@
-#include "noerr/noerr.h"
-#include "tap/tap.h"
-#include "noerr/noerr.c"
+#include <ccan/noerr/noerr.h>
+#include <ccan/tap/tap.h>
+#include <ccan/noerr/noerr.c>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -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");
+       char *name = "noerr.file";
        int fd;
+       FILE *fp;
 
-       plan_tests(12);
+       plan_tests(15);
        /* Should fail to unlink. */
        ok1(unlink(name) != 0);
        ok1(errno == ENOENT);
@@ -44,5 +44,20 @@ 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);
+
        return exit_status();
 }