Make folly's T_CHECK_TIMEOUT/T_CHECK_TIME_LT use SKIP() on failure
[folly.git] / folly / test / FileTest.cpp
index a7e70921dfb92ab64588290c175439af81536f3c..9ee40bbd6de83f263fc16493faf77e5e5655433d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -35,11 +35,11 @@ namespace {
 void expectWouldBlock(ssize_t r) {
   int savedErrno = errno;
   EXPECT_EQ(-1, r);
-  EXPECT_EQ(EAGAIN, savedErrno) << errnoStr(errno);
+  EXPECT_EQ(EAGAIN, savedErrno) << errnoStr(savedErrno);
 }
 void expectOK(ssize_t r) {
   int savedErrno = errno;
-  EXPECT_LE(0, r) << ": errno=" << errnoStr(errno);
+  EXPECT_LE(0, r) << ": errno=" << errnoStr(savedErrno);
 }
 }  // namespace
 
@@ -55,6 +55,15 @@ TEST(File, Simple) {
   }
 }
 
+TEST(File, SimpleStringPiece) {
+  char buf = 'x';
+  File f(StringPiece("/etc/hosts"));
+  EXPECT_NE(-1, f.fd());
+  EXPECT_EQ(1, ::read(f.fd(), &buf, 1));
+  f.close();
+  EXPECT_EQ(-1, f.fd());
+}
+
 TEST(File, OwnsFd) {
   // Wrap a file descriptor, make sure that ownsFd works
   // We'll test that the file descriptor is closed by closing the writing
@@ -147,9 +156,21 @@ TEST(File, Locks) {
   CHECK_ERR(r);
   buf[r] = '\0';
 
-  fs::path helper(buf);
-  helper.remove_filename();
-  helper /= "file_test_lock_helper";
+  // NOTE(agallagher): Our various internal build systems layout built
+  // binaries differently, so the two layouts below.
+  fs::path me(buf);
+  auto helper_basename = "file_test_lock_helper";
+  fs::path helper;
+  if (fs::exists(me.parent_path() / helper_basename)) {
+    helper = me.parent_path() / helper_basename;
+  } else if (fs::exists(
+      me.parent_path().parent_path() / helper_basename / helper_basename)) {
+    helper = me.parent_path().parent_path()
+      / helper_basename / helper_basename;
+  } else {
+    throw std::runtime_error(
+      folly::to<std::string>("cannot find helper ", helper_basename));
+  }
 
   TemporaryFile tempFile;
   File f(tempFile.fd());
@@ -209,4 +230,3 @@ TEST(File, Locks) {
     testLock(SHARED, true);
   }
 }
-