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

1
test/testsuite.cpp

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

2
test/testsuite.h

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

Loading…
Cancel
Save