mgorny created this revision. mgorny added reviewers: krytarowski, vitalybuka. Herald added subscribers: Sanitizers, llvm-commits, kubamracek.
Rewrite the tests for fgets and for fputs/puts to verify results using assert instead of silently returning non-zero exit status. This is based on requests made in review of D56136 <https://reviews.llvm.org/D56136>. Repository: rCRT Compiler Runtime https://reviews.llvm.org/D56149 Files: test/sanitizer_common/TestCases/Posix/fgets.cc test/sanitizer_common/TestCases/Posix/fputs_puts.cc 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/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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits