@@ -12,12 +12,34 @@ def current_version():
12
12
return open ('VERSION' ).read ().strip ()
13
13
14
14
15
+ def normalize_stderr (stderr ):
16
+ # dumb-init prints out argv[0] in its usage message. This should always be
17
+ # just "dumb-init" under regular test scenarios here since that is how we
18
+ # call it, but in CI the use of QEMU causes the argv[0] to be replaced with
19
+ # the full path.
20
+ #
21
+ # This is supposed to be avoidable by:
22
+ # 1) Setting the "P" flag in the binfmt register:
23
+ # https://en.wikipedia.org/wiki/Binfmt_misc#Registration
24
+ # This can be done by setting the QEMU_PRESERVE_PARENT env var when
25
+ # calling binfmt.
26
+ #
27
+ # 2) Setting the "QEMU_ARGV0" env var to empty string for *all*
28
+ # processes:
29
+ # https://bugs.launchpad.net/qemu/+bug/1835839
30
+ #
31
+ # I can get it working properly in CI outside of Docker, but for some
32
+ # reason not during Docker builds. This doesn't affect the built executable
33
+ # so I decided to just punt on it.
34
+ return re .sub (rb'(^|(?<=\s))[a-z/.]+/dumb-init' , b'dumb-init' , stderr )
35
+
36
+
15
37
@pytest .mark .usefixtures ('both_debug_modes' , 'both_setsid_modes' )
16
38
def test_no_arguments_prints_usage ():
17
39
proc = Popen (('dumb-init' ), stderr = PIPE )
18
40
_ , stderr = proc .communicate ()
19
41
assert proc .returncode != 0
20
- assert stderr == (
42
+ assert normalize_stderr ( stderr ) == (
21
43
b'Usage: dumb-init [option] program [args]\n '
22
44
b'Try dumb-init --help for full usage.\n '
23
45
)
@@ -28,7 +50,7 @@ def test_exits_invalid_with_invalid_args():
28
50
proc = Popen (('dumb-init' , '--yolo' , '/bin/true' ), stderr = PIPE )
29
51
_ , stderr = proc .communicate ()
30
52
assert proc .returncode == 1
31
- assert stderr in (
53
+ assert normalize_stderr ( stderr ) in (
32
54
b"dumb-init: unrecognized option '--yolo'\n " , # glibc
33
55
b'dumb-init: unrecognized option: yolo\n ' , # musl
34
56
)
@@ -43,7 +65,7 @@ def test_help_message(flag, current_version):
43
65
proc = Popen (('dumb-init' , flag ), stderr = PIPE )
44
66
_ , stderr = proc .communicate ()
45
67
assert proc .returncode == 0
46
- assert stderr == (
68
+ assert normalize_stderr ( stderr ) == (
47
69
b'dumb-init v' + current_version .encode ('ascii' ) + b'\n '
48
70
b'Usage: dumb-init [option] command [[arg] ...]\n '
49
71
b'\n '
0 commit comments