There is no guarantee that this environment variable is set. Eg, when running a test outside of the build system, such as under a debugger. And passing a nullptr to the string constructor is undefined. Use an empty string, which seems like it is close to the original intent.
33 lines
1.1 KiB
C++
33 lines
1.1 KiB
C++
//===-- Implementation of the file path generator for bazel ---------------===//
|
|
//
|
|
// 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 "LibcTest.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "src/__support/CPP/string.h"
|
|
#include "src/__support/c_string.h"
|
|
#include "src/__support/macros/config.h"
|
|
|
|
namespace LIBC_NAMESPACE_DECL {
|
|
namespace testing {
|
|
|
|
CString libc_make_test_file_path_func(const char *file_name) {
|
|
// This is the path to the folder bazel wants the test outputs written to.
|
|
const char *UNDECLARED_OUTPUTS_PATH = getenv("TEST_UNDECLARED_OUTPUTS_DIR");
|
|
// Do something sensible if not run under bazel, otherwise this may segfault
|
|
// when constructing the string.
|
|
if (UNDECLARED_OUTPUTS_PATH == nullptr)
|
|
UNDECLARED_OUTPUTS_PATH = "";
|
|
|
|
return cpp::string(UNDECLARED_OUTPUTS_PATH) + file_name;
|
|
}
|
|
|
|
} // namespace testing
|
|
} // namespace LIBC_NAMESPACE_DECL
|