<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Mon, Aug 8, 2016 at 6:53 PM Tim Shen <<a href="mailto:timshen@google.com">timshen@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">timshen added inline comments.<br>
<br>
================<br>
Comment at: unittests/ADT/ScopeExitTest.cpp:21-31<br>
@@ +20,13 @@<br>
+TEST(ScopeExitTest, Copy) {<br>
+  std::vector<int> v;<br>
+  const auto f = [&](int counter) {<br>
+    return [&v, counter] { v.push_back(counter); };<br>
+  };<br>
+  {<br>
+    auto g1 = make_scope_exit(f(0));<br>
+    { auto g2 = make_scope_exit(f(1)); }<br>
+    auto g3 = make_scope_exit(f(2));<br>
+    EXPECT_EQ((std::vector<int>{1}), v);<br>
+  }<br>
+  EXPECT_EQ((std::vector<int>{1, 2, 0}), v);<br>
+}<br>
----------------<br>
dblaikie wrote:<br>
> This test seems a bit complicated - lambdas producing lambdas, a std::vector, etc.<br>
><br>
> What are the actual behaviors you're trying to test here?<br>
Sorry, if std::vector raises surprises, it's a mistake. Changed to SmallVector.<br></blockquote><div><br></div><div>Oh, sorry, no - it's not the difference between std::vector and SmallVector. It's the existence of a vector at all in a test for a scope device like this. It seems like more work than I'd expect to need.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I'd like to test the order of the scope_exit runs. I label each scope_exit with a number (x for make_scope_exit(f(x))), and when the scope exits, the label is pushed to the vector "v". Then I inspect v to make sure of the order of labels.<span style="line-height:1.5"> </span></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Do you have any suggestions to make it simpler?<br></blockquote><div><br></div><div>I'm trying to understand why testing 3 of them gives greater coverage than testing one. They're rather orthogonal & I would expect something like this:<br><br>TEST(ScopeExitTest, Basic) {</div><div>  bool Called = false;<br>  {<br>    auto g1 = make_scope_exit([&] { Called = true; });<br>    EXPECT_FALSE(Called);<br>  }<br>  EXPECT_TRUE(Called);<br>}<br><br>would suffice.<br><br>(also, none of these necessarily test the copy (or move - I assume this isn't actually copyable?) support of the type, due to NRVO possibly)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
================<br>
Comment at: unittests/ADT/ScopeExitTest.cpp:37<br>
@@ +36,3 @@<br>
+  std::function<void()> f([&succ] { succ = true; });<br>
+  ASSERT_TRUE(static_cast<bool>(f));<br>
+  {<br>
----------------<br>
dblaikie wrote:<br>
> I take it this static cast is needed for some reason? (but isn't needed for EXPECT_FALSE?)<br>
Yes, otherwise it doesn't compile - it's something to do with ASSERT.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D22796" rel="noreferrer" target="_blank">https://reviews.llvm.org/D22796</a><br>
<br>
<br>
<br>
</blockquote></div></div>