@@ -157,6 +157,47 @@ export PATH="$HOME/apple/bin"
157
157
} ) ;
158
158
}
159
159
160
+ #[ test]
161
+ fn install_adds_path_to_rc_handling_no_newline ( ) {
162
+ clitools:: setup ( Scenario :: Empty , & |config| {
163
+ let profile = config. homedir . join ( ".profile" ) ;
164
+ let fake_rc_modified = FAKE_RC . strip_suffix ( '\n' ) . expect ( "Should end in a newline" ) ;
165
+ raw:: write_file ( & profile, fake_rc_modified) . unwrap ( ) ;
166
+ // Run once to to add the configuration
167
+ expect_ok ( config, & INIT_NONE ) ;
168
+ // Run twice to test that the process is idempotent
169
+ expect_ok ( config, & INIT_NONE ) ;
170
+
171
+ let new_profile = fs:: read_to_string ( & profile) . unwrap ( ) ;
172
+ let expected = FAKE_RC . to_owned ( ) + & source ( config. cargodir . display ( ) , POSIX_SH ) ;
173
+ assert_eq ! ( new_profile, expected) ;
174
+ } ) ;
175
+ }
176
+
177
+ #[ test]
178
+ fn install_adds_path_to_multiple_rc_files ( ) {
179
+ clitools:: setup ( Scenario :: Empty , & |config| {
180
+ // Two RC files that are both from the same shell
181
+ let bash_profile = config. homedir . join ( ".bash_profile" ) ;
182
+ let bashrc = config. homedir . join ( ".bashrc" ) ;
183
+
184
+ let expected = FAKE_RC . to_owned ( ) + & source ( config. cargodir . display ( ) , POSIX_SH ) ;
185
+
186
+ // The order that the two files are processed isn't known, so test both orders
187
+ for [ path1, path2] in & [ [ & bash_profile, & bashrc] , [ & bashrc, & bash_profile] ] {
188
+ raw:: write_file ( & path1, & expected) . unwrap ( ) ;
189
+ raw:: write_file ( & path2, FAKE_RC ) . unwrap ( ) ;
190
+
191
+ expect_ok ( config, & INIT_NONE ) ;
192
+
193
+ let new1 = fs:: read_to_string ( & path1) . unwrap ( ) ;
194
+ assert_eq ! ( new1, expected) ;
195
+ let new2 = fs:: read_to_string ( & path2) . unwrap ( ) ;
196
+ assert_eq ! ( new2, expected) ;
197
+ }
198
+ } ) ;
199
+ }
200
+
160
201
#[ test]
161
202
fn uninstall_removes_source_from_rcs ( ) {
162
203
clitools:: setup ( Scenario :: Empty , & |config| {
0 commit comments