FLANG
testing.h
1//===-- include/flang/Testing/testing.h -------------------------*- C++ -*-===//
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef FORTRAN_TESTING_TESTING_H_
10#define FORTRAN_TESTING_TESTING_H_
11
12#include <cinttypes>
13#include <string>
14
15namespace testing {
16
17// Returns EXIT_SUCCESS or EXIT_FAILURE, so a test's main() should end
18// with "return testing::Complete()".
19int Complete();
20
21// Pass/fail testing. These macros return a pointer to a printf-like
22// function that can be optionally called to print more detail, e.g.
23// COMPARE(x, ==, y)("z is 0x%llx", z);
24// will also print z after the usual failure message if x != y.
25#define TEST(predicate) \
26 testing::Test(__FILE__, __LINE__, #predicate, (predicate))
27#define MATCH(want, got) testing::Match(__FILE__, __LINE__, (want), #got, (got))
28#define COMPARE(x, rel, y) \
29 testing::Compare(__FILE__, __LINE__, #x, #rel, #y, (x), (y))
30
31// Functions called by these macros; do not call directly.
32using FailureDetailPrinter = void (*)(const char *, ...);
33FailureDetailPrinter Test(
34 const char *file, int line, const char *predicate, bool pass);
35FailureDetailPrinter Match(const char *file, int line, std::uint64_t want,
36 const char *gots, std::uint64_t got);
37FailureDetailPrinter Match(const char *file, int line, const char *want,
38 const char *gots, const std::string &got);
39FailureDetailPrinter Match(const char *file, int line, const std::string &want,
40 const char *gots, const std::string &got);
41FailureDetailPrinter Compare(const char *file, int line, const char *xs,
42 const char *rel, const char *ys, std::uint64_t x, std::uint64_t y);
43} // namespace testing
44#endif // FORTRAN_TESTING_TESTING_H_