@@ -77,61 +77,51 @@ fn test_too_many_hashes() {
77
77
check_raw_str ( & s2, Err ( RawStrError :: TooManyDelimiters { found : u32:: from ( max_count) + 1 } ) ) ;
78
78
}
79
79
80
+ // https://github.com/rust-lang/rust/issues/70528
80
81
#[ test]
81
82
fn 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( ) ) ) ;
86
85
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]" ;
91
87
assert_eq ! ( strip_shebang( input) , None ) ;
92
- }
93
88
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] " ;
98
93
assert_eq ! ( strip_shebang( input) , None ) ;
99
- }
100
94
101
- #[ test]
102
- fn test_shebang_space ( ) {
103
- let input = "#! /bin/bash" ;
95
+ let input = "#! /* blah */ /bin/bash" ;
104
96
assert_eq ! ( strip_shebang( input) , Some ( input. len( ) ) ) ;
105
- }
106
97
107
- #[ test]
108
- fn test_shebang_empty_shebang ( ) {
109
- let input = "#! \n [attribute(foo)]" ;
98
+ let input = "#! /* blah */ [attribute]" ;
110
99
assert_eq ! ( strip_shebang( input) , None ) ;
111
- }
112
100
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
118
103
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 ) ;
124
106
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 ) ) ;
130
109
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 ) ;
135
125
}
136
126
137
127
fn check_lexing ( src : & str , expect : Expect ) {
0 commit comments