diff --git a/dockerc b/dockerc index ef47dba..dbf7005 100755 --- a/dockerc +++ b/dockerc @@ -715,7 +715,7 @@ elif [ "$(echo "$ARGS" | cut -c1)" = '@' ]; then echo ' @b build' echo ' @bp build --pull' echo ' @bf build --pull --no-cache' - echo ' @bn build --dry-run --pull --no-cache' + echo ' @bn build --dry-run --pull --no-cache' echo ' @d down' echo ' @da down --remove-orphans' echo ' @dr down --remove-orphans --rmi local' @@ -764,7 +764,7 @@ elif [ "$(echo "$ARGS" | cut -c1)" = '@' ]; then echo " @llts logs -t --no-log-prefix" echo ' @p ps' echo ' @pa ps -a' - echo ' @pu push' + echo ' @pu push' echo ' @pl pull' echo ' @rs rm --stop' echo ' @rf rm -f' diff --git a/test/src/RunDockerc.py b/test/src/RunDockerc.py index 5970aee..e528f96 100644 --- a/test/src/RunDockerc.py +++ b/test/src/RunDockerc.py @@ -1,3 +1,4 @@ +import re import subprocess class RunDockerc(): @@ -27,17 +28,40 @@ def __init__( def assert_context( self, - stdout: bytes | None = None, - stderr: bytes | None = None, + stdout: bytes | re.Pattern | None = None, + stderr: bytes | re.Pattern | None = None, returncode: int = 0, ): - assert self.proc_stdout == stdout - assert self.proc_stderr == stderr + # if self.proc_stdout != stdout: + # # Debugging + # import difflib + # diff = difflib.unified_diff( + # self.proc_stdout.decode('utf-8').splitlines(keepends = True), + # ( + # stdout.decode('utf-8').splitlines(keepends = True) + # if isinstance(stdout, bytes) else + # stdout.pattern.splitlines(keepends = True) + # if isinstance(stdout, re.Pattern) else + # stdout + # ), + # ) + # print(''.join(diff)) + + if isinstance(stdout, re.Pattern): + assert stdout.match(self.proc_stdout.decode('utf-8')) + else: + assert self.proc_stdout == stdout + + if isinstance(stderr, re.Pattern): + assert stderr.match(self.proc_stderr.decode('utf-8')) + else: + assert self.proc_stderr == stderr + assert self.proc.returncode == returncode def assert_context_found( self, - stdout: bytes = b'', + stdout: bytes | re.Pattern = b'', ): return self.assert_context( stdout = stdout, @@ -45,8 +69,8 @@ def assert_context_found( def assert_context_error( self, - stdout: bytes | None = None, - stderr: bytes | None = None, + stdout: bytes | re.Pattern | None = None, + stderr: bytes | re.Pattern | None = None, ): return self.assert_context( **({'stdout': stdout} if stdout is not None else {}), diff --git a/test/test/help/test_version.py b/test/test/help/test_version.py index 93ad0b4..52ca67e 100644 --- a/test/test/help/test_version.py +++ b/test/test/help/test_version.py @@ -1,7 +1,9 @@ +import re + from test.src.TestDirContext import TestDirContext -VERSION_STDOUT_SHORT = ( - b'DockerC (v1.8.2) - https://github.com/matiboux/dockerc\n' +VERSION_STDOUT_SHORT_REGEX = ( + '^DockerC \(v[0-9]+\.[0-9]+\.[0-9]+\) - https://github\.com/matiboux/dockerc\n$' ) def test_version(file = __file__): @@ -9,25 +11,33 @@ def test_version(file = __file__): dockerc = ctx.run_dockerc( '--version', ) - dockerc.assert_context_found(VERSION_STDOUT_SHORT) + dockerc.assert_context_found( + re.compile(VERSION_STDOUT_SHORT_REGEX) + ) def test_version_shorthand(file = __file__): with TestDirContext(file) as ctx: dockerc = ctx.run_dockerc( '-v', ) - dockerc.assert_context_found(VERSION_STDOUT_SHORT) + dockerc.assert_context_found( + re.compile(VERSION_STDOUT_SHORT_REGEX) + ) def test_version_dry(file = __file__): with TestDirContext(file) as ctx: dockerc = ctx.run_dockerc( '-n', '--version', ) - dockerc.assert_context_found(VERSION_STDOUT_SHORT) + dockerc.assert_context_found( + re.compile(VERSION_STDOUT_SHORT_REGEX) + ) def test_version_dry_shorthand(file = __file__): with TestDirContext(file) as ctx: dockerc = ctx.run_dockerc( '-n', '-v', ) - dockerc.assert_context_found(VERSION_STDOUT_SHORT) + dockerc.assert_context_found( + re.compile(VERSION_STDOUT_SHORT_REGEX) + )