90
90
"test-command=TEST_EXE.exe" ,
91
91
])
92
92
93
+
94
+ def quote (s ):
95
+ s = str (s )
96
+ return f'"{ s } "' if " " in s else s
97
+
98
+
93
99
def create_registry_data (root , data ):
94
100
def _create_registry_data (root , key , value ):
95
101
if isinstance (value , dict ):
@@ -542,10 +548,10 @@ def test_virtualenv_with_env(self):
542
548
data1 = self .run_py ([], env = {** env , "PY_PYTHON" : "PythonTestSuite/3" })
543
549
data2 = self .run_py (["-V:PythonTestSuite/3" ], env = {** env , "PY_PYTHON" : "PythonTestSuite/3" })
544
550
# Compare stdout, because stderr goes via ascii
545
- self .assertEqual (data1 ["stdout" ].strip (), str (venv_exe ))
551
+ self .assertEqual (data1 ["stdout" ].strip (), quote (venv_exe ))
546
552
self .assertEqual (data1 ["SearchInfo.lowPriorityTag" ], "True" )
547
553
# Ensure passing the argument doesn't trigger the same behaviour
548
- self .assertNotEqual (data2 ["stdout" ].strip (), str (venv_exe ))
554
+ self .assertNotEqual (data2 ["stdout" ].strip (), quote (venv_exe ))
549
555
self .assertNotEqual (data2 ["SearchInfo.lowPriorityTag" ], "True" )
550
556
551
557
def test_py_shebang (self ):
@@ -554,55 +560,60 @@ def test_py_shebang(self):
554
560
data = self .run_py ([script , "-postarg" ])
555
561
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
556
562
self .assertEqual ("3.100" , data ["SearchInfo.tag" ])
557
- self .assertEqual (f"X.Y.exe -prearg { script } -postarg" , data ["stdout" ].strip ())
563
+ self .assertEqual (f"X.Y.exe -prearg { quote ( script ) } -postarg" , data ["stdout" ].strip ())
558
564
559
565
def test_python_shebang (self ):
560
566
with self .py_ini (TEST_PY_DEFAULTS ):
561
567
with self .script ("#! python -prearg" ) as script :
562
568
data = self .run_py ([script , "-postarg" ])
563
569
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
564
570
self .assertEqual ("3.100" , data ["SearchInfo.tag" ])
565
- self .assertEqual (f"X.Y.exe -prearg { script } -postarg" , data ["stdout" ].strip ())
571
+ self .assertEqual (f"X.Y.exe -prearg { quote ( script ) } -postarg" , data ["stdout" ].strip ())
566
572
567
573
def test_py2_shebang (self ):
568
574
with self .py_ini (TEST_PY_DEFAULTS ):
569
575
with self .script ("#! /usr/bin/python2 -prearg" ) as script :
570
576
data = self .run_py ([script , "-postarg" ])
571
577
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
572
578
self .assertEqual ("3.100-32" , data ["SearchInfo.tag" ])
573
- self .assertEqual (f"X.Y-32.exe -prearg { script } -postarg" , data ["stdout" ].strip ())
579
+ self .assertEqual (f"X.Y-32.exe -prearg { quote (script )} -postarg" ,
580
+ data ["stdout" ].strip ())
574
581
575
582
def test_py3_shebang (self ):
576
583
with self .py_ini (TEST_PY_DEFAULTS ):
577
584
with self .script ("#! /usr/bin/python3 -prearg" ) as script :
578
585
data = self .run_py ([script , "-postarg" ])
579
586
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
580
587
self .assertEqual ("3.100-arm64" , data ["SearchInfo.tag" ])
581
- self .assertEqual (f"X.Y-arm64.exe -X fake_arg_for_test -prearg { script } -postarg" , data ["stdout" ].strip ())
588
+ self .assertEqual (f"X.Y-arm64.exe -X fake_arg_for_test -prearg { quote (script )} -postarg" ,
589
+ data ["stdout" ].strip ())
582
590
583
591
def test_py_shebang_nl (self ):
584
592
with self .py_ini (TEST_PY_DEFAULTS ):
585
593
with self .script ("#! /usr/bin/python -prearg\n " ) as script :
586
594
data = self .run_py ([script , "-postarg" ])
587
595
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
588
596
self .assertEqual ("3.100" , data ["SearchInfo.tag" ])
589
- self .assertEqual (f"X.Y.exe -prearg { script } -postarg" , data ["stdout" ].strip ())
597
+ self .assertEqual (f"X.Y.exe -prearg { quote (script )} -postarg" ,
598
+ data ["stdout" ].strip ())
590
599
591
600
def test_py2_shebang_nl (self ):
592
601
with self .py_ini (TEST_PY_DEFAULTS ):
593
602
with self .script ("#! /usr/bin/python2 -prearg\n " ) as script :
594
603
data = self .run_py ([script , "-postarg" ])
595
604
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
596
605
self .assertEqual ("3.100-32" , data ["SearchInfo.tag" ])
597
- self .assertEqual (f"X.Y-32.exe -prearg { script } -postarg" , data ["stdout" ].strip ())
606
+ self .assertEqual (f"X.Y-32.exe -prearg { quote (script )} -postarg" ,
607
+ data ["stdout" ].strip ())
598
608
599
609
def test_py3_shebang_nl (self ):
600
610
with self .py_ini (TEST_PY_DEFAULTS ):
601
611
with self .script ("#! /usr/bin/python3 -prearg\n " ) as script :
602
612
data = self .run_py ([script , "-postarg" ])
603
613
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
604
614
self .assertEqual ("3.100-arm64" , data ["SearchInfo.tag" ])
605
- self .assertEqual (f"X.Y-arm64.exe -X fake_arg_for_test -prearg { script } -postarg" , data ["stdout" ].strip ())
615
+ self .assertEqual (f"X.Y-arm64.exe -X fake_arg_for_test -prearg { quote (script )} -postarg" ,
616
+ data ["stdout" ].strip ())
606
617
607
618
def test_py_shebang_short_argv0 (self ):
608
619
with self .py_ini (TEST_PY_DEFAULTS ):
@@ -630,7 +641,8 @@ def test_search_path(self):
630
641
[script , "-postarg" ],
631
642
env = {"PATH" : f"{ exe .parent } ;{ os .getenv ('PATH' )} " },
632
643
)
633
- self .assertEqual (f"{ exe } -prearg { script } -postarg" , data ["stdout" ].strip ())
644
+ self .assertEqual (f"{ quote (exe )} -prearg { quote (script )} -postarg" ,
645
+ data ["stdout" ].strip ())
634
646
635
647
def test_search_path_exe (self ):
636
648
# Leave the .exe on the name to ensure we don't add it a second time
@@ -643,7 +655,8 @@ def test_search_path_exe(self):
643
655
[script , "-postarg" ],
644
656
env = {"PATH" : f"{ exe .parent } ;{ os .getenv ('PATH' )} " },
645
657
)
646
- self .assertEqual (f"{ exe } -prearg { script } -postarg" , data ["stdout" ].strip ())
658
+ self .assertEqual (f"{ quote (exe )} -prearg { quote (script )} -postarg" ,
659
+ data ["stdout" ].strip ())
647
660
648
661
def test_recursive_search_path (self ):
649
662
stem = self .get_py_exe ().stem
@@ -654,7 +667,7 @@ def test_recursive_search_path(self):
654
667
env = {"PATH" : f"{ self .get_py_exe ().parent } ;{ os .getenv ('PATH' )} " },
655
668
)
656
669
# The recursive search is ignored and we get normal "py" behavior
657
- self .assertEqual (f"X.Y.exe { script } " , data ["stdout" ].strip ())
670
+ self .assertEqual (f"X.Y.exe { quote ( script ) } " , data ["stdout" ].strip ())
658
671
659
672
def test_install (self ):
660
673
data = self .run_py (["-V:3.10" ], env = {"PYLAUNCHER_ALWAYS_INSTALL" : "1" }, expect_returncode = 111 )
@@ -674,38 +687,38 @@ def test_literal_shebang_absolute(self):
674
687
with self .script ("#! C:/some_random_app -witharg" ) as script :
675
688
data = self .run_py ([script ])
676
689
self .assertEqual (
677
- f"C:\\ some_random_app -witharg { script } " ,
690
+ f"C:\\ some_random_app -witharg { quote ( script ) } " ,
678
691
data ["stdout" ].strip (),
679
692
)
680
693
681
694
def test_literal_shebang_relative (self ):
682
695
with self .script ("#! ..\\ some_random_app -witharg" ) as script :
683
696
data = self .run_py ([script ])
684
697
self .assertEqual (
685
- f"{ script .parent .parent } \\ some_random_app -witharg { script } " ,
698
+ f"{ quote ( script .parent .parent / ' some_random_app' ) } -witharg { quote ( script ) } " ,
686
699
data ["stdout" ].strip (),
687
700
)
688
701
689
702
def test_literal_shebang_quoted (self ):
690
703
with self .script ('#! "some random app" -witharg' ) as script :
691
704
data = self .run_py ([script ])
692
705
self .assertEqual (
693
- f'" { script .parent } \\ some random app" -witharg { script } ' ,
706
+ f" { quote ( script .parent / ' some random app' ) } -witharg { quote ( script ) } " ,
694
707
data ["stdout" ].strip (),
695
708
)
696
709
697
710
with self .script ('#! some" random "app -witharg' ) as script :
698
711
data = self .run_py ([script ])
699
712
self .assertEqual (
700
- f'" { script .parent } \\ some random app" -witharg { script } ' ,
713
+ f" { quote ( script .parent / ' some random app' ) } -witharg { quote ( script ) } " ,
701
714
data ["stdout" ].strip (),
702
715
)
703
716
704
717
def test_literal_shebang_quoted_escape (self ):
705
718
with self .script ('#! some\\ " random "app -witharg' ) as script :
706
719
data = self .run_py ([script ])
707
720
self .assertEqual (
708
- f'" { script .parent } \\ some\\ random app" -witharg { script } ' ,
721
+ f" { quote ( script .parent / ' some/ random app' ) } -witharg { quote ( script ) } " ,
709
722
data ["stdout" ].strip (),
710
723
)
711
724
@@ -714,7 +727,7 @@ def test_literal_shebang_command(self):
714
727
with self .script ('#! test-command arg1' ) as script :
715
728
data = self .run_py ([script ])
716
729
self .assertEqual (
717
- f"TEST_EXE.exe arg1 { script } " ,
730
+ f"TEST_EXE.exe arg1 { quote ( script ) } " ,
718
731
data ["stdout" ].strip (),
719
732
)
720
733
@@ -723,7 +736,7 @@ def test_literal_shebang_invalid_template(self):
723
736
data = self .run_py ([script ])
724
737
expect = script .parent / "/usr/bin/not-python"
725
738
self .assertEqual (
726
- f"{ expect } arg1 { script } " ,
739
+ f"{ quote ( expect ) } arg1 { quote ( script ) } " ,
727
740
data ["stdout" ].strip (),
728
741
)
729
742
@@ -746,8 +759,8 @@ def test_shebang_command_in_venv(self):
746
759
747
760
with self .script (f'#! /usr/bin/env { stem } arg1' ) as script :
748
761
data = self .run_py ([script ], env = env )
749
- self .assertEqual (data ["stdout" ].strip (), f"{ venv_exe } arg1 { script } " )
762
+ self .assertEqual (data ["stdout" ].strip (), f"{ quote ( venv_exe ) } arg1 { quote ( script ) } " )
750
763
751
764
with self .script (f'#! /usr/bin/env { exe .stem } arg1' ) as script :
752
765
data = self .run_py ([script ], env = env )
753
- self .assertEqual (data ["stdout" ].strip (), f"{ exe } arg1 { script } " )
766
+ self .assertEqual (data ["stdout" ].strip (), f"{ quote ( exe ) } arg1 { quote ( script ) } " )
0 commit comments