@@ -355,6 +355,13 @@ fn executable_exists(repo: &Path, short_name: &str) -> bool {
355355 os:: path_exists ( & exec) && is_rwx ( & exec)
356356}
357357
358+ fn remove_executable_file ( p : & PkgId , workspace : & Path ) {
359+ let exec = target_executable_in_workspace ( & PkgId :: new ( p. short_name ) , workspace) ;
360+ if os:: path_exists ( & exec) {
361+ assert ! ( os:: remove_file( & exec) ) ;
362+ }
363+ }
364+
358365fn assert_built_executable_exists ( repo : & Path , short_name : & str ) {
359366 assert ! ( built_executable_exists( repo, short_name) ) ;
360367}
@@ -368,6 +375,14 @@ fn built_executable_exists(repo: &Path, short_name: &str) -> bool {
368375 }
369376}
370377
378+ fn remove_built_executable_file ( p : & PkgId , workspace : & Path ) {
379+ let exec = built_executable_in_workspace ( & PkgId :: new ( p. short_name ) , workspace) ;
380+ match exec {
381+ Some ( r) => assert ! ( os:: remove_file( & r) ) ,
382+ None => ( )
383+ }
384+ }
385+
371386fn object_file_exists ( repo : & Path , short_name : & str ) -> bool {
372387 file_exists ( repo, short_name, "o" )
373388}
@@ -1705,6 +1720,44 @@ fn test_dependencies_terminate() {
17051720 command_line_test([~" install", ~" b"], &workspace);
17061721}
17071722
1723+ #[test]
1724+ fn install_after_build() {
1725+ let b_id = PkgId::new(" b");
1726+ let workspace = create_local_package(&b_id);
1727+ command_line_test([~" build", ~" b"], &workspace);
1728+ command_line_test([~" install", ~" b"], &workspace);
1729+ assert_executable_exists(&workspace, b_id.short_name);
1730+ assert_lib_exists(&workspace, &b_id.path, NoVersion);
1731+ }
1732+
1733+ #[test]
1734+ fn reinstall() {
1735+ let b = PkgId::new(" b");
1736+ let workspace = create_local_package(&b);
1737+ // 1. Install, then remove executable file, then install again,
1738+ // and make sure executable was re-installed
1739+ command_line_test([~" install", ~" b"], &workspace);
1740+ assert_executable_exists(&workspace, b.short_name);
1741+ assert_lib_exists(&workspace, &b.path, NoVersion);
1742+ remove_executable_file(&b, &workspace);
1743+ command_line_test([~" install", ~" b"], &workspace);
1744+ assert_executable_exists(&workspace, b.short_name);
1745+ // 2. Build, then remove build executable file, then build again,
1746+ // and make sure executable was re-built.
1747+ command_line_test([~" build", ~" b"], &workspace);
1748+ remove_built_executable_file(&b, &workspace);
1749+ command_line_test([~" build", ~" b"], &workspace);
1750+ assert_built_executable_exists(&workspace, b.short_name);
1751+ // 3. Install, then remove both executable and built executable,
1752+ // then install again, make sure both were recreated
1753+ command_line_test([~" install", ~" b"], &workspace);
1754+ remove_executable_file(&b, &workspace);
1755+ remove_built_executable_file(&b, &workspace);
1756+ command_line_test([~" install", ~" b"], &workspace);
1757+ assert_executable_exists(&workspace, b.short_name);
1758+ assert_built_executable_exists(&workspace, b.short_name);
1759+ }
1760+
17081761/// Returns true if p exists and is executable
17091762fn is_executable(p: &Path) -> bool {
17101763 use std::libc::consts::os::posix88::{S_IXUSR};
0 commit comments