Repository navigation
Expand file tree
/
Copy pathComputerPrograms_UnitTestRunner.h
More file actions
122 lines (89 loc) · 3.29 KB
/
Copy pathComputerPrograms_UnitTestRunner.h
File metadata and controls
122 lines (89 loc) · 3.29 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* Unit Test Runner
*
* From: https://github.com/PokemonAutomation/
*
*/
#ifndef PokemonAutomation_ComputerPrograms_UnitTestRunner_H
#define PokemonAutomation_ComputerPrograms_UnitTestRunner_H
#include <atomic>
#include "Common/Cpp/TestRunners/ParallelUnitTestRunner.h"
#include "Common/Cpp/Options/StaticTextOption.h"
#include "Common/Cpp/Options/EnumDropdownOption.h"
#include "Common/Cpp/Options/StringOption.h"
#include "Common/Cpp/Options/TextEditOption.h"
#include "CommonTools/Options/StringSelectOption.h"
#include "ComputerPrograms/ComputerProgram.h"
namespace PokemonAutomation{
namespace ComputerPrograms{
class UnitTestRunner_Descriptor : public ComputerProgramDescriptor{
public:
UnitTestRunner_Descriptor();
class Stats;
virtual std::unique_ptr<StatsTracker> make_stats() const override;
};
class UnitTestRunner
: public ComputerProgramInstance
, public PokemonAutomation::UnitTestRunner::Listener
, public ConfigOption::Listener
{
public:
using Descriptor = UnitTestRunner_Descriptor;
~UnitTestRunner();
UnitTestRunner();
virtual void program(ProgramEnvironment& env, CancellableScope& scope) override;
private:
virtual void on_config_value_changed(void* object) override;
virtual void on_test_finished(
std::shared_ptr<const UnitTest> test,
UnitTestResult result
) override;
private:
StaticTextOption RESOURCE_LABEL;
StringCell RESOURCE_PATH;
enum class RunMode{
RUN_ONE,
RUN_SUBSTRING_MATCH,
RUN_ALL,
};
EnumDropdownOption<RunMode> RUN_MODE;
StaticTextOption SINGLE_TEST_LABEL;
StringSelectCell SINGLE_TEST;
StaticTextOption SUBSTRING_TEST_LABEL;
StringCell SUBSTRING_TEST;
TextEditOption TESTS_TO_RUN;
TextEditOption PASSED_TESTS;
TextEditOption FAILED_TESTS;
ProgramEnvironment* m_env = nullptr;
std::atomic<uint64_t> m_total_failed;
};
class CommandLineUnitTestRunner : public PokemonAutomation::UnitTestRunner::Listener{
public:
CommandLineUnitTestRunner(Logger& logger)
: m_logger(logger)
, m_skipped_tests(0)
, m_passed_tests(0)
, m_failed_tests(0)
{}
// Run the unit tests. Return true if any test failed.
// If `augment_color_distortions` is true, also run each image test under different color
// distortion augmentation to widen the test coverage, using the distortion data in the
// CaptureCardCalibration/ folder of the test repo. If that data can't be loaded, log the
// error and return true without running any test.
// If `test_substring` is not empty, only run the tests whose name contains that substring
// (case sensitive, the same matching as the GUI's "Run All Tests Containing This Substring"
// mode). If nothing matches, no test runs and a warning is logged.
bool run(bool augment_color_distortions, const std::string& test_substring);
private:
virtual void on_test_finished(
std::shared_ptr<const UnitTest> test,
UnitTestResult result
) override;
private:
Logger& m_logger;
std::atomic<size_t> m_skipped_tests;
std::atomic<size_t> m_passed_tests;
std::atomic<size_t> m_failed_tests;
};
}
}
#endif