From e834e9f45d4b3aa8693424490446976549523fc4 Mon Sep 17 00:00:00 2001 From: breblanc Date: Sun, 12 Jan 2025 12:59:29 +0100 Subject: [PATCH] have something that works for stdin --- tested/dsl/schema-strict.json | 89 +++++++++++++++++++++++++++++----- tested/dsl/schema.json | 89 +++++++++++++++++++++++++++++----- tested/dsl/translate_parser.py | 10 ++-- 3 files changed, 161 insertions(+), 27 deletions(-) diff --git a/tested/dsl/schema-strict.json b/tested/dsl/schema-strict.json index 8ab5f251..41195e33 100644 --- a/tested/dsl/schema-strict.json +++ b/tested/dsl/schema-strict.json @@ -276,11 +276,27 @@ }, "stdin" : { "description" : "Stdin for this context", - "type" : [ - "string", - "number", - "integer", - "boolean" + "oneOf": [ + { + "type" : [ + "string", + "number", + "integer", + "boolean" + ] + }, + { + "type": "object", + "required" : [ + "path" + ], + "properties" : { + "path": { + "type": "string", + "description": "Path to the file that contains the stdin" + } + } + } ] }, "arguments" : { @@ -372,11 +388,27 @@ }, "stdin" : { "description" : "Stdin for this context", - "type" : [ - "string", - "number", - "integer", - "boolean" + "oneOf": [ + { + "type" : [ + "string", + "number", + "integer", + "boolean" + ] + }, + { + "type": "object", + "required" : [ + "path" + ], + "properties" : { + "path": { + "type": "string", + "description": "Path to the file that contains the stdin" + } + } + } ] }, "arguments" : { @@ -519,10 +551,23 @@ { "type" : "object", "description" : "Built-in oracle for text values.", - "required" : [ - "data" + "oneOf": [ + { + "required" : [ + "data" + ] + }, + { + "required" : [ + "path" + ] + } ], "properties" : { + "path": { + "type" : "string", + "description" : "The path to the file containing the text value." + }, "data" : { "$ref" : "#/definitions/textualType" }, @@ -537,12 +582,32 @@ { "type" : "object", "description" : "Custom oracle for text values.", + "oneOf": [ + { + "required" : [ + "oracle", + "file", + "data" + ] + }, + { + "required" : [ + "oracle", + "file", + "path" + ] + } + ], "required" : [ "oracle", "file", "data" ], "properties" : { + "path": { + "type" : "string", + "description" : "The path to the file containing the text value." + }, "data" : { "$ref" : "#/definitions/textualType" }, diff --git a/tested/dsl/schema.json b/tested/dsl/schema.json index 665c447c..146db555 100644 --- a/tested/dsl/schema.json +++ b/tested/dsl/schema.json @@ -276,11 +276,27 @@ }, "stdin" : { "description" : "Stdin for this context", - "type" : [ - "string", - "number", - "integer", - "boolean" + "oneOf": [ + { + "type" : [ + "string", + "number", + "integer", + "boolean" + ] + }, + { + "type": "object", + "required" : [ + "path" + ], + "properties" : { + "path": { + "type": "string", + "description": "Path to the file that contains the stdin" + } + } + } ] }, "arguments" : { @@ -372,11 +388,27 @@ }, "stdin" : { "description" : "Stdin for this context", - "type" : [ - "string", - "number", - "integer", - "boolean" + "oneOf": [ + { + "type" : [ + "string", + "number", + "integer", + "boolean" + ] + }, + { + "type": "object", + "required" : [ + "path" + ], + "properties" : { + "path": { + "type": "string", + "description": "Path to the file that contains the stdin" + } + } + } ] }, "arguments" : { @@ -519,10 +551,23 @@ { "type" : "object", "description" : "Built-in oracle for text values.", - "required" : [ - "data" + "oneOf": [ + { + "required" : [ + "data" + ] + }, + { + "required" : [ + "path" + ] + } ], "properties" : { + "path": { + "type" : "string", + "description" : "The path to the file containing the text value." + }, "data" : { "$ref" : "#/definitions/textualType" }, @@ -537,12 +582,32 @@ { "type" : "object", "description" : "Custom oracle for text values.", + "oneOf": [ + { + "required" : [ + "oracle", + "file", + "data" + ] + }, + { + "required" : [ + "oracle", + "file", + "path" + ] + } + ], "required" : [ "oracle", "file", "data" ], "properties" : { + "path": { + "type" : "string", + "description" : "The path to the file containing the text value." + }, "data" : { "$ref" : "#/definitions/textualType" }, diff --git a/tested/dsl/translate_parser.py b/tested/dsl/translate_parser.py index 68f376e8..5e08b940 100644 --- a/tested/dsl/translate_parser.py +++ b/tested/dsl/translate_parser.py @@ -67,7 +67,7 @@ TextBuiltin, TextData, TextOutputChannel, - ValueOutputChannel, + ValueOutputChannel, TextChannelType, ) from tested.utils import get_args, recursive_dict_merge @@ -590,8 +590,12 @@ def _convert_testcase(testcase: YamlDict, context: DslContext) -> Testcase: return_channel = IgnoredChannel.IGNORED if "statement" in testcase else None else: if "stdin" in testcase: - assert isinstance(testcase["stdin"], str) - stdin = TextData(data=_ensure_trailing_newline(testcase["stdin"])) + if isinstance(testcase["stdin"], dict): + path = testcase["stdin"].get("path") + stdin = TextData(data=path, type=TextChannelType.FILE) + else: + assert isinstance(testcase["stdin"], str) + stdin = TextData(data=_ensure_trailing_newline(testcase["stdin"])) else: stdin = EmptyChannel.NONE arguments = testcase.get("arguments", [])