aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.util/test_capture_stream.cc
blob: 27c8596e1b35c647efa3208be2d0f6982de6a38f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * This source code is released into the public domain.
 */

#include <iostream>

#include <catch2/catch_test_macros.hpp>

import nihil.util;

TEST_CASE("nihil.util: capture", "[nihil][nihil.util]")
{
	SECTION("std::cout with release()") {
		auto cap = nihil::capture_stream(std::cout);

		std::cout << 1 << '+' << 1 << '=' << (1 + 1) << '\n';
		REQUIRE(cap.str() == "1+1=2\n");
		
		cap.release();
		REQUIRE(cap.str() == "1+1=2\n");
	}

	SECTION("std::cout with dtor") {
		auto cap = nihil::capture_stream(std::cout);
		std::cout << 1 << '+' << 1 << '=' << (1 + 1) << '\n';
		REQUIRE(cap.str() == "1+1=2\n");
	}

	SECTION("std::cerr with release()") {
		auto cap = nihil::capture_stream(std::cerr);

		std::cerr << 1 << '+' << 1 << '=' << (1 + 1) << '\n';
		REQUIRE(cap.str() == "1+1=2\n");
		
		cap.release();
		REQUIRE(cap.str() == "1+1=2\n");
	}

	SECTION("std::cerr with dtor") {
		auto cap = nihil::capture_stream(std::cerr);
		std::cerr << 1 << '+' << 1 << '=' << (1 + 1) << '\n';
		REQUIRE(cap.str() == "1+1=2\n");
	}
}