33 lines · cpp
1//===-- Unittests for perror ---------------------------------------------===//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#include "src/stdio/perror.h"10 11#include "src/__support/libc_errno.h"12#include "test/UnitTest/Test.h"13 14// The standard says perror prints directly to stderr and returns nothing. This15// makes it rather difficult to test automatically.16 17// TODO: figure out redirecting stderr so this test can check correctness.18TEST(LlvmLibcPerrorTest, PrintOut) {19 LIBC_NAMESPACE::libc_errno = 0;20 constexpr char simple[] = "A simple string";21 LIBC_NAMESPACE::perror(simple);22 23 // stick to stdc errno values, specifically 0, EDOM, ERANGE, and EILSEQ.24 LIBC_NAMESPACE::libc_errno = EDOM;25 LIBC_NAMESPACE::perror("Print this and an error");26 27 LIBC_NAMESPACE::libc_errno = EILSEQ;28 LIBC_NAMESPACE::perror("\0 shouldn't print this.");29 30 LIBC_NAMESPACE::libc_errno = ERANGE;31 LIBC_NAMESPACE::perror(nullptr);32}33