Browse Source

Test: Add stderr stream pointer to the test suite

master
Riyyi 3 years ago
parent
commit
ff92522b8c
  1. 6
      test/testdotfile.cpp
  2. 1
      test/testsuite.cpp
  3. 2
      test/testsuite.h

6
test/testdotfile.cpp

@ -4,11 +4,10 @@
* SPDX-License-Identifier: MIT
*/
#include <cstdio>
#include <cstdio> // stderr
#include <filesystem>
#include <string>
#include <unistd.h> // geteuid, setegid, seteuid
#include <utility>
#include <vector>
#include "dotfile.h"
@ -111,7 +110,10 @@ TEST_CASE(AddDotfiles)
TEST_CASE(AddNonExistentDotfiles)
{
stderr = Test::TestSuite::the().outputNull();
Dotfile::the().add({ "/tmp/__non-existent-test-file" });
stderr = Test::TestSuite::the().outputErr();
EXPECT(!std::filesystem::exists("__non-existent-test-file"));
}

1
test/testsuite.cpp

@ -11,6 +11,7 @@ namespace Test {
TestSuite::TestSuite(s)
{
m_outputStd = stdout;
m_outputErr = stderr;
m_outputNull = fopen("/dev/null", "w"); // Windows: nul
}

2
test/testsuite.h

@ -19,11 +19,13 @@ public:
void currentTestCaseFailed() { m_currentTestCasePassed = false; }
FILE* outputStd() const { return m_outputStd; }
FILE* outputErr() const { return m_outputErr; }
FILE* outputNull() const { return m_outputNull; }
private:
bool m_currentTestCasePassed { true };
FILE* m_outputStd { nullptr };
FILE* m_outputErr { nullptr };
FILE* m_outputNull { nullptr };
std::vector<TestCase> m_cases;

Loading…
Cancel
Save