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
|
#ifndef SLANG_CORE_TEST_TOOL_UTIL_H
#define SLANG_CORE_TEST_TOOL_UTIL_H
#include "slang-std-writers.h"
namespace Slang {
#ifdef SLANG_SHARED_LIBRARY_TOOL
# define SLANG_TEST_TOOL_API SLANG_EXTERN_C SLANG_DLL_EXPORT
#else
# define SLANG_TEST_TOOL_API
#endif
/* When a tool is run as an executable the return code is the code returned from
the last return of main. On unix this can be up to 8 bits.
By normal command line tool conventions returning 0 means success. */
enum class ToolReturnCode
{
CompilationFailed = -1, ///< Compilation failure (-1 to maintain compatibility). This may still produce output and may mean a test was successful.
Success = 0, ///< Tool ran normally
Failed, ///< Tool failed
Ignored, ///< The run was ignored because it couldn't be run (because some optional feature was not present for example)
FailedToRun, ///< Could not even run the test
};
enum class ToolReturnCodeSpan
{
// Span of all valid values
First = int(ToolReturnCode::CompilationFailed),
Last = int(ToolReturnCode::FailedToRun),
// Span of all values that indicate the test is 'done'
FirstIsDone = int(ToolReturnCode::Ignored),
LastIsDone = int(ToolReturnCode::FailedToRun)
};
/* Utility functions for 'test tools' */
struct TestToolUtil
{
typedef SlangResult(*InnerMainFunc)(Slang::StdWriters* stdWriters, SlangSession* session, int argc, const char*const* argv);
/// If the test failed to run or was ignored then we are done
static bool isDone(ToolReturnCode code) { return int(code) >= int(ToolReturnCodeSpan::FirstIsDone) && int(code) <= int(ToolReturnCodeSpan::LastIsDone); }
/// Convert from an int
static ToolReturnCode getReturnCodeFromInt(int code);
/// Given a slang result, returns a return code that can be returned from an executable
static ToolReturnCode getReturnCode(SlangResult res);
/// Given the executable path (as located in Slang directory hierarchy), works out the absolute path to the root
static SlangResult getRootPath(const char* exePath, String& outRootPath);
/// Given the exePath, give return the absolute path to the directory the exe is in
static SlangResult getExeDirectoryPath(const char* exePath, String& outExeDirectoryPath);
/// Sets the default preludes on the session based on the executable path
static SlangResult setSessionDefaultPreludeFromRootPath(const String& rootPath, slang::IGlobalSession* session);
/// Calculates the path that is the combination of parentPath, and relPath
/// And converts such that can be used as an include path (handling slashes)
static SlangResult getIncludePath(const String& parentPath, const char* relPath, String& outIncludePath);
/// Sets the default preludes on the session based on the executable path
static SlangResult setSessionDefaultPreludeFromExePath(const char* exePath, slang::IGlobalSession* session);
/// Returns true if the StdLib should not be initialized immediately (eg when doing a -load-stdlib).
static bool hasDeferredStdLib(Index numArgs, const char*const* args);
};
} // namespace Slang
#endif // SLANG_TEST_TOOL_H
|