mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:10:12 +01:00
Noted CopyNameFromImportIR while glancing around (this one's interesting because it's NameId, not void nor auto), did a scan just for a few other cases. Not an exhaustive fix, and TBH assuming we'd prefer `auto ... -> auto` since equivalent Carbon syntax would probably be `fn ... -> auto`
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>
|
|
static 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_
|