mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 06:40:11 +01:00
`-Wunused-template` was added to `-Wunused`, so clean up the things it found. One of them was a bug in the Clang warning that I've worked around and reported upstream: https://github.com/llvm/llvm-project/issues/218429
38 lines
1.3 KiB
C++
38 lines
1.3 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef CARBON_TESTING_BASE_CAPTURE_STD_STREAMS_H_
|
|
#define CARBON_TESTING_BASE_CAPTURE_STD_STREAMS_H_
|
|
|
|
#include <string>
|
|
|
|
namespace Carbon::Testing {
|
|
|
|
// Implementation details.
|
|
namespace Internal {
|
|
auto BeginStdStreamCapture() -> void;
|
|
auto EndStdStreamCapture(std::string& out, std::string& err) -> void;
|
|
} // namespace Internal
|
|
|
|
// Calls the provided function while capturing both `stdout` and `stderr`. The
|
|
// `out` and `err` strings are set to whatever is captured after the function
|
|
// returns.
|
|
//
|
|
// Note that any output that is captured will not be visible when running, which
|
|
// can make debugging tests that use this routine difficult. Make sure to either
|
|
// print back out or otherwise expose any of the contents of the captured output
|
|
// that are needed when debugging.
|
|
template <typename FnT>
|
|
auto CallWithCapturedOutput(std::string& out, std::string& err, FnT function)
|
|
-> auto {
|
|
Internal::BeginStdStreamCapture();
|
|
auto result = function();
|
|
Internal::EndStdStreamCapture(out, err);
|
|
return result;
|
|
}
|
|
|
|
} // namespace Carbon::Testing
|
|
|
|
#endif // CARBON_TESTING_BASE_CAPTURE_STD_STREAMS_H_
|