brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 411bb4f Raw
52 lines · cpp
1//===- ScopeExitTest.cpp --------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// Tests for orc-rt's ScopeExit.h APIs.10//11//===----------------------------------------------------------------------===//12 13#include "orc-rt/ScopeExit.h"14#include "gtest/gtest.h"15 16using namespace orc_rt;17 18TEST(ScopeExitTest, Noop) {19  auto _ = make_scope_exit([]() {});20}21 22TEST(ScopeExitTest, OnScopeExit) {23  bool ScopeExitRun = false;24  {25    auto _ = make_scope_exit([&]() { ScopeExitRun = true; });26    EXPECT_FALSE(ScopeExitRun);27  }28  EXPECT_TRUE(ScopeExitRun);29}30 31TEST(ScopeExitTest, Release) {32  bool ScopeExitRun = false;33  {34    auto OnExit = make_scope_exit([&]() { ScopeExitRun = true; });35    EXPECT_FALSE(ScopeExitRun);36    OnExit.release();37  }38  EXPECT_FALSE(ScopeExitRun);39}40 41TEST(ScopeExitTest, MoveOnlyFunctionObject) {42  struct MoveOnly {43    MoveOnly() = default;44    MoveOnly(MoveOnly &&) = default;45    void operator()() {}46  };47 48  {49    auto OnExit = make_scope_exit(MoveOnly());50  }51}52