From 8b9e508a0f6ba114005a364fe9e7ca3c8d786ee2 Mon Sep 17 00:00:00 2001 From: deme Date: Wed, 17 Oct 2018 13:59:49 +0200 Subject: [PATCH] #20 Add test file os property --- tests/README.md | 3 +++ .../colors/{native_colors.test => native_colors_unix.test} | 5 ++--- ...{native_colors_win7.test => native_colors_windows.test} | 5 +++-- tests/test_config.nim | 7 +++++++ tests/testrunner.nim | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) rename tests/colors/{native_colors.test => native_colors_unix.test} (78%) rename tests/colors/{native_colors_win7.test => native_colors_windows.test} (85%) diff --git a/tests/README.md b/tests/README.md index 649ff24..f734e3d 100644 --- a/tests/README.md +++ b/tests/README.md @@ -23,6 +23,9 @@ your own timestamp peg here. should be expected. - **error_file**: When expecting a compilation failure, the source file where the error should occur. +- **os**: Space and/or comma separated list of operating systems for which the +test should be run. Defaults to `"linux, macosx, windows"`. Tests meant for a +different OS than the host will be marked as `SKIPPED`. - **--skip**: This will simply skip the test (will not be marked as failure). ### Forwarded Options diff --git a/tests/colors/native_colors.test b/tests/colors/native_colors_unix.test similarity index 78% rename from tests/colors/native_colors.test rename to tests/colors/native_colors_unix.test index 762db21..8fa2c9d 100644 --- a/tests/colors/native_colors.test +++ b/tests/colors/native_colors_unix.test @@ -1,13 +1,12 @@ ; NativeColors on Unix will give AnsiColors -; To make this test work on both Unix and Windows we would need a flag where -; we can set the OS to test for or test on different outputs per OS -; For now, this test should only be run on Unix, as it will fail on Windows program=long_lines chronicles_sinks="textlines[stdout]" chronicles_colors=NativeColors chronicles_timestamps=None +os="Linux MacOSX" + [Output] stdout="""INF long info  thread=0 file=long_lines.nim:10 str="some multiline\nstring\nmore lines" WRN long warning  thread=0 str="some multiline\nstring\nmore lines" diff --git a/tests/colors/native_colors_win7.test b/tests/colors/native_colors_windows.test similarity index 85% rename from tests/colors/native_colors_win7.test rename to tests/colors/native_colors_windows.test index 2569d37..d88cdb5 100644 --- a/tests/colors/native_colors_win7.test +++ b/tests/colors/native_colors_windows.test @@ -1,10 +1,11 @@ ---skip -; NativeColors test for Windows 7, actually just compares the non colored output +; NativeColors test for Windows, actually just compares the non colored output program=long_lines chronicles_sinks="textlines[stdout]" chronicles_colors=NativeColors chronicles_timestamps=None +os=Windows + [Output] stdout="""INF long info thread=0 file=long_lines.nim:10 str="some multiline\nstring\nmore lines" WRN long warning thread=0 str="some multiline\nstring\nmore lines" diff --git a/tests/test_config.nim b/tests/test_config.nim index a5b91e0..0e0c2f1 100644 --- a/tests/test_config.nim +++ b/tests/test_config.nim @@ -26,6 +26,7 @@ type errorFile*: string errorLine*: int errorColumn*: int + os*: seq[string] proc processArguments*(): TestConfig = var opt = initOptParser() @@ -47,7 +48,11 @@ proc processArguments*(): TestConfig = if result.path == "": quit(Usage) +proc defaults(result: var TestSpec) = + result.os = @["linux", "macosx", "windows"] + proc parseTestFile*(filePath:string): TestSpec = + result.defaults() result.name = extractFilename(filePath) var f = newFileStream(filePath, fmRead) var outputSection = false @@ -81,6 +86,8 @@ proc parseTestFile*(filePath:string): TestSpec = result.compileError = e.value of "error_file": result.errorFile = e.value + of "os": + result.os = e.value.normalize.split({','} + Whitespace) else: result.flags &= ("-d:$#:$#" % [e.key, e.value]).quoteShell & " " of cfgOption: diff --git a/tests/testrunner.nim b/tests/testrunner.nim index 5441447..d863ee4 100644 --- a/tests/testrunner.nim +++ b/tests/testrunner.nim @@ -187,7 +187,7 @@ proc test(testPath: string): TestStatus = if test.program.len == 0: # a program name is bare minimum of a test file result = INVALID break - if test.skip: + if test.skip or hostOS notin test.os: result = SKIPPED break