|
1 | 1 | use std::{ffi::OsStr, thread, time::Duration, time::Instant}; |
2 | 2 |
|
3 | | -use xshell::{cmd, cwd, mkdir_p, pushd, pushenv, read_file, rm_rf, write_file}; |
| 3 | +use xshell::{cmd, cp, cwd, mkdir_p, mktemp_d, pushd, pushenv, read_file, rm_rf, write_file}; |
4 | 4 |
|
5 | 5 | #[test] |
6 | 6 | fn smoke() { |
@@ -208,6 +208,28 @@ fn test_pushenv_lock() { |
208 | 208 | t2.join().unwrap(); |
209 | 209 | } |
210 | 210 |
|
| 211 | +#[test] |
| 212 | +fn test_cp() { |
| 213 | + let path; |
| 214 | + { |
| 215 | + let tempdir = mktemp_d().unwrap(); |
| 216 | + path = tempdir.path().to_path_buf(); |
| 217 | + let foo = tempdir.path().join("foo.txt"); |
| 218 | + let bar = tempdir.path().join("bar.txt"); |
| 219 | + let dir = tempdir.path().join("dir"); |
| 220 | + write_file(&foo, "hello world").unwrap(); |
| 221 | + mkdir_p(&dir).unwrap(); |
| 222 | + |
| 223 | + cp(&foo, &bar).unwrap(); |
| 224 | + assert_eq!(read_file(&bar).unwrap(), "hello world"); |
| 225 | + |
| 226 | + cp(&foo, &dir).unwrap(); |
| 227 | + assert_eq!(read_file(&dir.join("foo.txt")).unwrap(), "hello world"); |
| 228 | + assert!(path.exists()); |
| 229 | + } |
| 230 | + assert!(!path.exists()); |
| 231 | +} |
| 232 | + |
211 | 233 | fn check_failure(code: &str, err_msg: &str) { |
212 | 234 | mkdir_p("./target/cf").unwrap(); |
213 | 235 | let _p = pushd("./target/cf").unwrap(); |
|
0 commit comments