50 lines · c
1//===-- Header selector for libc unittests ----------------------*- 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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_TEST_UNITTEST_TEST_H10#define LLVM_LIBC_TEST_UNITTEST_TEST_H11 12// This macro takes a file name and returns a value implicitly castable to13// a const char*. That const char* is the path to a file with the provided name14// in a directory where the test is allowed to write. By default it writes15// directly to the filename provided, but implementations are allowed to16// redefine it as necessary.17#define libc_make_test_file_path(file_name) (file_name)18 19// The LIBC_COPT_TEST_USE_* macros can select either of two alternate test20// frameworks:21// * gtest, the well-known model for them all22// * zxtest, the gtest workalike subset sometimes used in the Fuchsia build23// The default is to use llvm-libc's own gtest workalike framework.24//25// All the frameworks provide the basic EXPECT_* and ASSERT_* macros that gtest26// does. The wrapper headers below define LIBC_NAMESPACE::testing::Test as the27// base class for test fixture classes. Each also provides a definition of the28// macro LIBC_TEST_HAS_MATCHERS() for use in `#if` conditionals to guard use of29// gmock-style matchers, which zxtest does not support.30 31#if defined(LIBC_COPT_TEST_USE_ZXTEST)32#include "ZxTest.h"33// TODO: Migrate Pigweed to setting LIBC_COPT_TEST_USE_GTEST instead.34#elif defined(LIBC_COPT_TEST_USE_GTEST) || defined(LIBC_COPT_TEST_USE_PIGWEED)35#include "GTest.h"36#else37#include "LibcTest.h"38#endif39 40// Some macro utility to append file names with LIBC_TEST macro's value to be41// used in stdio tests.42#undef STR43#undef EVAL_THEN_STR44#define STR(X) #X45#define EVAL_THEN_STR(X) STR(X)46 47#define APPEND_LIBC_TEST(X) X "." EVAL_THEN_STR(LIBC_TEST)48 49#endif // LLVM_LIBC_TEST_UNITTEST_TEST_H50