Skip to content

Commit

Permalink
Add set-modification-time, fix inline stdin data.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillof committed Nov 20, 2023
1 parent e4db895 commit 470c2da
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
17 changes: 7 additions & 10 deletions manpages/nihtest-case.mdoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd June 15, 2023
.Dd November 20, 2023
.Dt NIHTEST-CASE 5
.Os
.Sh NAME
Expand Down Expand Up @@ -146,6 +146,12 @@ is run.
.It Ic return Ar exit-code
.Ar exit-code
is the expected exit code (usually 0 on success).
.It Ic set-modification-time Ar file Ar time
Set the modification of
.Ar file
in the sandbox to
.Ar time ,
which can be either in ISO-8601 format or seconds since Unix epoch.
.It Ic stderr Op Ar file
Specify the expect standard error output (stderr).
If
Expand Down Expand Up @@ -187,15 +193,6 @@ If
is given, the output is compared with that file,
otherwise the expected text is taken from the following lines of the test case, up to a line consisting of
.Dq end-of-inline-data .
.\" .It Ic touch Ar MTIME FILE
.\" Set the last modified timestamp of
.\" .Ar FILE
.\" to
.\" .Ar MTIME
.\" (in seconds since epoch).
.\" If
.\" .Ar FILE
.\" doesn't exist, an empty file is created.
.\" .It Ic ulimit Ar C VALUE
.\" Set
.\" .Xr ulimit 1
Expand Down
3 changes: 3 additions & 0 deletions nihtest/Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def run(self):
for file in self.case.files:
file.prepare(self.case.configuration, self.sandbox.directory)

for file, modification_time in self.case.modification_times.items():
os.utime(os.path.join(self.sandbox.directory, file), (modification_time, modification_time))

if not self.case.configuration.run_test:
return TestResult.OK

Expand Down
16 changes: 14 additions & 2 deletions nihtest/TestCase.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dateutil.parser
import re
import shlex
import sys
Expand Down Expand Up @@ -54,6 +55,7 @@ def __init__(self, configuration, args):
self.stdout = []
self.ok = True
self.directories = []
self.modification_times = {}
self.parse_case()
if not self.ok:
raise RuntimeError("invalid test case")
Expand Down Expand Up @@ -113,7 +115,7 @@ def file_data(self, argument):
if argument == "{}":
return None
if len(argument) >= 2 and argument[0] == "<" and argument[-1] == ">":
inline_file_name = file_name=argument[1:-1]
inline_file_name = argument[1:-1]
if inline_file_name == "empty" or inline_file_name.startswith("empty."):
data = []
else:
Expand Down Expand Up @@ -171,6 +173,13 @@ def directive_program(self, arguments):
def directive_return(self, arguments):
self.exit_code = int(arguments[0]) # TODO: error check?

def directive_set_modification_time(self, arguments):
if arguments[1].isnumeric():
timestamp = int(arguments[1])
else:
timestamp = dateutil.parser.isoparse(arguments[1]).timestamp()
self.modification_times[arguments[0]] = timestamp

def directive_stderr(self, arguments):
self.stderr = self.io_data(arguments)

Expand Down Expand Up @@ -229,6 +238,9 @@ def directive_stdout(self, arguments):
usage="exit-code",
minimum_arguments=1,
only_once=True),
"set-modification-time": Directive(method=directive_set_modification_time,
usage="file time",
minimum_arguments=2),
"stderr": Directive(method=directive_stderr,
usage="[file]",
minimum_arguments=0, maximum_arguments=1,
Expand All @@ -247,4 +259,4 @@ def directive_stdout(self, arguments):
}

def get_program_directories(self):
return self.configuration.program_directories
return self.configuration.program_directories
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ classifiers = [
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
]
dependencies = [
"python-dateutil"
]

[project.urls]
"Homepage" = "https://github.com/nih-at/nihtest"
Expand Down

0 comments on commit 470c2da

Please sign in to comment.