Skip to content

Commit 8c724d7

Browse files
committed
regression test for --help-env & --help-xoptions sort order
1 parent 37d1eb7 commit 8c724d7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Lib/test/test_cmd_line.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# See test_cmd_line_script.py for testing of script execution
44

55
import os
6+
import re
67
import subprocess
78
import sys
89
import tempfile
@@ -54,11 +55,22 @@ def test_help(self):
5455
def test_help_env(self):
5556
out = self.verify_valid_flag('--help-env')
5657
self.assertIn(b'PYTHONHOME', out)
58+
# Env vars in each section should be sorted alphabetically
59+
# (ignoring underscores so PYTHON_FOO and PYTHONFOO intermix naturally)
60+
sort_key = lambda name: name.replace(b'_', b'').lower()
61+
sections = out.split(b'These variables have equivalent')
62+
for section in sections:
63+
envvars = re.findall(rb'^(PYTHON\w+)', section, re.MULTILINE)
64+
self.assertEqual(envvars, sorted(envvars, key=sort_key),
65+
"env vars should be sorted alphabetically")
5766

5867
@support.cpython_only
5968
def test_help_xoptions(self):
6069
out = self.verify_valid_flag('--help-xoptions')
6170
self.assertIn(b'-X dev', out)
71+
options = re.findall(rb'^-X (\w+)', out, re.MULTILINE)
72+
self.assertEqual(options, sorted(options),
73+
"options should be sorted alphabetically")
6274

6375
@support.cpython_only
6476
def test_help_all(self):

0 commit comments

Comments
 (0)