@@ -1808,3 +1808,159 @@ fn test_install_symlink_same_file() {
1808
1808
"'{target_dir}/{file}' and '{target_link}/{file}' are the same file"
1809
1809
) ) ;
1810
1810
}
1811
+
1812
+ #[ test]
1813
+ fn test_install_no_target_directory_failing_cannot_overwrite ( ) {
1814
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
1815
+ let at = & scene. fixtures ;
1816
+ let file = "file" ;
1817
+ let dir = "dir" ;
1818
+
1819
+ at. touch ( file) ;
1820
+ at. mkdir ( dir) ;
1821
+ scene
1822
+ . ucmd ( )
1823
+ . arg ( "-T" )
1824
+ . arg ( file)
1825
+ . arg ( dir)
1826
+ . fails ( )
1827
+ . stderr_contains ( "cannot overwrite directory 'dir' with non-directory" ) ;
1828
+
1829
+ assert ! ( !at. dir_exists( "dir/file" ) ) ;
1830
+ }
1831
+
1832
+ #[ test]
1833
+ fn test_install_no_target_directory_failing_omitting_directory ( ) {
1834
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
1835
+ let at = & scene. fixtures ;
1836
+ let dir1 = "dir1" ;
1837
+ let dir2 = "dir2" ;
1838
+
1839
+ at. mkdir ( dir1) ;
1840
+ at. mkdir ( dir2) ;
1841
+ scene
1842
+ . ucmd ( )
1843
+ . arg ( "-T" )
1844
+ . arg ( dir1)
1845
+ . arg ( dir2)
1846
+ . fails ( )
1847
+ . stderr_contains ( "omitting directory 'dir1'" ) ;
1848
+ }
1849
+
1850
+ #[ test]
1851
+ fn test_install_no_target_directory_creating_leading_dirs_with_single_source_and_target_dir ( ) {
1852
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
1853
+ let at = & scene. fixtures ;
1854
+
1855
+ let source1 = "file" ;
1856
+ let target_dir = "missing_target_dir/" ;
1857
+
1858
+ at. touch ( source1) ;
1859
+
1860
+ // installing a single file into a missing directory will fail, when -D is used w/o -t parameter
1861
+ scene
1862
+ . ucmd ( )
1863
+ . arg ( "-TD" )
1864
+ . arg ( source1)
1865
+ . arg ( at. plus ( target_dir) )
1866
+ . fails ( )
1867
+ . stderr_contains ( "missing_target_dir/' is not a directory" ) ;
1868
+
1869
+ assert ! ( !at. dir_exists( target_dir) ) ;
1870
+ }
1871
+
1872
+ #[ test]
1873
+ fn test_install_no_target_directory_failing_combine_with_target_directory ( ) {
1874
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
1875
+ let at = & scene. fixtures ;
1876
+ let file = "file" ;
1877
+ let dir1 = "dir1" ;
1878
+
1879
+ at. touch ( file) ;
1880
+ at. mkdir ( dir1) ;
1881
+ scene
1882
+ . ucmd ( )
1883
+ . arg ( "-T" )
1884
+ . arg ( file)
1885
+ . arg ( "-t" )
1886
+ . arg ( dir1)
1887
+ . fails ( )
1888
+ . stderr_contains (
1889
+ "Options --target-directory and --no-target-directory are mutually exclusive" ,
1890
+ ) ;
1891
+ }
1892
+
1893
+ #[ test]
1894
+ fn test_install_no_target_directory_failing_usage_with_target_directory ( ) {
1895
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
1896
+ let at = & scene. fixtures ;
1897
+ let file = "file" ;
1898
+
1899
+ at. touch ( file) ;
1900
+ scene
1901
+ . ucmd ( )
1902
+ . arg ( "-T" )
1903
+ . arg ( file)
1904
+ . arg ( "-t" )
1905
+ . fails ( )
1906
+ . stderr_contains (
1907
+ "a value is required for '--target-directory <DIRECTORY>' but none was supplied" ,
1908
+ )
1909
+ . stderr_contains ( "For more information, try '--help'" ) ;
1910
+ }
1911
+
1912
+ #[ test]
1913
+ fn test_install_no_target_multiple_sources_and_target_dir ( ) {
1914
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
1915
+ let at = & scene. fixtures ;
1916
+
1917
+ let file1 = "file1" ;
1918
+ let file2 = "file2" ;
1919
+ let dir1 = "dir1" ;
1920
+ let dir2 = "dir2" ;
1921
+
1922
+ at. touch ( file1) ;
1923
+ at. touch ( file2) ;
1924
+ at. mkdir ( dir1) ;
1925
+ at. mkdir ( dir2) ;
1926
+
1927
+ // installing multiple files into a missing directory will fail, when -D is used w/o -t parameter
1928
+ scene
1929
+ . ucmd ( )
1930
+ . arg ( "-T" )
1931
+ . arg ( file1)
1932
+ . arg ( file2)
1933
+ . arg ( dir1)
1934
+ . fails ( )
1935
+ . stderr_contains ( "extra operand 'dir1'" )
1936
+ . stderr_contains ( "[OPTION]... [FILE]..." ) ;
1937
+
1938
+ scene
1939
+ . ucmd ( )
1940
+ . arg ( "-T" )
1941
+ . arg ( file1)
1942
+ . arg ( file2)
1943
+ . arg ( dir1)
1944
+ . arg ( dir2)
1945
+ . fails ( )
1946
+ . stderr_contains ( "extra operand 'dir1'" )
1947
+ . stderr_contains ( "[OPTION]... [FILE]..." ) ;
1948
+ }
1949
+
1950
+ #[ test]
1951
+ fn test_install_no_target_basic ( ) {
1952
+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
1953
+ let file = "file" ;
1954
+ let dir = "dir" ;
1955
+
1956
+ at. touch ( file) ;
1957
+ at. mkdir ( dir) ;
1958
+ ucmd. arg ( "-T" )
1959
+ . arg ( file)
1960
+ . arg ( format ! ( "{dir}/{file}" ) )
1961
+ . succeeds ( )
1962
+ . no_stderr ( ) ;
1963
+
1964
+ assert ! ( at. file_exists( file) ) ;
1965
+ assert ! ( at. file_exists( format!( "{dir}/{file}" ) ) ) ;
1966
+ }
0 commit comments