|
1 |
| -use crate::utils::helpers::{check_cfg_arg, extract_beta_rev, hex_encode, make}; |
2 |
| -use std::path::PathBuf; |
| 1 | +use crate::{ |
| 2 | + utils::helpers::{ |
| 3 | + check_cfg_arg, extract_beta_rev, hex_encode, make, program_out_of_date, symlink_dir, |
| 4 | + }, |
| 5 | + Config, |
| 6 | +}; |
| 7 | +use std::{ |
| 8 | + fs::{self, remove_file, File}, |
| 9 | + io::Write, |
| 10 | + path::PathBuf, |
| 11 | +}; |
3 | 12 |
|
4 | 13 | #[test]
|
5 | 14 | fn test_make() {
|
@@ -70,3 +79,38 @@ fn test_check_cfg_arg() {
|
70 | 79 | "--check-cfg=cfg(target_os,values(\"nixos\",\"nix2\"))"
|
71 | 80 | );
|
72 | 81 | }
|
| 82 | + |
| 83 | +#[test] |
| 84 | +fn test_program_out_of_date() { |
| 85 | + let config = Config::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]); |
| 86 | + let tempfile = config.tempdir().join(".tmp-stamp-file"); |
| 87 | + File::create(&tempfile).unwrap().write_all(b"dummy value").unwrap(); |
| 88 | + assert!(tempfile.exists()); |
| 89 | + |
| 90 | + // up-to-date |
| 91 | + assert!(!program_out_of_date(&tempfile, "dummy value")); |
| 92 | + // out-of-date |
| 93 | + assert!(program_out_of_date(&tempfile, "")); |
| 94 | + |
| 95 | + remove_file(tempfile).unwrap(); |
| 96 | +} |
| 97 | + |
| 98 | +#[test] |
| 99 | +fn test_symlink_dir() { |
| 100 | + let config = Config::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]); |
| 101 | + let tempdir = config.tempdir().join(".tmp-dir"); |
| 102 | + let link_path = config.tempdir().join(".tmp-link"); |
| 103 | + |
| 104 | + fs::create_dir_all(&tempdir).unwrap(); |
| 105 | + symlink_dir(&config, &tempdir, &link_path).unwrap(); |
| 106 | + |
| 107 | + let link_source = fs::read_link(&link_path).unwrap(); |
| 108 | + assert_eq!(link_source, tempdir); |
| 109 | + |
| 110 | + fs::remove_dir(tempdir).unwrap(); |
| 111 | + |
| 112 | + #[cfg(windows)] |
| 113 | + fs::remove_dir(link_path).unwrap(); |
| 114 | + #[cfg(not(windows))] |
| 115 | + fs::remove_file(link_path).unwrap(); |
| 116 | +} |
0 commit comments