@@ -77,61 +77,51 @@ fn test_too_many_hashes() {
7777 check_raw_str ( & s2, Err ( RawStrError :: TooManyDelimiters { found : u32:: from ( max_count) + 1 } ) ) ;
7878}
7979
80+ // https://github.com/rust-lang/rust/issues/70528
8081#[ test]
8182fn test_valid_shebang ( ) {
82- // https://github.com/rust-lang/rust/issues/70528
83- let input = "#!/usr/bin/rustrun\n let x = 5;" ;
84- assert_eq ! ( strip_shebang( input) , Some ( 18 ) ) ;
85- }
83+ let input = "#!/bin/bash" ;
84+ assert_eq ! ( strip_shebang( input) , Some ( input. len( ) ) ) ;
8685
87- #[ test]
88- fn test_invalid_shebang_valid_rust_syntax ( ) {
89- // https://github.com/rust-lang/rust/issues/70528
90- let input = "#! [bad_attribute]" ;
86+ let input = "#![attribute]" ;
9187 assert_eq ! ( strip_shebang( input) , None ) ;
92- }
9388
94- # [ test ]
95- fn test_shebang_second_line ( ) {
96- // Because shebangs are interpreted by the kernel, they must be on the first line
97- let input = "\n #!/bin/bash " ;
89+ let input = "#! /bin/bash" ;
90+ assert_eq ! ( strip_shebang ( input ) , Some ( input . len ( ) ) ) ;
91+
92+ let input = "#! [attribute] " ;
9893 assert_eq ! ( strip_shebang( input) , None ) ;
99- }
10094
101- #[ test]
102- fn test_shebang_space ( ) {
103- let input = "#! /bin/bash" ;
95+ let input = "#! /* blah */ /bin/bash" ;
10496 assert_eq ! ( strip_shebang( input) , Some ( input. len( ) ) ) ;
105- }
10697
107- #[ test]
108- fn test_shebang_empty_shebang ( ) {
109- let input = "#! \n [attribute(foo)]" ;
98+ let input = "#! /* blah */ [attribute]" ;
11099 assert_eq ! ( strip_shebang( input) , None ) ;
111- }
112100
113- #[ test]
114- fn test_invalid_shebang_comment ( ) {
115- let input = "#!//bin/ami/a/comment\n [" ;
116- assert_eq ! ( strip_shebang( input) , None )
117- }
101+ let input = "#! // blah\n /bin/bash" ;
102+ assert_eq ! ( strip_shebang( input) , Some ( 10 ) ) ; // strip up to the newline
118103
119- #[ test]
120- fn test_invalid_shebang_another_comment ( ) {
121- let input = "#!/*bin/ami/a/comment*/\n [attribute" ;
122- assert_eq ! ( strip_shebang( input) , None )
123- }
104+ let input = "#! // blah\n [attribute]" ;
105+ assert_eq ! ( strip_shebang( input) , None ) ;
124106
125- #[ test]
126- fn test_shebang_valid_rust_after ( ) {
127- let input = "#!/*bin/ami/a/comment*/\n pub fn main() {}" ;
128- assert_eq ! ( strip_shebang( input) , Some ( 23 ) )
129- }
107+ let input = "#! /* blah\n blah\n blah */ /bin/bash" ;
108+ assert_eq ! ( strip_shebang( input) , Some ( 10 ) ) ;
130109
131- #[ test]
132- fn test_shebang_followed_by_attrib ( ) {
133- let input = "#!/bin/rust-scripts\n #![allow_unused(true)]" ;
134- assert_eq ! ( strip_shebang( input) , Some ( 19 ) ) ;
110+ let input = "#! /* blah\n blah\n blah */ [attribute]" ;
111+ assert_eq ! ( strip_shebang( input) , None ) ;
112+
113+ let input = "#!\n /bin/sh" ;
114+ assert_eq ! ( strip_shebang( input) , Some ( 2 ) ) ;
115+
116+ let input = "#!\n [attribute]" ;
117+ assert_eq ! ( strip_shebang( input) , None ) ;
118+
119+ // Because shebangs are interpreted by the kernel, they must be on the first line
120+ let input = "\n #!/bin/bash" ;
121+ assert_eq ! ( strip_shebang( input) , None ) ;
122+
123+ let input = "\n #![attribute]" ;
124+ assert_eq ! ( strip_shebang( input) , None ) ;
135125}
136126
137127fn check_lexing ( src : & str , expect : Expect ) {
0 commit comments