yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
a68e2635c
master
1// test-reporter.h 2 3#ifndef TEST_REPORTER_H_INCLUDED 4#define TEST_REPORTER_H_INCLUDED 5 6#include "../../source/core/slang-dictionary.h" 7#include "../../source/core/slang-platform.h" 8#include "../../source/core/slang-std-writers.h" 9#include "../../source/core/slang-string-util.h" 10#include "unit-test/slang-unit-test.h" 11 12#include <mutex> 13 14// Forward declaration 15enum class VerbosityLevel ; 16 17enum class TestOutputMode 18{ 19Default = 0 ,///< Default mode is to write test results to the console 20AppVeyor ,///< For AppVeyor continuous integration 21Travis ,///< We currently don't specialize for Travis, but maybe we should. 22XUnit ,///< xUnit original format https://nose.readthedocs.io/en/latest/plugins/xunit.html 23XUnit2 ,///< https://xunit.github.io/docs/format-xml-v2 24TeamCity ,///< Output suitable for teamcity 25}; 26 27class TestReporter :public ITestReporter 28{ 29public : 30struct TestInfo 31 { 32TestResult testResult = TestResult ::Ignored ; 33Slang ::String name ; 34Slang ::String message ;///< Message that is specific for the testResult 35double executionTime = 0.0 ;///< <= 0.0 if not defined. Time is in seconds. 36 }; 37 38class TestScope 39{ 40public : 41TestScope (TestReporter * reporter, const Slang::String & testName) 42: m_reporter( reporter ) 43{ 44reporter -> startTest (testName. getBuffer ()); 45} 46~ TestScope () { m_reporter -> endTest (); } 47 48protected : 49TestReporter * m_reporter; 50}; 51 52class SuiteScope 53{ 54public : 55SuiteScope (TestReporter * reporter, const Slang::String & suiteName) 56: m_reporter( reporter ) 57{ 58reporter -> startSuite (suiteName); 59} 60~ SuiteScope () { m_reporter -> endSuite (); } 61 62protected : 63TestReporter * m_reporter; 64}; 65 66void startSuite ( const Slang ::String & name); 67void endSuite (); 68 69TestResult adjustResult ( Slang ::UnownedStringSlice testName, TestResult result); 70 71virtual SLANG_NO_THROW void SLANG_MCALL startTest ( const char * testName) override; 72virtual SLANG_NO_THROW void SLANG_MCALL addResult ( TestResult result) override; 73virtual SLANG_NO_THROW void SLANG_MCALL addResultWithLocation ( 74TestResult result, 75const char * testText, 76const char * file, 77int line) override; 78virtual SLANG_NO_THROW void SLANG_MCALL addResultWithLocation ( 79bool testSucceeded, 80const char * testText, 81const char * file, 82int line) override; 83virtual SLANG_NO_THROW void SLANG_MCALL addExecutionTime ( double time) override; 84virtual SLANG_NO_THROW void SLANG_MCALL endTest () override ; 85 86/// Runs start/endTest and outputs the result 87TestResult addTest ( const Slang ::String & testName, bool isPass); 88/// Effectively runs start/endTest (so cannot be called inside start/endTest). 89void addTest ( const Slang ::String & testName, TestResult testResult); 90 91// Called for an error in the test-runner (not for an error involving a test itself). 92void message ( TestMessageType type, const Slang ::String & errorText); 93SLANG_ATTR_PRINTF ( 3 , 4 ) 94void messageFormat ( TestMessageType type, char const * message, ...); 95virtual SLANG_NO_THROW void SLANG_MCALL 96message ( TestMessageType type, char const * message) override; 97 98void dumpOutputDifference ( 99const Slang ::String & expectedOutput, 100const Slang ::String & actualOutput); 101 102void consolidateWith ( TestReporter * other); 103 104/// True if can write output directly to stderr 105bool canWriteStdError () const; 106 107 108/// Returns true if all run tests succeeded 109bool didAllSucceed () const; 110 111/// Returns a result from the current test 112TestResult getResult () const; 113 114void outputSummary (); 115 116SlangResult init ( 117TestOutputMode outputMode, 118const Slang ::HashSet < Slang::String >& expectedFailureList, 119bool isSubReporter = false); 120 121/// Ctor 122TestReporter(); 123/// Dtor 124~ TestReporter (); 125 126static TestResult combine ( TestResult a, TestResult b) { return (a > b) ? a : b; } 127 128static TestReporter * get () { return s_reporter; } 129static void set ( TestReporter * reporter) { s_reporter = reporter; } 130 131Slang ::List < TestInfo > m_testInfos; 132 133Slang ::List < Slang::String > m_suiteStack; 134 135int m_totalTestCount; 136int m_passedTestCount; 137int m_failedTestCount; 138int m_ignoredTestCount; 139int m_expectedFailedTestCount; 140 141int m_maxFailTestResults; ///< Maximum amount of results per test. If 0 it's infinite. 142 143TestOutputMode m_outputMode = TestOutputMode::Default; 144bool m_dumpOutputOnFailure; 145VerbosityLevel m_verbosity; 146bool m_hideIgnored = false; 147bool m_isSubReporter = false; 148Slang ::HashSet < Slang::String > m_expectedFailureList; 149 150protected : 151void _addResult ( TestInfo info); 152 153Slang :: StringBuilder m_currentMessage; 154TestInfo m_currentInfo; 155int m_numCurrentResults; 156int m_numFailResults; 157 158bool m_inTest; 159 160std :: recursive_mutex m_mutex; 161 162static TestReporter * s_reporter; 163}; 164 165#endif // TEST_REPORTER_H_INCLUDED