llvm/llvm/unittests/ADT/FallibleIteratorTest.cpp

//===- unittests/ADT/FallibleIteratorTest.cpp - fallible_iterator.h tests -===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "llvm/ADT/fallible_iterator.h"
#include "llvm/Testing/Support/Error.h"

#include "gtest/gtest-spi.h"
#include "gtest/gtest.h"

#include <utility>
#include <vector>

usingnamespacellvm;

namespace {

using ItemValid = enum {};
using LinkValid = enum {};

class Item {};

// A utility to mock "bad collections". It supports both invalid items,
// where the dereference operator may return an Error, and bad links
// where the inc/dec operations may return an Error.
// Each element of the mock collection contains a pair of a (possibly broken)
// item and link.
FallibleCollection;

class FallibleCollectionWalker {};

class FallibleCollectionWalkerWithStructDeref
    : public FallibleCollectionWalker {};

class FallibleCollectionWalkerWithFallibleDeref
    : public FallibleCollectionWalker {};

TEST(FallibleIteratorTest, BasicSuccess) {}

TEST(FallibleIteratorTest, BasicFailure) {}

TEST(FallibleIteratorTest, NoRedundantErrorCheckOnEarlyExit) {}

#if LLVM_ENABLE_ABI_BREAKING_CHECKS
TEST(FallibleIteratorTest, RegularLoopExitRequiresErrorCheck) {

  // Check that Err must be checked after a normal (i.e. not early) loop exit
  // by failing to check and expecting program death (due to the unchecked
  // error).

  EXPECT_DEATH(
      {
        FallibleCollection C({{ValidItem, ValidLink}, {ValidItem, ValidLink}});

        FallibleCollectionWalker begin(C, 0);
        FallibleCollectionWalker end(C, 2);

        Error Err = Error::success();
        for (auto &Elem :
             make_fallible_range<FallibleCollectionWalker>(begin, end, Err))
          (void)Elem;
      },
      "Program aborted due to an unhandled Error:")
      << "Normal (i.e. not early) loop exit should require an error check";
}
#endif

TEST(FallibleIteratorTest, RawIncrementAndDecrementBehavior) {}

TEST(FallibleIteratorTest, CheckStructDerefOperatorSupport) {}

TEST(FallibleIteratorTest, CheckDerefToExpectedSupport) {}

} // namespace