mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-10 13:48:40 +01:00
Remove magic values as exit codes in test application (#777)
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "wren.h"
|
||||
#include "../test.h"
|
||||
|
||||
int callWrenCallRootRunTests(WrenVM* vm)
|
||||
{
|
||||
@ -17,7 +18,7 @@ int callWrenCallRootRunTests(WrenVM* vm)
|
||||
WrenInterpretResult result = wrenCall(vm, run);
|
||||
if (result == WREN_RESULT_RUNTIME_ERROR)
|
||||
{
|
||||
exitCode = 70;
|
||||
exitCode = WREN_EX_SOFTWARE;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -47,8 +47,8 @@ int main(int argc, const char* argv[]) {
|
||||
exitCode = APITest_Run(vm, testName);
|
||||
}
|
||||
|
||||
if (result == WREN_RESULT_COMPILE_ERROR) return 65; // EX_DATAERR.
|
||||
if (result == WREN_RESULT_RUNTIME_ERROR) return 70; // EX_SOFTWARE.
|
||||
if (result == WREN_RESULT_COMPILE_ERROR) return WREN_EX_DATAERR;
|
||||
if (result == WREN_RESULT_RUNTIME_ERROR) return WREN_EX_SOFTWARE;
|
||||
|
||||
wrenFreeVM(vm);
|
||||
|
||||
|
||||
@ -320,7 +320,7 @@
|
||||
if (buffer == NULL)
|
||||
{
|
||||
fprintf(stderr, "Could not read file \"%s\".\n", path);
|
||||
exit(74);
|
||||
exit(WREN_EX_IOERR);
|
||||
}
|
||||
|
||||
// Read the entire file.
|
||||
@ -328,7 +328,7 @@
|
||||
if (bytesRead < fileSize)
|
||||
{
|
||||
fprintf(stderr, "Could not read file \"%s\".\n", path);
|
||||
exit(74);
|
||||
exit(WREN_EX_IOERR);
|
||||
}
|
||||
|
||||
// Terminate the string.
|
||||
@ -421,7 +421,7 @@
|
||||
if (source == NULL)
|
||||
{
|
||||
fprintf(stderr, "Could not find file \"%s\".\n", path);
|
||||
exit(66);
|
||||
exit(WREN_EX_NOINPUT);
|
||||
}
|
||||
|
||||
// If it looks like a relative path, make it explicitly relative so that we
|
||||
@ -452,7 +452,7 @@
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("This is a Wren test runner.\nUsage: wren_test [file]\n");
|
||||
return 64; // EX_USAGE.
|
||||
return WREN_EX_USAGE;
|
||||
}
|
||||
|
||||
if (argc == 2 && strcmp(argv[1], "--version") == 0)
|
||||
|
||||
17
test/test.h
17
test/test.h
@ -6,6 +6,23 @@
|
||||
#include <string.h>
|
||||
#include "wren.h"
|
||||
|
||||
// Exit codes used by the wren binaries, following the BSD standard
|
||||
//
|
||||
// The interpreter was used with an incorrect number of arguments
|
||||
#define WREN_EX_USAGE 64
|
||||
|
||||
// Compilation error
|
||||
#define WREN_EX_DATAERR 65
|
||||
|
||||
// Runtime error
|
||||
#define WREN_EX_SOFTWARE 70
|
||||
|
||||
// Cannot open input file
|
||||
#define WREN_EX_NOINPUT 66
|
||||
|
||||
// I/O Error
|
||||
#define WREN_EX_IOERR 74
|
||||
|
||||
// The maximum number of components in a path. We can't normalize a path that
|
||||
// contains more than this number of parts. The number here assumes a max path
|
||||
// length of 4096, which is common on Linux, and then assumes each component is
|
||||
|
||||
@ -53,7 +53,6 @@ num_skipped = 0
|
||||
skipped = defaultdict(int)
|
||||
expectations = 0
|
||||
|
||||
|
||||
class Test:
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
@ -99,7 +98,7 @@ class Test:
|
||||
if match:
|
||||
self.compile_errors.add(line_num)
|
||||
|
||||
# If we expect a compile error, it should exit with EX_DATAERR.
|
||||
# If we expect a compile error, it should exit with WREN_EX_DATAERR.
|
||||
self.exit_code = 65
|
||||
expectations += 1
|
||||
|
||||
@ -107,7 +106,7 @@ class Test:
|
||||
if match:
|
||||
self.compile_errors.add(int(match.group(1)))
|
||||
|
||||
# If we expect a compile error, it should exit with EX_DATAERR.
|
||||
# If we expect a compile error, it should exit with WREN_EX_DATAERR.
|
||||
self.exit_code = 65
|
||||
expectations += 1
|
||||
|
||||
@ -115,7 +114,7 @@ class Test:
|
||||
if match:
|
||||
self.runtime_error_line = line_num
|
||||
self.runtime_error_message = match.group(2)
|
||||
# If the runtime error isn't handled, it should exit with EX_SOFTWARE.
|
||||
# If the runtime error isn't handled, it should exit with WREN_EX_SOFTWARE.
|
||||
if match.group(1) != "handled ":
|
||||
self.exit_code = 70
|
||||
expectations += 1
|
||||
|
||||
Reference in New Issue
Block a user