/
githubmirror
/
carbon-lang
Обзор
Документация
Войти
/
githubmirror
/
carbon-lang
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
testing/base/capture_std_streams.h
37 строк
1 KB
Jon Ross-Perkins
Add missing trailing return types (#5006)
25 фев 2025, 01:41
Не верифицирован
25 фев 2025, 01:41
21252b5
Код
Авторство
О чём код?
// 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_