blob: 301942c30bbc743a194902066ecbe3d946426197 [file] [log] [blame]
Tim Shen64afe232016-08-10 17:52:09 +00001//===- llvm/unittest/ADT/ScopeExit.cpp - Scope exit unit tests --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/ADT/ScopeExit.h"
11#include "gtest/gtest.h"
12
13using namespace llvm;
14
15namespace {
16
17TEST(ScopeExitTest, Basic) {
18 struct Callable {
19 bool &Called;
20 Callable(bool &Called) : Called(Called) {}
21 Callable(Callable &&RHS) : Called(RHS.Called) {}
22 void operator()() { Called = true; }
23 };
24 bool Called = false;
25 {
26 auto g = make_scope_exit(Callable(Called));
27 EXPECT_FALSE(Called);
28 }
29 EXPECT_TRUE(Called);
30}
31
32} // end anonymous namespace