mgorny updated this revision to Diff 179693.
mgorny retitled this revision from "[sanitizer_common] Rewrite fgets/fputs/puts
tests to use asserts" to "[sanitizer_common] Rewrite more Posix tests to use
asserts".
mgorny edited the summary of this revision.
mgorny added a comment.
Updated to cover functions which used `exit(1)` too.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56149/new/
https://reviews.llvm.org/D56149
Files:
test/sanitizer_common/TestCases/Posix/devname.cc
test/sanitizer_common/TestCases/Posix/devname_r.cc
test/sanitizer_common/TestCases/Posix/fgetln.cc
test/sanitizer_common/TestCases/Posix/fgets.cc
test/sanitizer_common/TestCases/Posix/fputs_puts.cc
test/sanitizer_common/TestCases/Posix/lstat.cc
Index: test/sanitizer_common/TestCases/Posix/lstat.cc
===================================================================
--- test/sanitizer_common/TestCases/Posix/lstat.cc
+++ test/sanitizer_common/TestCases/Posix/lstat.cc
@@ -1,16 +1,14 @@
// RUN: %clangxx -O0 -g %s -o %t && %run %t
+#include <assert.h>
#include <stdlib.h>
#include <sys/stat.h>
int main(void) {
struct stat st;
- if (lstat("/dev/null", &st))
- exit(1);
-
- if (!S_ISCHR(st.st_mode))
- exit(1);
+ assert(!lstat("/dev/null", &st));
+ assert(S_ISCHR(st.st_mode));
return 0;
}
Index: test/sanitizer_common/TestCases/Posix/fputs_puts.cc
===================================================================
--- test/sanitizer_common/TestCases/Posix/fputs_puts.cc
+++ test/sanitizer_common/TestCases/Posix/fputs_puts.cc
@@ -1,18 +1,12 @@
// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
// CHECK: {{^foobar$}}
+#include <assert.h>
#include <stdio.h>
int main(void) {
- int r;
-
- r = fputs("foo", stdout);
- if (r < 0)
- return 1;
-
- r = puts("bar");
- if (r < 0)
- return 1;
+ assert(fputs("foo", stdout) >= 0);
+ assert(puts("bar") >= 0);
return 0;
}
Index: test/sanitizer_common/TestCases/Posix/fgets.cc
===================================================================
--- test/sanitizer_common/TestCases/Posix/fgets.cc
+++ test/sanitizer_common/TestCases/Posix/fgets.cc
@@ -1,20 +1,16 @@
// RUN: %clangxx -g %s -o %t && %run %t
+#include <assert.h>
#include <stdio.h>
int main(int argc, char **argv) {
- FILE *fp;
- char buf[2];
- char *s;
-
- fp = fopen(argv[0], "r");
- if (!fp)
- return 1;
+ FILE *fp = fopen(argv[0], "r");
+ assert(fp);
- s = fgets(buf, sizeof(buf), fp);
- if (!s)
- return 2;
+ char buf[2];
+ char *s = fgets(buf, sizeof(buf), fp);
+ assert(s);
- fclose(fp);
+ assert(!fclose(fp));
return 0;
}
Index: test/sanitizer_common/TestCases/Posix/fgetln.cc
===================================================================
--- test/sanitizer_common/TestCases/Posix/fgetln.cc
+++ test/sanitizer_common/TestCases/Posix/fgetln.cc
@@ -1,24 +1,20 @@
// RUN: %clangxx -O0 -g %s -o %t && %run %t
// UNSUPPORTED: linux
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
- FILE *fp;
- size_t len;
- char *s;
-
- fp = fopen("/etc/hosts", "r");
- if (!fp)
- exit(1);
+ FILE *fp = fopen("/etc/hosts", "r");
+ assert(fp);
- s = fgetln(fp, &len);
+ size_t len;
+ char *s = fgetln(fp, &len);
printf("%.*s\n", (int)len, s);
- if (fclose(fp) == EOF)
- exit(1);
+ assert(!fclose(fp));
return 0;
}
Index: test/sanitizer_common/TestCases/Posix/devname_r.cc
===================================================================
--- test/sanitizer_common/TestCases/Posix/devname_r.cc
+++ test/sanitizer_common/TestCases/Posix/devname_r.cc
@@ -4,6 +4,7 @@
#include <sys/cdefs.h>
#include <sys/stat.h>
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
@@ -12,17 +13,14 @@
char name[100];
mode_t type;
- if (stat("/dev/null", &st))
- exit(1);
+ assert(!stat("/dev/null", &st));
type = S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK;
#if defined(__NetBSD__)
- if (devname_r(st.st_rdev, type, name, sizeof(name)))
- exit(1);
+ assert(!devname_r(st.st_rdev, type, name, sizeof(name)));
#else
- if (!devname_r(st.st_rdev, type, name, sizeof(name)))
- exit(1);
+ assert(devname_r(st.st_rdev, type, name, sizeof(name)));
#endif
printf("%s\n", name);
Index: test/sanitizer_common/TestCases/Posix/devname.cc
===================================================================
--- test/sanitizer_common/TestCases/Posix/devname.cc
+++ test/sanitizer_common/TestCases/Posix/devname.cc
@@ -1,6 +1,7 @@
// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
// UNSUPPORTED: linux, solaris
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
@@ -9,11 +10,8 @@
struct stat st;
char *name;
- if (stat("/dev/null", &st))
- exit(1);
-
- if (!(name = devname(st.st_rdev, S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK)))
- exit(1);
+ assert(!stat("/dev/null", &st));
+ assert((name = devname(st.st_rdev, S_ISCHR(st.st_mode) ? S_IFCHR : S_IFBLK)));
printf("%s\n", name);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits