Skip to content

Commit

Permalink
Add directive test-case-source.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillof committed Apr 19, 2024
1 parent afd1b2c commit b1cf8ea
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.7.0 [2024-04-19]

- Add `test-case-source` directory for better support of script generated test cases.

# 1.6.0 [2024-04-10]

- Print command line for `--verbose --setup-only`.
Expand Down
5 changes: 5 additions & 0 deletions manpages/nihtest-case.mdoc
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ before comparing them.
See
.Ic stderr-replace
for details.
.It Ic test-case-source Ar filename
Use
.Ar filename
to refer to test case in error messages.
This is useful if the test case is created by a script.
.\" .It Ic ulimit Ar C VALUE
.\" Set
.\" .Xr ulimit 1
Expand Down
2 changes: 1 addition & 1 deletion nihtest/Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def run(self):
st = os.stat(full_file)
os.chmod(full_file, st.st_mode | stat.S_IWRITE)

output = Output.Output(self.case.file_name + ":1: test case failed", self.case.configuration.verbose != Configuration.When.NEVER)
output = Output.Output(self.case.test_case_source + ":1: test case failed", self.case.configuration.verbose != Configuration.When.NEVER)

self.compare(output, "exit code", [str(self.case.exit_code)], [str(command.exit_code)])
self.compare(output,"output", self.case.stdout, self.process_output_replace(command.stdout, self.case.stdout_replace))
Expand Down
8 changes: 8 additions & 0 deletions nihtest/TestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, configuration, args):
if file_name[-5:] != ".test":
file_name += ".test"
self.file_name = self.configuration.find_input_file(file_name)
self.test_case_source = self.file_name
self.file = open(self.file_name, mode="r", encoding='utf-8')
self.line_number = 0
self.directives_seen = {}
Expand Down Expand Up @@ -207,6 +208,9 @@ def directive_stdout(self, arguments):
def directive_stdout_replace(self, arguments):
self.stdout_replace.append((re.compile(arguments[0]), arguments[1]))

def directive_test_case_source(self, arguments):
self.test_case_source = arguments[0]

def directive_working_directory(self, arguments):
self.working_directory = arguments[0]

Expand Down Expand Up @@ -277,6 +281,10 @@ def directive_working_directory(self, arguments):
"stdout-replace": Directive(method=directive_stdout_replace,
usage="pattern replacement",
minimum_arguments=2),
"test-case-source": Directive(method=directive_test_case_source,
usage="file",
minimum_arguments=1,
only_once=True),
"working-directory": Directive(method=directive_working_directory,
usage="directory",
minimum_arguments=1,
Expand Down
3 changes: 3 additions & 0 deletions tests/test-case-source.input
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test-case-source source.test
program nihtest-false
return 0
12 changes: 12 additions & 0 deletions tests/test-case-source.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
program nihtest
arguments test.test
return 1
file test.test test-case-source.input
file nihtest.conf nihtest-conf
stdout
source.test:1: test case failed
exit code differs:
-0
+1
test -- FAIL: exit code
end-of-inline-data

0 comments on commit b1cf8ea

Please sign in to comment.