blob: 66c50f69e6fbb1edc93e879baca1509919875fb2 [file] [edit]
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Unittests for execlp.
///
//===----------------------------------------------------------------------===//
#include "hdr/errno_macros.h"
#include "src/unistd/execlp.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
using LlvmLibcExeclpTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
TEST_F(LlvmLibcExeclpTest, NonExistentFile) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
ASSERT_THAT(LIBC_NAMESPACE::execlp("nonexistent_binary_xyz_123",
"nonexistent_binary_xyz_123", nullptr),
Fails(ENOENT));
}
TEST_F(LlvmLibcExeclpTest, NonExistentPathWithSlash) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
ASSERT_THAT(LIBC_NAMESPACE::execlp("/nonexistent/path/xyz", "xyz", nullptr),
Fails(ENOENT));
}
TEST_F(LlvmLibcExeclpTest, EmptyFileName) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
ASSERT_THAT(LIBC_NAMESPACE::execlp("", "", nullptr), Fails(ENOENT));
}