proxygen
TestUtils.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
10 #pragma once
11 
12 #include <folly/Random.h>
13 #include <folly/Range.h>
14 #include <folly/io/IOBuf.h>
15 #include <folly/io/Cursor.h>
17 
18 #ifndef NDEBUG
19 #define EXPECT_DEATH_NO_CORE(token, regex) { \
20  rlimit oldLim; \
21  getrlimit(RLIMIT_CORE, &oldLim); \
22  rlimit newLim{0, oldLim.rlim_max}; \
23  setrlimit(RLIMIT_CORE, &newLim); \
24  EXPECT_DEATH(token, regex); \
25  setrlimit(RLIMIT_CORE, &oldLim); \
26  }
27 #else
28 #define EXPECT_DEATH_NO_CORE(tken, regex) {}
29 #endif
30 
31 
32 inline folly::StringPiece
34  auto pos = folly::rfind(input, '/');
35  if (pos == std::string::npos) {
36  pos = 0;
37  } else {
38  pos += 1;
39  }
40  return input.subpiece(0, pos);
41 }
size_t rfind(const Range< Iter > &haystack, const typename Range< Iter >::value_type &needle)
Definition: Range.h:1404
Range subpiece(size_type first, size_type length=npos) const
Definition: Range.h:686
folly::StringPiece getContainingDirectory(folly::StringPiece input)
Definition: TestUtils.h:33