[PATCH] D56149: [sanitizer_common] Rewrite fgets/fputs/puts tests to use asserts

Michał Górny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 29 08:35:36 PST 2018


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;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56149.179692.patch
Type: text/x-patch
Size: 1311 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181229/b23c2d6b/attachment.bin>


More information about the llvm-commits mailing list