mirror-llvm-project/orc-rt/test/unit/scope_exit-test.cpp
Lang Hames d855251d60
[orc-rt] Move the unit tests into test/unit (#208431)
Move unit tests from orc-rt/unittests into orc-rt/test/unit, completing
the consolidation of the runtime's tests under orc-rt/test (alongside
test/regression and test/tools).
2026-07-09 21:32:26 +10:00

51 lines
1.2 KiB
C++

//===- scope_exit-test.cpp ------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Tests for orc-rt's scope_exit.h APIs.
//
//===----------------------------------------------------------------------===//
#include "orc-rt/scope_exit.h"
#include "gtest/gtest.h"
using namespace orc_rt;
TEST(ScopeExitTest, Noop) {
auto _ = scope_exit([]() {});
}
TEST(ScopeExitTest, OnScopeExit) {
bool ScopeExitRun = false;
{
auto _ = scope_exit([&]() { ScopeExitRun = true; });
EXPECT_FALSE(ScopeExitRun);
}
EXPECT_TRUE(ScopeExitRun);
}
TEST(ScopeExitTest, Release) {
bool ScopeExitRun = false;
{
auto OnExit = scope_exit([&]() { ScopeExitRun = true; });
EXPECT_FALSE(ScopeExitRun);
OnExit.release();
}
EXPECT_FALSE(ScopeExitRun);
}
TEST(ScopeExitTest, MoveOnlyFunctionObject) {
struct MoveOnly {
MoveOnly() = default;
MoveOnly(MoveOnly &&) = default;
void operator()() {}
};
{
auto OnExit = scope_exit(MoveOnly());
}
}