2016-07-12 18:56:21 +00:00
|
|
|
use common::util::*;
|
2016-07-13 13:29:24 +00:00
|
|
|
use std::os::unix::fs::PermissionsExt;
|
2016-07-12 18:56:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_help() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (_, mut ucmd) = at_and_ucmd!();
|
2016-07-12 18:56:21 +00:00
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
assert!(
|
2016-08-14 01:37:48 +00:00
|
|
|
ucmd.arg("--help").succeeds().no_stderr().stdout.contains("Options:"));
|
2016-07-12 18:56:21 +00:00
|
|
|
}
|
2016-07-12 20:58:44 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_basic() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2016-07-13 08:37:08 +00:00
|
|
|
let dir = "test_install_target_dir_dir_a";
|
2016-07-13 10:27:11 +00:00
|
|
|
let file1 = "test_install_target_dir_file_a1";
|
|
|
|
let file2 = "test_install_target_dir_file_a2";
|
2016-07-12 20:58:44 +00:00
|
|
|
|
2016-07-13 10:27:11 +00:00
|
|
|
at.touch(file1);
|
|
|
|
at.touch(file2);
|
2016-07-12 20:58:44 +00:00
|
|
|
at.mkdir(dir);
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.arg(file1).arg(file2).arg(dir).succeeds().no_stderr();
|
2016-07-12 20:58:44 +00:00
|
|
|
|
2016-07-13 10:27:11 +00:00
|
|
|
assert!(at.file_exists(file1));
|
|
|
|
assert!(at.file_exists(file2));
|
|
|
|
assert!(at.file_exists(&format!("{}/{}", dir, file1)));
|
|
|
|
assert!(at.file_exists(&format!("{}/{}", dir, file2)));
|
2016-07-12 20:58:44 +00:00
|
|
|
}
|
2016-07-13 08:37:08 +00:00
|
|
|
|
2017-12-27 08:31:19 +00:00
|
|
|
#[test]
|
|
|
|
fn test_install_failing_not_dir() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let file1 = "test_install_target_dir_file_a1";
|
|
|
|
let file2 = "test_install_target_dir_file_a2";
|
|
|
|
let file3 = "test_install_target_dir_file_a3";
|
|
|
|
|
|
|
|
at.touch(file1);
|
|
|
|
at.touch(file2);
|
|
|
|
at.touch(file3);
|
|
|
|
assert!(ucmd.arg(file1).arg(file2).arg(file3)
|
|
|
|
.fails().stderr.contains("not a directory"));
|
|
|
|
}
|
|
|
|
|
2016-07-13 08:37:08 +00:00
|
|
|
#[test]
|
|
|
|
fn test_install_unimplemented_arg() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2016-07-13 08:37:08 +00:00
|
|
|
let dir = "test_install_target_dir_dir_b";
|
|
|
|
let file = "test_install_target_dir_file_b";
|
|
|
|
let context_arg = "--context";
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
at.mkdir(dir);
|
2016-08-13 21:59:21 +00:00
|
|
|
assert!(ucmd.arg(context_arg).arg(file).arg(dir)
|
|
|
|
.fails().stderr.contains("Unimplemented"));
|
2016-07-13 08:37:08 +00:00
|
|
|
|
|
|
|
assert!(!at.file_exists(&format!("{}/{}", dir, file)));
|
|
|
|
}
|
2016-07-13 10:53:22 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_component_directories() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2016-07-13 10:53:22 +00:00
|
|
|
let component1 = "test_install_target_dir_component_c1";
|
|
|
|
let component2 = "test_install_target_dir_component_c2";
|
|
|
|
let component3 = "test_install_target_dir_component_c3";
|
|
|
|
let directories_arg = "-d";
|
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.args(&[directories_arg, component1, component2, component3])
|
|
|
|
.succeeds().no_stderr();
|
2016-07-13 10:53:22 +00:00
|
|
|
|
|
|
|
assert!(at.dir_exists(component1));
|
|
|
|
assert!(at.dir_exists(component2));
|
|
|
|
assert!(at.dir_exists(component3));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_component_directories_failing() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2016-07-13 10:53:22 +00:00
|
|
|
let component = "test_install_target_dir_component_d1";
|
|
|
|
let directories_arg = "-d";
|
|
|
|
|
|
|
|
at.mkdir(component);
|
2016-08-13 21:59:21 +00:00
|
|
|
assert!(ucmd.arg(directories_arg).arg(component)
|
|
|
|
.fails().stderr.contains("File exists"));
|
2016-07-13 10:53:22 +00:00
|
|
|
}
|
2016-07-13 13:29:24 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_mode_numeric() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2016-07-13 13:29:24 +00:00
|
|
|
let dir = "test_install_target_dir_dir_e";
|
|
|
|
let file = "test_install_target_dir_file_e";
|
|
|
|
let mode_arg = "--mode=333";
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
at.mkdir(dir);
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.arg(file).arg(dir).arg(mode_arg).succeeds().no_stderr();
|
2016-07-13 13:29:24 +00:00
|
|
|
|
|
|
|
let dest_file = &format!("{}/{}", dir, file);
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
assert!(at.file_exists(dest_file));
|
|
|
|
let permissions = at.metadata(dest_file).permissions();
|
2017-12-05 22:53:40 +00:00
|
|
|
assert_eq!(0o100333 as u32, PermissionsExt::mode(&permissions));
|
2016-07-13 13:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_mode_symbolic() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2016-07-13 13:29:24 +00:00
|
|
|
let dir = "test_install_target_dir_dir_f";
|
|
|
|
let file = "test_install_target_dir_file_f";
|
|
|
|
let mode_arg = "--mode=o+wx";
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
at.mkdir(dir);
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.arg(file).arg(dir).arg(mode_arg).succeeds().no_stderr();
|
2016-07-13 13:29:24 +00:00
|
|
|
|
|
|
|
let dest_file = &format!("{}/{}", dir, file);
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
assert!(at.file_exists(dest_file));
|
|
|
|
let permissions = at.metadata(dest_file).permissions();
|
2017-12-05 22:53:40 +00:00
|
|
|
assert_eq!(0o100003 as u32, PermissionsExt::mode(&permissions));
|
2016-07-13 13:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_mode_failing() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2016-07-13 13:29:24 +00:00
|
|
|
let dir = "test_install_target_dir_dir_g";
|
|
|
|
let file = "test_install_target_dir_file_g";
|
|
|
|
let mode_arg = "--mode=999";
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
at.mkdir(dir);
|
2016-08-13 21:59:21 +00:00
|
|
|
assert!(ucmd.arg(file).arg(dir).arg(mode_arg)
|
2017-12-11 04:11:05 +00:00
|
|
|
.fails().stderr.contains("Invalid mode string: invalid digit found in string"));
|
2016-07-13 13:29:24 +00:00
|
|
|
|
|
|
|
let dest_file = &format!("{}/{}", dir, file);
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
assert!(!at.file_exists(dest_file));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_mode_directories() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2016-07-13 13:29:24 +00:00
|
|
|
let component = "test_install_target_dir_component_h";
|
|
|
|
let directories_arg = "-d";
|
|
|
|
let mode_arg = "--mode=333";
|
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.arg(directories_arg).arg(component).arg(mode_arg).succeeds().no_stderr();
|
2016-07-13 13:29:24 +00:00
|
|
|
|
|
|
|
assert!(at.dir_exists(component));
|
|
|
|
let permissions = at.metadata(component).permissions();
|
2017-12-05 22:53:40 +00:00
|
|
|
assert_eq!(0o040333 as u32, PermissionsExt::mode(&permissions));
|
2016-07-13 13:29:24 +00:00
|
|
|
}
|
2017-12-27 08:31:19 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_target_file() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let file1 = "test_install_target_file_file_i1";
|
|
|
|
let file2 = "test_install_target_file_file_i2";
|
|
|
|
|
|
|
|
at.touch(file1);
|
|
|
|
at.touch(file2);
|
|
|
|
ucmd.arg(file1).arg(file2).succeeds().no_stderr();
|
|
|
|
|
|
|
|
assert!(at.file_exists(file1));
|
|
|
|
assert!(at.file_exists(file2));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_target_new_file() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let file = "test_install_target_new_filer_file_j";
|
|
|
|
let dir = "test_install_target_new_file_dir_j";
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
at.mkdir(dir);
|
|
|
|
ucmd.arg(file).arg(format!("{}/{}", dir, file)).succeeds().no_stderr();
|
|
|
|
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
assert!(at.file_exists(&format!("{}/{}", dir, file)));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_target_new_file_failing_nonexistent_parent() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let file1 = "test_install_target_new_file_failing_file_k1";
|
|
|
|
let file2 = "test_install_target_new_file_failing_file_k2";
|
|
|
|
let dir = "test_install_target_new_file_failing_dir_k";
|
|
|
|
|
|
|
|
at.touch(file1);
|
|
|
|
|
|
|
|
let err = ucmd.arg(file1).arg(format!("{}/{}", dir, file2))
|
|
|
|
.fails().stderr;
|
|
|
|
|
|
|
|
assert!(err.contains("not a directory"))
|
|
|
|
}
|
|
|
|
|