A fixture directory is deleted by the test that made it
Browse files at this commit5c391249b3c0641c97018ebbdec7126b302e1104Parent: ad9f1ba- test
- a fixture directory is deleted by the test that made it
28 changed files +231 -131
- crates/app/src/keymap.rs +4 -2
- crates/app/src/main.rs +1 -2
- crates/engine/src/edith.rs +1 -3
- crates/engine/src/lib.rs +1 -0
- crates/engine/src/mux.rs +8 -6
- crates/engine/src/scratch.rs +130 -0
- crates/engine/tests/audio_decode.rs +2 -1
- crates/engine/tests/audio_export.rs +6 -8
- crates/engine/tests/audio_files.rs +5 -13
- crates/engine/tests/audio_streams.rs +3 -2
- crates/engine/tests/av1.rs +6 -8
- crates/engine/tests/backends.rs +3 -5
- crates/engine/tests/color.rs +2 -2
- crates/engine/tests/eq_audio.rs +3 -4
- crates/engine/tests/export.rs +7 -8
- crates/engine/tests/export_subs.rs +4 -6
- crates/engine/tests/hevc.rs +3 -4
- crates/engine/tests/hevc_export.rs +4 -6
- crates/engine/tests/hevc_hvc1.rs +2 -2
- crates/engine/tests/images.rs +6 -13
- crates/engine/tests/lanes.rs +6 -7
- crates/engine/tests/mixed_fps.rs +5 -5
- crates/engine/tests/playback.rs +5 -6
- crates/engine/tests/saveload.rs +4 -7
- crates/engine/tests/silence.rs +2 -2
- crates/engine/tests/speed.rs +3 -2
- crates/engine/tests/subtitles.rs +3 -5
- crates/engine/tests/vp9.rs +2 -2
crates/app/src/keymap.rsmodified+4 -2
| @@ -961,6 +961,8 @@ fn parse(text: &str) -> Result<(Keymap, Vec<String>), String> { | |||
| 961 | 961 | ||
| 962 | #[cfg(test)] | 962 | #[cfg(test)] |
| 963 | mod tests { | 963 | mod tests { |
| 964 | + use engine::scratch::Scratch; | ||
| 965 | + | ||
| 964 | use super::{ActionId, Chord, Keymap, config_path_in, emit, parse}; | 966 | use super::{ActionId, Chord, Keymap, config_path_in, emit, parse}; |
| 965 | 967 | ||
| 966 | fn chord(key: &str, ctrl: bool) -> Chord { | 968 | fn chord(key: &str, ctrl: bool) -> Chord { |
| @@ -1124,7 +1126,7 @@ mod tests { | |||
| 1124 | 1126 | ||
| 1125 | // The notice names the line and the file, and the defaults do *not* | 1127 | // The notice names the line and the file, and the defaults do *not* |
| 1126 | // take over -- that was the data loss. | 1128 | // take over -- that was the data loss. |
| 1127 | - let dir = std::env::temp_dir().join(format!("edith-keymap-drop-{}", std::process::id())); | 1129 | + let dir = Scratch::dir("edith-keymap-drop"); |
| 1128 | let path = dir.join("edith").join("keybindings"); | 1130 | let path = dir.join("edith").join("keybindings"); |
| 1129 | std::fs::create_dir_all(path.parent().unwrap()).unwrap(); | 1131 | std::fs::create_dir_all(path.parent().unwrap()).unwrap(); |
| 1130 | std::fs::write(&path, text).unwrap(); | 1132 | std::fs::write(&path, text).unwrap(); |
| @@ -1230,7 +1232,7 @@ mod tests { | |||
| 1230 | #[test] | 1232 | #[test] |
| 1231 | fn a_saved_keymap_comes_back_off_the_disk() { | 1233 | fn a_saved_keymap_comes_back_off_the_disk() { |
| 1232 | // Its own directory, never the real config one: this test writes. | 1234 | // Its own directory, never the real config one: this test writes. |
| 1233 | - let dir = std::env::temp_dir().join(format!("edith-keymap-{}", std::process::id())); | 1235 | + let dir = Scratch::dir("edith-keymap"); |
| 1234 | let path = dir.join("edith").join("keybindings"); | 1236 | let path = dir.join("edith").join("keybindings"); |
| 1235 | let mut written = Keymap::defaults(); | 1237 | let mut written = Keymap::defaults(); |
| 1236 | written | 1238 | written |
crates/app/src/main.rsmodified+1 -2
| @@ -12973,8 +12973,7 @@ mod tests { | |||
| 12973 | 12973 | ||
| 12974 | // Saved and loaded back with the lanes in the order a hand-written | 12974 | // Saved and loaded back with the lanes in the order a hand-written |
| 12975 | // project may hold them: the sound last, behind the layer. | 12975 | // project may hold them: the sound last, behind the layer. |
| 12976 | - let dir = std::env::temp_dir().join(format!("ve_group_{}", std::process::id())); | 12976 | + let dir = engine::scratch::Scratch::dir("ve_group"); |
| 12977 | - std::fs::create_dir_all(&dir).expect("a scratch directory"); | ||
| 12978 | let file = dir.join("lanes.edith"); | 12977 | let file = dir.join("lanes.edith"); |
| 12979 | session.save_project(&file).expect("save the project"); | 12978 | session.save_project(&file).expect("save the project"); |
| 12980 | let text = std::fs::read_to_string(&file).expect("read it back"); | 12979 | let text = std::fs::read_to_string(&file).expect("read it back"); |
crates/engine/src/edith.rsmodified+1 -3
| @@ -1960,10 +1960,8 @@ mod tests { | |||
| 1960 | "a bare filename is saved into the working directory" | 1960 | "a bare filename is saved into the working directory" |
| 1961 | ); | 1961 | ); |
| 1962 | 1962 | ||
| 1963 | - let dir = std::env::temp_dir().join(format!("ve_edith_link_{}", std::process::id())); | 1963 | + let dir = crate::scratch::Scratch::dir("ve_edith_link"); |
| 1964 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 1965 | std::fs::create_dir_all(dir.join("real")).expect("scratch dir"); | 1964 | std::fs::create_dir_all(dir.join("real")).expect("scratch dir"); |
| 1966 | - let dir = std::fs::canonicalize(&dir).expect("canonical scratch dir"); | ||
| 1967 | std::os::unix::fs::symlink(dir.join("real"), dir.join("link")).expect("symlink"); | 1965 | std::os::unix::fs::symlink(dir.join("real"), dir.join("link")).expect("symlink"); |
| 1968 | let source = dir.join("real/a.mp4"); | 1966 | let source = dir.join("real/a.mp4"); |
| 1969 | let path = dir.join("link/p.edith"); | 1967 | let path = dir.join("link/p.edith"); |
crates/engine/src/lib.rsmodified+1 -0
| @@ -17,6 +17,7 @@ pub mod mux; | |||
| 17 | pub mod playback; | 17 | pub mod playback; |
| 18 | pub mod project; | 18 | pub mod project; |
| 19 | pub mod scale; | 19 | pub mod scale; |
| 20 | +pub mod scratch; | ||
| 20 | pub mod silence; | 21 | pub mod silence; |
| 21 | pub mod subtitle; | 22 | pub mod subtitle; |
| 22 | pub mod waveform; | 23 | pub mod waveform; |
crates/engine/src/mux.rsmodified+8 -6
| @@ -1283,6 +1283,8 @@ fn nal_type(nal: &[u8]) -> u8 { | |||
| 1283 | mod tests { | 1283 | mod tests { |
| 1284 | use std::io::BufReader; | 1284 | use std::io::BufReader; |
| 1285 | 1285 | ||
| 1286 | + use crate::scratch::Scratch; | ||
| 1287 | + | ||
| 1286 | use super::*; | 1288 | use super::*; |
| 1287 | 1289 | ||
| 1288 | const SPS: &[u8] = &[0x67, 0x42, 0x00, 0x1E, 0xAB]; | 1290 | const SPS: &[u8] = &[0x67, 0x42, 0x00, 0x1E, 0xAB]; |
| @@ -1372,7 +1374,7 @@ mod tests { | |||
| 1372 | 1374 | ||
| 1373 | #[test] | 1375 | #[test] |
| 1374 | fn create_rejects_unusable_config() { | 1376 | fn create_rejects_unusable_config() { |
| 1375 | - let out = std::env::temp_dir().join("ve_mux_never_written.mp4"); | 1377 | + let out = Scratch::file("ve_mux_never_written", "mp4"); |
| 1376 | let ok = VideoParams { | 1378 | let ok = VideoParams { |
| 1377 | width: 64, | 1379 | width: 64, |
| 1378 | height: 64, | 1380 | height: 64, |
| @@ -1420,7 +1422,7 @@ mod tests { | |||
| 1420 | au(&[&[0x41, 0x04, 0x05]]), | 1422 | au(&[&[0x41, 0x04, 0x05]]), |
| 1421 | au(&[&[0x41, 0x06]]), | 1423 | au(&[&[0x41, 0x06]]), |
| 1422 | ]; | 1424 | ]; |
| 1423 | - let out = std::env::temp_dir().join(format!("ve_mux_{}.mp4", std::process::id())); | 1425 | + let out = Scratch::file("ve_mux", "mp4"); |
| 1424 | 1426 | ||
| 1425 | let mut muxer = Mp4Muxer::create( | 1427 | let mut muxer = Mp4Muxer::create( |
| 1426 | &out, | 1428 | &out, |
| @@ -1565,7 +1567,7 @@ mod tests { | |||
| 1565 | let packets = tone_packets(48_000, 2); | 1567 | let packets = tone_packets(48_000, 2); |
| 1566 | let heard: usize = packets.iter().map(|p| p.samples as usize).sum(); | 1568 | let heard: usize = packets.iter().map(|p| p.samples as usize).sum(); |
| 1567 | 1569 | ||
| 1568 | - let out = std::env::temp_dir().join(format!("ve_mkv_sound_{}.mkv", std::process::id())); | 1570 | + let out = Scratch::file("ve_mkv_sound", "mkv"); |
| 1569 | let mut muxer = MkvMuxer::create( | 1571 | let mut muxer = MkvMuxer::create( |
| 1570 | &out, | 1572 | &out, |
| 1571 | &Av1Params { | 1573 | &Av1Params { |
| @@ -1637,7 +1639,7 @@ mod tests { | |||
| 1637 | let inter = obu(6, &[0xBB; 5]); | 1639 | let inter = obu(6, &[0xBB; 5]); |
| 1638 | let packets = tone_packets(48_000, 2); | 1640 | let packets = tone_packets(48_000, 2); |
| 1639 | 1641 | ||
| 1640 | - let out = std::env::temp_dir().join(format!("ve_mp4_av1_{}.mp4", std::process::id())); | 1642 | + let out = Scratch::file("ve_mp4_av1", "mp4"); |
| 1641 | let mut muxer = Mp4Muxer::create_av1( | 1643 | let mut muxer = Mp4Muxer::create_av1( |
| 1642 | &out, | 1644 | &out, |
| 1643 | &Av1Params { | 1645 | &Av1Params { |
| @@ -1698,7 +1700,7 @@ mod tests { | |||
| 1698 | key.extend_from_slice(&obu(6, &[0xAA; 8])); | 1700 | key.extend_from_slice(&obu(6, &[0xAA; 8])); |
| 1699 | let inter = obu(6, &[0xBB; 5]); | 1701 | let inter = obu(6, &[0xBB; 5]); |
| 1700 | 1702 | ||
| 1701 | - let out = std::env::temp_dir().join(format!("ve_mkv_{}.mkv", std::process::id())); | 1703 | + let out = Scratch::file("ve_mkv", "mkv"); |
| 1702 | let config = av1_sequence_header(&key).expect("the keyframe carries one"); | 1704 | let config = av1_sequence_header(&key).expect("the keyframe carries one"); |
| 1703 | assert_eq!(config, &sequence[..], "the sequence header OBU, whole"); | 1705 | assert_eq!(config, &sequence[..], "the sequence header OBU, whole"); |
| 1704 | let mut muxer = MkvMuxer::create( | 1706 | let mut muxer = MkvMuxer::create( |
| @@ -1769,7 +1771,7 @@ mod tests { | |||
| 1769 | #[test] | 1771 | #[test] |
| 1770 | fn an_ntsc_rate_survives_the_round_trip() { | 1772 | fn an_ntsc_rate_survives_the_round_trip() { |
| 1771 | const NTSC: f64 = 24_000.0 / 1001.0; | 1773 | const NTSC: f64 = 24_000.0 / 1001.0; |
| 1772 | - let out = std::env::temp_dir().join(format!("ve_mux_ntsc_{}.mp4", std::process::id())); | 1774 | + let out = Scratch::file("ve_mux_ntsc", "mp4"); |
| 1773 | let mut muxer = Mp4Muxer::create( | 1775 | let mut muxer = Mp4Muxer::create( |
| 1774 | &out, | 1776 | &out, |
| 1775 | &VideoParams { | 1777 | &VideoParams { |
crates/engine/src/scratch.rsadded+130 -0
| @@ -0,0 +1,130 @@ | |||
| 1 | +//! Throwaway paths for the tests, and the one rule about them: everything a | ||
| 2 | +//! test writes goes inside a directory that deletes itself. | ||
| 3 | +//! | ||
| 4 | +//! [`Scratch`] is that directory. It derefs to a path -- the directory itself, | ||
| 5 | +//! or the one file inside it -- so a helper that used to hand back a `PathBuf` | ||
| 6 | +//! hands back one of these instead and its call sites do not change. `Drop` is | ||
| 7 | +//! what cleans up, which is the whole point: unwinding runs it, so a *failing* | ||
| 8 | +//! test leaves nothing behind either. The suites used to litter `/tmp` with a | ||
| 9 | +//! fresh `ve_*` directory per run and never take one back; on this machine that | ||
| 10 | +//! reached 2907 of them. | ||
| 11 | +//! | ||
| 12 | +//! Nothing outside a test has any use for this. It lives in the library rather | ||
| 13 | +//! than in a test file because the integration suites, the unit tests here and | ||
| 14 | +//! the app's own tests all need the same guard, and none of them can see each | ||
| 15 | +//! other's modules. | ||
| 16 | + | ||
| 17 | +use std::ffi::OsStr; | ||
| 18 | +use std::ops::Deref; | ||
| 19 | +use std::path::{Path, PathBuf}; | ||
| 20 | +use std::sync::atomic::{AtomicU64, Ordering}; | ||
| 21 | + | ||
| 22 | +/// A temporary directory and the path a test uses inside it, gone when the | ||
| 23 | +/// value is. | ||
| 24 | +#[derive(Debug)] | ||
| 25 | +pub struct Scratch { | ||
| 26 | + dir: PathBuf, | ||
| 27 | + path: PathBuf, | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +/// A fresh, empty directory under the system temporary one. `name` leads it so | ||
| 31 | +/// it is recognisable while a test is stopped in it; the process id and a | ||
| 32 | +/// counter follow, because two suites (or two tests of one suite, in parallel) | ||
| 33 | +/// must not write each other's files. Canonical, because saved projects hold | ||
| 34 | +/// paths relative to their own directory and `Project` canonicalises what it is | ||
| 35 | +/// handed. | ||
| 36 | +fn fresh(name: &str) -> PathBuf { | ||
| 37 | + static NTH: AtomicU64 = AtomicU64::new(0); | ||
| 38 | + let dir = std::env::temp_dir().join(format!( | ||
| 39 | + "{name}_{}_{}", | ||
| 40 | + std::process::id(), | ||
| 41 | + NTH.fetch_add(1, Ordering::Relaxed) | ||
| 42 | + )); | ||
| 43 | + let _ = std::fs::remove_dir_all(&dir); | ||
| 44 | + std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 45 | + std::fs::canonicalize(&dir).expect("canonical scratch dir") | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +impl Scratch { | ||
| 49 | + /// A directory to litter: the value *is* the directory. | ||
| 50 | + pub fn dir(name: &str) -> Self { | ||
| 51 | + let dir = fresh(name); | ||
| 52 | + Self { | ||
| 53 | + path: dir.clone(), | ||
| 54 | + dir, | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + /// A path for the one file a test writes, `name.ext`, alone in a directory | ||
| 59 | + /// of its own. Nothing creates it -- what is under test is what writes it, | ||
| 60 | + /// and several of these tests are about a file that must *not* appear. | ||
| 61 | + pub fn file(name: &str, ext: &str) -> Self { | ||
| 62 | + let dir = fresh(name); | ||
| 63 | + let path = dir.join(format!("{name}.{ext}")); | ||
| 64 | + Self { dir, path } | ||
| 65 | + } | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +impl Deref for Scratch { | ||
| 69 | + type Target = Path; | ||
| 70 | + | ||
| 71 | + fn deref(&self) -> &Path { | ||
| 72 | + &self.path | ||
| 73 | + } | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +impl AsRef<Path> for Scratch { | ||
| 77 | + fn as_ref(&self) -> &Path { | ||
| 78 | + &self.path | ||
| 79 | + } | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +/// So one of these can be handed to a `Command` as an argument, which is how | ||
| 83 | +/// the suites that check our output with ffmpeg name the file. | ||
| 84 | +impl AsRef<OsStr> for Scratch { | ||
| 85 | + fn as_ref(&self) -> &OsStr { | ||
| 86 | + self.path.as_os_str() | ||
| 87 | + } | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | +impl Drop for Scratch { | ||
| 91 | + fn drop(&mut self) { | ||
| 92 | + let _ = std::fs::remove_dir_all(&self.dir); | ||
| 93 | + } | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +#[cfg(test)] | ||
| 97 | +mod tests { | ||
| 98 | + use super::Scratch; | ||
| 99 | + | ||
| 100 | + /// The guard's whole job, both shapes: what it hands back is usable, and | ||
| 101 | + /// what it made is gone once it is -- including when a test panicked, which | ||
| 102 | + /// is the case that leaked. | ||
| 103 | + #[test] | ||
| 104 | + fn a_scratch_takes_its_directory_with_it() { | ||
| 105 | + let (dir, file) = (Scratch::dir("ve_scratch_dir"), Scratch::file("ve_scratch", "mp4")); | ||
| 106 | + assert!(dir.is_dir(), "a directory to litter, ready to use"); | ||
| 107 | + std::fs::write(dir.join("a.txt"), b"litter").expect("write into it"); | ||
| 108 | + assert!(!file.exists(), "the file itself is the test's to write"); | ||
| 109 | + assert!(file.parent().expect("inside a directory").is_dir()); | ||
| 110 | + assert_eq!(file.extension().and_then(|e| e.to_str()), Some("mp4")); | ||
| 111 | + | ||
| 112 | + let (left, right) = (dir.to_path_buf(), file.parent().unwrap().to_path_buf()); | ||
| 113 | + assert_ne!(left, right, "one directory each, never shared"); | ||
| 114 | + drop((dir, file)); | ||
| 115 | + assert!(!left.exists(), "the directory went with the guard"); | ||
| 116 | + assert!(!right.exists(), "and so did the file's"); | ||
| 117 | + | ||
| 118 | + // Unwinding runs `Drop`, so a failing test cleans up like a passing one. | ||
| 119 | + // The panic below is this test's own and is meant to reach stderr. | ||
| 120 | + let seen = std::sync::Mutex::new(None); | ||
| 121 | + let _ = std::panic::catch_unwind(|| { | ||
| 122 | + let dir = Scratch::dir("ve_scratch_panic"); | ||
| 123 | + std::fs::write(dir.join("a.txt"), b"litter").expect("write into it"); | ||
| 124 | + *seen.lock().expect("the lock") = Some(dir.to_path_buf()); | ||
| 125 | + panic!("a test failing with a scratch directory in hand"); | ||
| 126 | + }); | ||
| 127 | + let path = seen.lock().expect("the lock").clone().expect("it ran"); | ||
| 128 | + assert!(!path.exists(), "a panicking test leaves nothing behind"); | ||
| 129 | + } | ||
| 130 | +} | ||
crates/engine/tests/audio_decode.rsmodified+2 -1
| @@ -2,6 +2,7 @@ use std::path::PathBuf; | |||
| 2 | use std::time::Instant; | 2 | use std::time::Instant; |
| 3 | 3 | ||
| 4 | use engine::audio::AudioSession; | 4 | use engine::audio::AudioSession; |
| 5 | +use engine::scratch::Scratch; | ||
| 5 | 6 | ||
| 6 | const RATE: u32 = 44100; | 7 | const RATE: u32 = 44100; |
| 7 | const SECONDS: u32 = 5; | 8 | const SECONDS: u32 = 5; |
| @@ -297,7 +298,7 @@ fn a_matroska_with_no_track_is_silent_and_a_broken_one_is_an_error() { | |||
| 297 | 298 | ||
| 298 | // ...and a file that will not parse at all, under the same extension: an | 299 | // ...and a file that will not parse at all, under the same extension: an |
| 299 | // `Err` a front-end can show, not a silent import. | 300 | // `Err` a front-end can show, not a silent import. |
| 300 | - let broken = std::env::temp_dir().join(format!("ve_broken_{}.mkv", std::process::id())); | 301 | + let broken = Scratch::file("ve_broken", "mkv"); |
| 301 | std::fs::write(&broken, b"\x1a\x45\xdf\xa3not a matroska file at all").expect("write"); | 302 | std::fs::write(&broken, b"\x1a\x45\xdf\xa3not a matroska file at all").expect("write"); |
| 302 | let err = AudioSession::probe(&broken, 0) | 303 | let err = AudioSession::probe(&broken, 0) |
| 303 | .expect_err("a broken file must not pass for a silent one") | 304 | .expect_err("a broken file must not pass for a silent one") |
crates/engine/tests/audio_export.rsmodified+6 -8
| @@ -21,6 +21,7 @@ use mp4::{MediaType, Mp4Reader}; | |||
| 21 | use engine::export::{ExportSettings, Format}; | 21 | use engine::export::{ExportSettings, Format}; |
| 22 | use engine::project::{Lane, LaneKind, Source, Speed}; | 22 | use engine::project::{Lane, LaneKind, Source, Speed}; |
| 23 | use engine::scale::FitPolicy; | 23 | use engine::scale::FitPolicy; |
| 24 | +use engine::scratch::Scratch; | ||
| 24 | use engine::{AudioSession, Clip, ExportHandle, Project}; | 25 | use engine::{AudioSession, Clip, ExportHandle, Project}; |
| 25 | 26 | ||
| 26 | const RATE: u32 = 44_100; | 27 | const RATE: u32 = 44_100; |
| @@ -31,13 +32,10 @@ fn asset(name: &str) -> PathBuf { | |||
| 31 | .join(name) | 32 | .join(name) |
| 32 | } | 33 | } |
| 33 | 34 | ||
| 34 | -/// Per-run unique, like the mp4 suite's: two suites at once must not delete | 35 | +/// Its own directory, gone with the value: two suites at once must not delete |
| 35 | -/// each other's output. | 36 | +/// each other's output, and nothing may outlive the test that wrote it. |
| 36 | -fn out_path(name: &str, ext: &str) -> PathBuf { | 37 | +fn out_path(name: &str, ext: &str) -> Scratch { |
| 37 | - let path = std::env::temp_dir().join(format!("ve_audio_{name}_{}.{ext}", std::process::id())); | 38 | + Scratch::file(&format!("ve_audio_{name}"), ext) |
| 38 | - let _ = std::fs::remove_file(&path); | ||
| 39 | - let _ = std::fs::remove_file(part_path(&path)); | ||
| 40 | - path | ||
| 41 | } | 39 | } |
| 42 | 40 | ||
| 43 | fn part_path(out: &Path) -> PathBuf { | 41 | fn part_path(out: &Path) -> PathBuf { |
| @@ -900,7 +898,7 @@ fn a_mono_timeline_exports_as_dual_mono_ogg() { | |||
| 900 | std::fs::write(&src, &wav).expect("write the mono fixture"); | 898 | std::fs::write(&src, &wav).expect("write the mono fixture"); |
| 901 | 899 | ||
| 902 | let project = Project::from_parts( | 900 | let project = Project::from_parts( |
| 903 | - vec![Source::new(src.clone(), 0)], | 901 | + vec![Source::new(src.to_path_buf(), 0)], |
| 904 | vec![( | 902 | vec![( |
| 905 | LaneKind::Audio, | 903 | LaneKind::Audio, |
| 906 | vec![Clip { | 904 | vec![Clip { |
crates/engine/tests/audio_files.rsmodified+5 -13
| @@ -12,6 +12,7 @@ use std::path::{Path, PathBuf}; | |||
| 12 | 12 | ||
| 13 | use engine::export::{ExportSettings, Format}; | 13 | use engine::export::{ExportSettings, Format}; |
| 14 | use engine::project::Lane; | 14 | use engine::project::Lane; |
| 15 | +use engine::scratch::Scratch; | ||
| 15 | use engine::{AudioSession, Clip, PlaybackSession}; | 16 | use engine::{AudioSession, Clip, PlaybackSession}; |
| 16 | 17 | ||
| 17 | /// The fixtures `scripts/gen_fixtures.sh` writes: 3 s of 440 Hz left / 880 Hz | 18 | /// The fixtures `scripts/gen_fixtures.sh` writes: 3 s of 440 Hz left / 880 Hz |
| @@ -233,14 +234,11 @@ fn a_song_is_a_timeline_of_its_own() { | |||
| 233 | /// timeline: refused at the door, in the words of whatever refused it. | 234 | /// timeline: refused at the door, in the words of whatever refused it. |
| 234 | #[test] | 235 | #[test] |
| 235 | fn a_file_with_no_picture_and_no_sound_is_still_refused() { | 236 | fn a_file_with_no_picture_and_no_sound_is_still_refused() { |
| 236 | - let dir = std::env::temp_dir().join(format!("ve_audio_bad_{}", std::process::id())); | 237 | + let dir = Scratch::dir("ve_audio_bad"); |
| 237 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 238 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 239 | let fake = dir.join("not_really.mp3"); | 238 | let fake = dir.join("not_really.mp3"); |
| 240 | std::fs::write(&fake, b"this is not an mp3").expect("write"); | 239 | std::fs::write(&fake, b"this is not an mp3").expect("write"); |
| 241 | let e = refusal(PlaybackSession::open(&fake)); | 240 | let e = refusal(PlaybackSession::open(&fake)); |
| 242 | assert!(e.starts_with(&fake.display().to_string()), "{e}"); | 241 | assert!(e.starts_with(&fake.display().to_string()), "{e}"); |
| 243 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 244 | } | 242 | } |
| 245 | 243 | ||
| 246 | /// The whole audio-only round trip a user makes: open a song, place a second | 244 | /// The whole audio-only round trip a user makes: open a song, place a second |
| @@ -248,9 +246,7 @@ fn a_file_with_no_picture_and_no_sound_is_still_refused() { | |||
| 248 | /// format that needs a picture cannot have one. | 246 | /// format that needs a picture cannot have one. |
| 249 | #[test] | 247 | #[test] |
| 250 | fn an_audio_only_project_saves_reloads_and_exports_its_sound() { | 248 | fn an_audio_only_project_saves_reloads_and_exports_its_sound() { |
| 251 | - let dir = std::env::temp_dir().join(format!("ve_audio_only_{}", std::process::id())); | 249 | + let dir = Scratch::dir("ve_audio_only"); |
| 252 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 253 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 254 | 250 | ||
| 255 | let mut session = open(asset("test_tone.mp3")); | 251 | let mut session = open(asset("test_tone.mp3")); |
| 256 | // A second song joins it, the same way one joins a timeline of video: no | 252 | // A second song joins it, the same way one joins a timeline of video: no |
| @@ -440,9 +436,7 @@ fn an_export_refuses_audio_it_cannot_copy() { | |||
| 440 | 436 | ||
| 441 | #[test] | 437 | #[test] |
| 442 | fn a_song_survives_a_save_and_a_reload() { | 438 | fn a_song_survives_a_save_and_a_reload() { |
| 443 | - let dir = std::env::temp_dir().join(format!("ve_audio_files_{}", std::process::id())); | 439 | + let dir = Scratch::dir("ve_audio_files"); |
| 444 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 445 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 446 | let copy = |name: &str| { | 440 | let copy = |name: &str| { |
| 447 | let to = dir.join(name); | 441 | let to = dir.join(name); |
| 448 | std::fs::copy(asset(name), &to).expect("copy the fixture"); | 442 | std::fs::copy(asset(name), &to).expect("copy the fixture"); |
| @@ -508,9 +502,7 @@ fn a_song_survives_a_save_and_a_reload() { | |||
| 508 | /// hand-editing anywhere in it. | 502 | /// hand-editing anywhere in it. |
| 509 | #[test] | 503 | #[test] |
| 510 | fn a_pasted_song_never_lands_on_the_video_lane() { | 504 | fn a_pasted_song_never_lands_on_the_video_lane() { |
| 511 | - let dir = std::env::temp_dir().join(format!("ve_audio_paste_{}", std::process::id())); | 505 | + let dir = Scratch::dir("ve_audio_paste"); |
| 512 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 513 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 514 | let copy = |name: &str| { | 506 | let copy = |name: &str| { |
| 515 | let to = dir.join(name); | 507 | let to = dir.join(name); |
| 516 | std::fs::copy(asset(name), &to).expect("copy the fixture"); | 508 | std::fs::copy(asset(name), &to).expect("copy the fixture"); |
crates/engine/tests/audio_streams.rsmodified+3 -2
| @@ -5,6 +5,7 @@ | |||
| 5 | use std::path::PathBuf; | 5 | use std::path::PathBuf; |
| 6 | 6 | ||
| 7 | use engine::audio::{AudioSession, StreamInfo}; | 7 | use engine::audio::{AudioSession, StreamInfo}; |
| 8 | +use engine::scratch::Scratch; | ||
| 8 | 9 | ||
| 9 | /// Three audio streams: 0 is AAC 44.1k stereo (440/880 Hz, und), 1 is AAC | 10 | /// Three audio streams: 0 is AAC 44.1k stereo (440/880 Hz, und), 1 is AAC |
| 10 | /// 22.05k mono (220 Hz, fra), 2 is AC-3, which we cannot decode. | 11 | /// 22.05k mono (220 Hz, fra), 2 is AC-3, which we cannot decode. |
| @@ -197,7 +198,7 @@ fn flag_default_on_a_later_track_is_still_stream_0() { | |||
| 197 | "the fixture stopped carrying an explicit FlagDefault=0" | 198 | "the fixture stopped carrying an explicit FlagDefault=0" |
| 198 | ); | 199 | ); |
| 199 | bytes[at + 2] = 1; | 200 | bytes[at + 2] = 1; |
| 200 | - let patched = std::env::temp_dir().join(format!("ve_flagdefault_{}.mkv", std::process::id())); | 201 | + let patched = Scratch::file("ve_flagdefault", "mkv"); |
| 201 | std::fs::write(&patched, &bytes).expect("write the patched file"); | 202 | std::fs::write(&patched, &bytes).expect("write the patched file"); |
| 202 | 203 | ||
| 203 | // The flagged track leads: it is what `AudioSession::open` played before | 204 | // The flagged track leads: it is what `AudioSession::open` played before |
| @@ -215,7 +216,7 @@ fn flag_default_on_a_later_track_is_still_stream_0() { | |||
| 215 | // track's tone, sample for sample what the wrapper hands out. | 216 | // track's tone, sample for sample what the wrapper hands out. |
| 216 | let (wrapped, rx) = AudioSession::open(&patched).expect("opens").expect("audio"); | 217 | let (wrapped, rx) = AudioSession::open(&patched).expect("opens").expect("audio"); |
| 217 | let played: Vec<f32> = rx.into_iter().flat_map(|c| c.samples).collect(); | 218 | let played: Vec<f32> = rx.into_iter().flat_map(|c| c.samples).collect(); |
| 218 | - let sources = [(patched.clone(), 0)]; | 219 | + let sources = [(patched.to_path_buf(), 0)]; |
| 219 | let (meta, stream_0) = { | 220 | let (meta, stream_0) = { |
| 220 | let (meta, rx) = AudioSession::open_multi_streams(&sources, &[(Some(0), 0.0, f64::INFINITY)]) | 221 | let (meta, rx) = AudioSession::open_multi_streams(&sources, &[(Some(0), 0.0, f64::INFINITY)]) |
| 221 | .expect("opens") | 222 | .expect("opens") |
crates/engine/tests/av1.rsmodified+6 -8
| @@ -20,6 +20,7 @@ use std::time::{Duration, Instant}; | |||
| 20 | 20 | ||
| 21 | use engine::demux::{Codec, Demuxer}; | 21 | use engine::demux::{Codec, Demuxer}; |
| 22 | use engine::export::ExportSettings; | 22 | use engine::export::ExportSettings; |
| 23 | +use engine::scratch::Scratch; | ||
| 23 | use engine::{AudioSession, DecodeSession, PlaybackSession, Project}; | 24 | use engine::{AudioSession, DecodeSession, PlaybackSession, Project}; |
| 24 | 25 | ||
| 25 | /// 1280x720@30, 2 s, keyframes 30 apart -- see `scripts/gen_fixtures.sh`. | 26 | /// 1280x720@30, 2 s, keyframes 30 apart -- see `scripts/gen_fixtures.sh`. |
| @@ -271,8 +272,7 @@ fn an_mp4_export_of_a_matroska_source_carries_its_sound() { | |||
| 271 | // A short one: the picture is re-encoded frame by frame and what is under | 272 | // A short one: the picture is re-encoded frame by frame and what is under |
| 272 | // test here is the sound reaching the file, not H.264 throughput. | 273 | // test here is the sound reaching the file, not H.264 throughput. |
| 273 | let project = Project::single(asset("test_av1.mkv"), 15); | 274 | let project = Project::single(asset("test_av1.mkv"), 15); |
| 274 | - let out = std::env::temp_dir().join(format!("ve_export_av1_{}.mp4", std::process::id())); | 275 | + let out = Scratch::file("ve_export_av1", "mp4"); |
| 275 | - let _ = std::fs::remove_file(&out); | ||
| 276 | 276 | ||
| 277 | let handle = engine::export::start(project, meta, &out, &ExportSettings::default()); | 277 | let handle = engine::export::start(project, meta, &out, &ExportSettings::default()); |
| 278 | let started = Instant::now(); | 278 | let started = Instant::now(); |
| @@ -322,9 +322,8 @@ fn exported( | |||
| 322 | name: &str, | 322 | name: &str, |
| 323 | settings: &ExportSettings, | 323 | settings: &ExportSettings, |
| 324 | limit: Duration, | 324 | limit: Duration, |
| 325 | -) -> PathBuf { | 325 | +) -> Scratch { |
| 326 | - let out = std::env::temp_dir().join(format!("ve_av1_{name}_{}.mkv", std::process::id())); | 326 | + let out = Scratch::file(&format!("ve_av1_{name}"), "mkv"); |
| 327 | - let _ = std::fs::remove_file(&out); | ||
| 328 | let started = Instant::now(); | 327 | let started = Instant::now(); |
| 329 | let handle = session.export_to_with(&out, settings); | 328 | let handle = session.export_to_with(&out, settings); |
| 330 | while !handle.is_finished() { | 329 | while !handle.is_finished() { |
| @@ -405,8 +404,7 @@ fn an_av1_export_carries_the_timelines_sound_in_either_container() { | |||
| 405 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open test_av"); | 404 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open test_av"); |
| 406 | assert!(session.cut_at(2.0 / 30.0), "two frames of it"); | 405 | assert!(session.cut_at(2.0 / 30.0), "two frames of it"); |
| 407 | assert!(session.delete_clip(engine::project::Lane::V1, 1)); | 406 | assert!(session.delete_clip(engine::project::Lane::V1, 1)); |
| 408 | - let out = std::env::temp_dir().join(format!("ve_av1_sound_{}.{ext}", std::process::id())); | 407 | + let out = Scratch::file("ve_av1_sound", ext); |
| 409 | - let _ = std::fs::remove_file(&out); | ||
| 410 | let settings = ExportSettings { | 408 | let settings = ExportSettings { |
| 411 | format, | 409 | format, |
| 412 | force_sw: true, | 410 | force_sw: true, |
| @@ -448,7 +446,7 @@ fn an_av1_export_carries_the_timelines_sound_in_either_container() { | |||
| 448 | #[test] | 446 | #[test] |
| 449 | fn an_av1_export_of_an_audio_only_timeline_is_refused_by_name() { | 447 | fn an_av1_export_of_an_audio_only_timeline_is_refused_by_name() { |
| 450 | let session = PlaybackSession::open(asset("test_tone.wav")).expect("open the tone"); | 448 | let session = PlaybackSession::open(asset("test_tone.wav")).expect("open the tone"); |
| 451 | - let out = std::env::temp_dir().join(format!("ve_av1_refused_{}.mkv", std::process::id())); | 449 | + let out = Scratch::file("ve_av1_refused", "mkv"); |
| 452 | let handle = session.export_to_with(&out, &av1_settings()); | 450 | let handle = session.export_to_with(&out, &av1_settings()); |
| 453 | while !handle.is_finished() { | 451 | while !handle.is_finished() { |
| 454 | std::thread::sleep(Duration::from_millis(10)); | 452 | std::thread::sleep(Duration::from_millis(10)); |
crates/engine/tests/backends.rsmodified+3 -5
| @@ -14,6 +14,7 @@ use std::time::{Duration, Instant}; | |||
| 14 | use engine::Codec; | 14 | use engine::Codec; |
| 15 | use engine::decode::{Backend, probe}; | 15 | use engine::decode::{Backend, probe}; |
| 16 | use engine::export::{ExportSettings, Format}; | 16 | use engine::export::{ExportSettings, Format}; |
| 17 | +use engine::scratch::Scratch; | ||
| 17 | use engine::{ExportHandle, PlaybackSession}; | 18 | use engine::{ExportHandle, PlaybackSession}; |
| 18 | 19 | ||
| 19 | fn asset(name: &str) -> PathBuf { | 20 | fn asset(name: &str) -> PathBuf { |
| @@ -22,11 +23,8 @@ fn asset(name: &str) -> PathBuf { | |||
| 22 | .join(name) | 23 | .join(name) |
| 23 | } | 24 | } |
| 24 | 25 | ||
| 25 | -fn out_path(name: &str, ext: &str) -> PathBuf { | 26 | +fn out_path(name: &str, ext: &str) -> Scratch { |
| 26 | - let path = std::env::temp_dir().join(format!("ve_backend_{name}_{}.{ext}", std::process::id())); | 27 | + Scratch::file(&format!("ve_backend_{name}"), ext) |
| 27 | - let _ = std::fs::remove_file(&path); | ||
| 28 | - let _ = std::fs::remove_file(format!("{}.part", path.display())); | ||
| 29 | - path | ||
| 30 | } | 28 | } |
| 31 | 29 | ||
| 32 | /// A still has no coded stream and no decoder to pick, and it must say so | 30 | /// A still has no coded stream and no decoder to pick, and it must say so |
crates/engine/tests/color.rsmodified+2 -2
| @@ -17,6 +17,7 @@ use std::time::{Duration, Instant}; | |||
| 17 | use engine::color::ColorParams; | 17 | use engine::color::ColorParams; |
| 18 | use engine::export::ExportSettings; | 18 | use engine::export::ExportSettings; |
| 19 | use engine::project::Lane; | 19 | use engine::project::Lane; |
| 20 | +use engine::scratch::Scratch; | ||
| 20 | use engine::{DecodeSession, ExportHandle, PlaybackSession}; | 21 | use engine::{DecodeSession, ExportHandle, PlaybackSession}; |
| 21 | 22 | ||
| 22 | const FPS: f64 = 30.0; | 23 | const FPS: f64 = 30.0; |
| @@ -154,8 +155,7 @@ fn an_exported_grade_is_the_one_that_was_watched() { | |||
| 154 | } | 155 | } |
| 155 | let mut session = graded(); | 156 | let mut session = graded(); |
| 156 | session.pause(); | 157 | session.pause(); |
| 157 | - let out = std::env::temp_dir().join(format!("ve_color_{}.mp4", std::process::id())); | 158 | + let out = Scratch::file("ve_color", "mp4"); |
| 158 | - let _ = std::fs::remove_file(&out); | ||
| 159 | let handle = session.export_to_with(&out, &ExportSettings::default()); | 159 | let handle = session.export_to_with(&out, &ExportSettings::default()); |
| 160 | wait(&handle, Duration::from_secs(180)).expect("export"); | 160 | wait(&handle, Duration::from_secs(180)).expect("export"); |
| 161 | 161 | ||
crates/engine/tests/eq_audio.rsmodified+3 -4
| @@ -25,6 +25,7 @@ use engine::eq::{Band, BandKind, EqParams}; | |||
| 25 | use engine::export::{ExportSettings, Format}; | 25 | use engine::export::{ExportSettings, Format}; |
| 26 | use engine::project::{Lane, LaneKind, Source, Speed}; | 26 | use engine::project::{Lane, LaneKind, Source, Speed}; |
| 27 | use engine::scale::FitPolicy; | 27 | use engine::scale::FitPolicy; |
| 28 | +use engine::scratch::Scratch; | ||
| 28 | use engine::{AudioSession, Clip, ExportHandle, Project}; | 29 | use engine::{AudioSession, Clip, ExportHandle, Project}; |
| 29 | 30 | ||
| 30 | const RATE: u32 = 44_100; | 31 | const RATE: u32 = 44_100; |
| @@ -134,10 +135,8 @@ fn wait(handle: &ExportHandle, limit: Duration) -> engine::Result<()> { | |||
| 134 | handle.result().expect("a finished export has an outcome") | 135 | handle.result().expect("a finished export has an outcome") |
| 135 | } | 136 | } |
| 136 | 137 | ||
| 137 | -fn out_path(name: &str, ext: &str) -> PathBuf { | 138 | +fn out_path(name: &str, ext: &str) -> Scratch { |
| 138 | - let path = std::env::temp_dir().join(format!("ve_eq_{name}_{}.{ext}", std::process::id())); | 139 | + Scratch::file(&format!("ve_eq_{name}"), ext) |
| 139 | - let _ = std::fs::remove_file(&path); | ||
| 140 | - path | ||
| 141 | } | 140 | } |
| 142 | 141 | ||
| 143 | fn meta() -> engine::VideoMeta { | 142 | fn meta() -> engine::VideoMeta { |
crates/engine/tests/export.rsmodified+7 -8
| @@ -24,6 +24,7 @@ use engine::hw::HwEncoder; | |||
| 24 | use engine::mux::{Mp4Muxer, VideoParams, parameter_sets}; | 24 | use engine::mux::{Mp4Muxer, VideoParams, parameter_sets}; |
| 25 | use engine::project::{Lane, Source, Speed}; | 25 | use engine::project::{Lane, Source, Speed}; |
| 26 | use engine::scale::FitPolicy; | 26 | use engine::scale::FitPolicy; |
| 27 | +use engine::scratch::Scratch; | ||
| 27 | use engine::{DecodeSession, ExportHandle, PlaybackSession, Project}; | 28 | use engine::{DecodeSession, ExportHandle, PlaybackSession, Project}; |
| 28 | 29 | ||
| 29 | const FPS: f64 = 30.0; | 30 | const FPS: f64 = 30.0; |
| @@ -34,13 +35,11 @@ fn asset(name: &str) -> PathBuf { | |||
| 34 | .join(name) | 35 | .join(name) |
| 35 | } | 36 | } |
| 36 | 37 | ||
| 37 | -/// Per-run unique: two suite runs at once (a release sweep beside a debug one, | 38 | +/// Its own directory, gone with the value: two suite runs at once (a release |
| 38 | -/// or two agents) would otherwise write and delete each other's export. | 39 | +/// sweep beside a debug one, or two agents) would otherwise write and delete |
| 39 | -fn out_path(name: &str) -> PathBuf { | 40 | +/// each other's export, and nothing may outlive the test that wrote it. |
| 40 | - let path = std::env::temp_dir().join(format!("ve_export_{name}_{}.mp4", std::process::id())); | 41 | +fn out_path(name: &str) -> Scratch { |
| 41 | - let _ = std::fs::remove_file(&path); | 42 | + Scratch::file(&format!("ve_export_{name}"), "mp4") |
| 42 | - let _ = std::fs::remove_file(part_path(&path)); | ||
| 43 | - path | ||
| 44 | } | 43 | } |
| 45 | 44 | ||
| 46 | /// What the worker actually writes to until it succeeds; the engine appends the | 45 | /// What the worker actually writes to until it succeeds; the engine appends the |
| @@ -486,7 +485,7 @@ fn a_higher_bitrate_writes_a_bigger_file() { | |||
| 486 | fn a_vanished_source_fails_the_export() { | 485 | fn a_vanished_source_fails_the_export() { |
| 487 | pin_software(); | 486 | pin_software(); |
| 488 | let baseline = asset("test_baseline.mp4"); | 487 | let baseline = asset("test_baseline.mp4"); |
| 489 | - let doomed = std::env::temp_dir().join("ve_export_vanished_source.mp4"); | 488 | + let doomed = Scratch::file("ve_export_vanished_source", "mp4"); |
| 490 | std::fs::copy(&baseline, &doomed).expect("copy a second source"); | 489 | std::fs::copy(&baseline, &doomed).expect("copy a second source"); |
| 491 | let (meta, _) = engine::demux::Demuxer::open(&baseline).unwrap(); | 490 | let (meta, _) = engine::demux::Demuxer::open(&baseline).unwrap(); |
| 492 | 491 | ||
crates/engine/tests/export_subs.rsmodified+4 -6
| @@ -20,6 +20,7 @@ use std::time::{Duration, Instant}; | |||
| 20 | 20 | ||
| 21 | use engine::export::{ExportSettings, Format}; | 21 | use engine::export::{ExportSettings, Format}; |
| 22 | use engine::project::Lane; | 22 | use engine::project::Lane; |
| 23 | +use engine::scratch::Scratch; | ||
| 23 | use engine::subtitle::{self, Cue, SubtitleTrack}; | 24 | use engine::subtitle::{self, Cue, SubtitleTrack}; |
| 24 | use engine::{ExportHandle, Project}; | 25 | use engine::{ExportHandle, Project}; |
| 25 | 26 | ||
| @@ -38,11 +39,8 @@ fn asset(name: &str) -> PathBuf { | |||
| 38 | .join(name) | 39 | .join(name) |
| 39 | } | 40 | } |
| 40 | 41 | ||
| 41 | -fn out_path(name: &str) -> PathBuf { | 42 | +fn out_path(name: &str) -> Scratch { |
| 42 | - let path = | 43 | + Scratch::file(&format!("ve_subs_export_{name}"), "mkv") |
| 43 | - std::env::temp_dir().join(format!("ve_subs_export_{name}_{}.mkv", std::process::id())); | ||
| 44 | - let _ = std::fs::remove_file(&path); | ||
| 45 | - path | ||
| 46 | } | 44 | } |
| 47 | 45 | ||
| 48 | fn pin_software() { | 46 | fn pin_software() { |
| @@ -110,7 +108,7 @@ fn project() -> Project { | |||
| 110 | 108 | ||
| 111 | /// Exports `project` as an HEVC Matroska carrying subtitle track `pick`, and | 109 | /// Exports `project` as an HEVC Matroska carrying subtitle track `pick`, and |
| 112 | /// hands back what our own reader finds in the file. | 110 | /// hands back what our own reader finds in the file. |
| 113 | -fn exported(name: &str, project: Project, pick: Option<usize>) -> (PathBuf, Vec<Cue>) { | 111 | +fn exported(name: &str, project: Project, pick: Option<usize>) -> (Scratch, Vec<Cue>) { |
| 114 | pin_software(); | 112 | pin_software(); |
| 115 | let out = out_path(name); | 113 | let out = out_path(name); |
| 116 | let (meta, _) = engine::demux::Demuxer::open(&asset(MEDIA)).expect("probe the media"); | 114 | let (meta, _) = engine::demux::Demuxer::open(&asset(MEDIA)).expect("probe the media"); |
crates/engine/tests/hevc.rsmodified+3 -4
| @@ -20,6 +20,7 @@ use std::time::{Duration, Instant}; | |||
| 20 | 20 | ||
| 21 | use engine::demux::{Codec, Demuxer}; | 21 | use engine::demux::{Codec, Demuxer}; |
| 22 | use engine::export::ExportSettings; | 22 | use engine::export::ExportSettings; |
| 23 | +use engine::scratch::Scratch; | ||
| 23 | use engine::{AudioSession, DecodeSession, PlaybackSession, Project}; | 24 | use engine::{AudioSession, DecodeSession, PlaybackSession, Project}; |
| 24 | 25 | ||
| 25 | /// 1280x720@30, 2 s -- see `scripts/gen_fixtures.sh`. | 26 | /// 1280x720@30, 2 s -- see `scripts/gen_fixtures.sh`. |
| @@ -217,8 +218,7 @@ fn an_h264_take_plays_and_exports_on_an_hevc_timeline() { | |||
| 217 | // re-encodes both to one H.264 track. | 218 | // re-encodes both to one H.264 track. |
| 218 | let frames = | 219 | let frames = |
| 219 | (session.timeline_duration() * f64::from(session.meta().frame_rate as f32)).round() as u32; | 220 | (session.timeline_duration() * f64::from(session.meta().frame_rate as f32)).round() as u32; |
| 220 | - let out = std::env::temp_dir().join(format!("ve_export_mixed_{}.mp4", std::process::id())); | 221 | + let out = Scratch::file("ve_export_mixed", "mp4"); |
| 221 | - let _ = std::fs::remove_file(&out); | ||
| 222 | let handle = session.export_to_with(&out, &ExportSettings::default()); | 222 | let handle = session.export_to_with(&out, &ExportSettings::default()); |
| 223 | let started = Instant::now(); | 223 | let started = Instant::now(); |
| 224 | while !handle.is_finished() { | 224 | while !handle.is_finished() { |
| @@ -240,8 +240,7 @@ fn an_hevc_source_exports_as_h264() { | |||
| 240 | let session = PlaybackSession::open(asset("test_hevc.mp4")).expect("open test_hevc.mp4"); | 240 | let session = PlaybackSession::open(asset("test_hevc.mp4")).expect("open test_hevc.mp4"); |
| 241 | let meta = *session.meta(); | 241 | let meta = *session.meta(); |
| 242 | let project = Project::single(asset("test_hevc.mp4"), meta.frame_count); | 242 | let project = Project::single(asset("test_hevc.mp4"), meta.frame_count); |
| 243 | - let out = std::env::temp_dir().join(format!("ve_export_hevc_{}.mp4", std::process::id())); | 243 | + let out = Scratch::file("ve_export_hevc", "mp4"); |
| 244 | - let _ = std::fs::remove_file(&out); | ||
| 245 | 244 | ||
| 246 | let handle = engine::export::start(project, meta, &out, &ExportSettings::default()); | 245 | let handle = engine::export::start(project, meta, &out, &ExportSettings::default()); |
| 247 | let started = Instant::now(); | 246 | let started = Instant::now(); |
crates/engine/tests/hevc_export.rsmodified+4 -6
| @@ -26,6 +26,7 @@ use std::time::{Duration, Instant}; | |||
| 26 | 26 | ||
| 27 | use engine::demux::{Codec, Demuxer}; | 27 | use engine::demux::{Codec, Demuxer}; |
| 28 | use engine::export::{ExportSettings, Format}; | 28 | use engine::export::{ExportSettings, Format}; |
| 29 | +use engine::scratch::Scratch; | ||
| 29 | use engine::{AudioSession, PlaybackSession}; | 30 | use engine::{AudioSession, PlaybackSession}; |
| 30 | 31 | ||
| 31 | fn asset(name: &str) -> PathBuf { | 32 | fn asset(name: &str) -> PathBuf { |
| @@ -34,11 +35,8 @@ fn asset(name: &str) -> PathBuf { | |||
| 34 | .join(name) | 35 | .join(name) |
| 35 | } | 36 | } |
| 36 | 37 | ||
| 37 | -fn out_path(name: &str, ext: &str) -> PathBuf { | 38 | +fn out_path(name: &str, ext: &str) -> Scratch { |
| 38 | - let path = std::env::temp_dir().join(format!("ve_hevc_{name}_{}.{ext}", std::process::id())); | 39 | + Scratch::file(&format!("ve_hevc_{name}"), ext) |
| 39 | - let _ = std::fs::remove_file(&path); | ||
| 40 | - let _ = std::fs::remove_file(format!("{}.part", path.display())); | ||
| 41 | - path | ||
| 42 | } | 40 | } |
| 43 | 41 | ||
| 44 | /// Runs an export to completion, failing on the deadline rather than hanging. | 42 | /// Runs an export to completion, failing on the deadline rather than hanging. |
| @@ -275,7 +273,7 @@ fn probe(path: &Path) -> Option<String> { | |||
| 275 | /// A two-second 1920x1080 H.264 fixture in the temp directory -- the assets are | 273 | /// A two-second 1920x1080 H.264 fixture in the temp directory -- the assets are |
| 276 | /// all 720p, which is a multiple of 16 in both directions and would leave the | 274 | /// all 720p, which is a multiple of 16 in both directions and would leave the |
| 277 | /// crop path untested. `None` where ffmpeg is not installed. | 275 | /// crop path untested. `None` where ffmpeg is not installed. |
| 278 | -fn fixture_1080p() -> Option<PathBuf> { | 276 | +fn fixture_1080p() -> Option<Scratch> { |
| 279 | let path = out_path("source1080", "mp4"); | 277 | let path = out_path("source1080", "mp4"); |
| 280 | let made = Command::new("ffmpeg") | 278 | let made = Command::new("ffmpeg") |
| 281 | .args([ | 279 | .args([ |
crates/engine/tests/hevc_hvc1.rsmodified+2 -2
| @@ -19,6 +19,7 @@ use std::time::{Duration, Instant}; | |||
| 19 | 19 | ||
| 20 | use engine::demux::{Codec, Demuxer}; | 20 | use engine::demux::{Codec, Demuxer}; |
| 21 | use engine::export::ExportSettings; | 21 | use engine::export::ExportSettings; |
| 22 | +use engine::scratch::Scratch; | ||
| 22 | use engine::{AudioSession, DecodeSession, PlaybackSession, Project}; | 23 | use engine::{AudioSession, DecodeSession, PlaybackSession, Project}; |
| 23 | 24 | ||
| 24 | /// 1280x720@30, 2 s -- see `scripts/gen_fixtures.sh`. | 25 | /// 1280x720@30, 2 s -- see `scripts/gen_fixtures.sh`. |
| @@ -124,8 +125,7 @@ fn an_hvc1_source_exports_as_h264() { | |||
| 124 | let session = PlaybackSession::open(asset(HVC1)).expect("open the hvc1 fixture"); | 125 | let session = PlaybackSession::open(asset(HVC1)).expect("open the hvc1 fixture"); |
| 125 | let meta = *session.meta(); | 126 | let meta = *session.meta(); |
| 126 | let project = Project::single(asset(HVC1), meta.frame_count); | 127 | let project = Project::single(asset(HVC1), meta.frame_count); |
| 127 | - let out = std::env::temp_dir().join(format!("ve_export_hvc1_{}.mp4", std::process::id())); | 128 | + let out = Scratch::file("ve_export_hvc1", "mp4"); |
| 128 | - let _ = std::fs::remove_file(&out); | ||
| 129 | 129 | ||
| 130 | let handle = engine::export::start(project, meta, &out, &ExportSettings::default()); | 130 | let handle = engine::export::start(project, meta, &out, &ExportSettings::default()); |
| 131 | let started = Instant::now(); | 131 | let started = Instant::now(); |
crates/engine/tests/images.rsmodified+6 -13
| @@ -17,6 +17,7 @@ use std::time::{Duration, Instant}; | |||
| 17 | 17 | ||
| 18 | use engine::export::{ExportSettings, Format}; | 18 | use engine::export::{ExportSettings, Format}; |
| 19 | use engine::project::{Edge, Lane, LaneKind}; | 19 | use engine::project::{Edge, Lane, LaneKind}; |
| 20 | +use engine::scratch::Scratch; | ||
| 20 | use engine::{DecodeSession, ExportHandle, PlaybackSession}; | 21 | use engine::{DecodeSession, ExportHandle, PlaybackSession}; |
| 21 | 22 | ||
| 22 | /// test_av.mp4's rate, which every fixture here shares. | 23 | /// test_av.mp4's rate, which every fixture here shares. |
| @@ -117,7 +118,7 @@ fn importing_a_still_fills_the_library_and_places_nothing() { | |||
| 117 | assert_eq!(session.file_frames(&asset("test_still.png")), CAP); | 118 | assert_eq!(session.file_frames(&asset("test_still.png")), CAP); |
| 118 | 119 | ||
| 119 | // A file that is not a picture at all is refused at the same door, by name. | 120 | // A file that is not a picture at all is refused at the same door, by name. |
| 120 | - let broken = std::env::temp_dir().join(format!("ve_not_a_png_{}.png", std::process::id())); | 121 | + let broken = Scratch::file("ve_not_a_png", "png"); |
| 121 | std::fs::write(&broken, b"this is not a PNG").expect("write the decoy"); | 122 | std::fs::write(&broken, b"this is not a PNG").expect("write the decoy"); |
| 122 | let refused = session.import(&broken).expect_err("not a picture"); | 123 | let refused = session.import(&broken).expect_err("not a picture"); |
| 123 | assert!( | 124 | assert!( |
| @@ -125,7 +126,6 @@ fn importing_a_still_fills_the_library_and_places_nothing() { | |||
| 125 | "the refusal names the file: {refused}" | 126 | "the refusal names the file: {refused}" |
| 126 | ); | 127 | ); |
| 127 | assert_eq!(session.sources().len(), 2, "a refusal registers nothing"); | 128 | assert_eq!(session.sources().len(), 2, "a refusal registers nothing"); |
| 128 | - let _ = std::fs::remove_file(&broken); | ||
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | /// The picture itself: placed on a canvas twice its size, the still comes back | 131 | /// The picture itself: placed on a canvas twice its size, the still comes back |
| @@ -241,9 +241,7 @@ fn a_still_trims_out_to_its_cap_and_no_further() { | |||
| 241 | #[test] | 241 | #[test] |
| 242 | fn pasting_a_copied_still_never_reaches_the_audio_lane() { | 242 | fn pasting_a_copied_still_never_reaches_the_audio_lane() { |
| 243 | pin_software(); | 243 | pin_software(); |
| 244 | - let dir = std::env::temp_dir().join(format!("ve_images_paste_{}", std::process::id())); | 244 | + let dir = Scratch::dir("ve_images_paste"); |
| 245 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 246 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 247 | let media = dir.join("test_av.mp4"); | 245 | let media = dir.join("test_av.mp4"); |
| 248 | let still = dir.join("test_still.png"); | 246 | let still = dir.join("test_still.png"); |
| 249 | std::fs::copy(asset("test_av.mp4"), &media).expect("copy the video"); | 247 | std::fs::copy(asset("test_av.mp4"), &media).expect("copy the video"); |
| @@ -312,9 +310,7 @@ fn pasting_a_copied_still_never_reaches_the_audio_lane() { | |||
| 312 | #[test] | 310 | #[test] |
| 313 | fn a_still_survives_the_project_round_trip() { | 311 | fn a_still_survives_the_project_round_trip() { |
| 314 | pin_software(); | 312 | pin_software(); |
| 315 | - let dir = std::env::temp_dir().join(format!("ve_images_{}", std::process::id())); | 313 | + let dir = Scratch::dir("ve_images"); |
| 316 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 317 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 318 | let media = dir.join("test_av.mp4"); | 314 | let media = dir.join("test_av.mp4"); |
| 319 | let still = dir.join("test_still.png"); | 315 | let still = dir.join("test_still.png"); |
| 320 | std::fs::copy(asset("test_av.mp4"), &media).expect("copy the video"); | 316 | std::fs::copy(asset("test_av.mp4"), &media).expect("copy the video"); |
| @@ -371,9 +367,7 @@ fn a_still_survives_the_project_round_trip() { | |||
| 371 | #[test] | 367 | #[test] |
| 372 | fn a_still_at_saved_source_zero_keeps_the_rate_and_the_sound() { | 368 | fn a_still_at_saved_source_zero_keeps_the_rate_and_the_sound() { |
| 373 | pin_software(); | 369 | pin_software(); |
| 374 | - let dir = std::env::temp_dir().join(format!("ve_still_first_{}", std::process::id())); | 370 | + let dir = Scratch::dir("ve_still_first"); |
| 375 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 376 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 377 | let media = dir.join("test_25fps.mp4"); | 371 | let media = dir.join("test_25fps.mp4"); |
| 378 | let still = dir.join("test_still.png"); | 372 | let still = dir.join("test_still.png"); |
| 379 | std::fs::copy(asset("test_25fps.mp4"), &media).expect("copy the video"); | 373 | std::fs::copy(asset("test_25fps.mp4"), &media).expect("copy the video"); |
| @@ -471,8 +465,7 @@ fn a_mixed_timeline_exports_the_still_at_the_cut() { | |||
| 471 | assert_eq!(session.lane_clips(Lane::V1).len(), 2); | 465 | assert_eq!(session.lane_clips(Lane::V1).len(), 2); |
| 472 | assert_eq!(session.resolution(), (640, 360)); | 466 | assert_eq!(session.resolution(), (640, 360)); |
| 473 | 467 | ||
| 474 | - let out = std::env::temp_dir().join(format!("ve_images_export_{}.mp4", std::process::id())); | 468 | + let out = Scratch::file("ve_images_export", "mp4"); |
| 475 | - let _ = std::fs::remove_file(&out); | ||
| 476 | wait(&session.export_to(&out), Duration::from_secs(300)).expect("export"); | 469 | wait(&session.export_to(&out), Duration::from_secs(300)).expect("export"); |
| 477 | 470 | ||
| 478 | let (meta, frames) = DecodeSession::open(&out).expect("reopen the export"); | 471 | let (meta, frames) = DecodeSession::open(&out).expect("reopen the export"); |
crates/engine/tests/lanes.rsmodified+6 -7
| @@ -16,6 +16,7 @@ use std::time::{Duration, Instant}; | |||
| 16 | use engine::export::{ExportSettings, Format}; | 16 | use engine::export::{ExportSettings, Format}; |
| 17 | use engine::project::{Clip, LaneKind, Source, Speed}; | 17 | use engine::project::{Clip, LaneKind, Source, Speed}; |
| 18 | use engine::scale::FitPolicy; | 18 | use engine::scale::FitPolicy; |
| 19 | +use engine::scratch::Scratch; | ||
| 19 | use engine::{DecodeSession, ExportHandle, PlaybackSession, Project}; | 20 | use engine::{DecodeSession, ExportHandle, PlaybackSession, Project}; |
| 20 | 21 | ||
| 21 | const FPS: f64 = 30.0; | 22 | const FPS: f64 = 30.0; |
| @@ -41,12 +42,10 @@ fn pin_software() { | |||
| 41 | }); | 42 | }); |
| 42 | } | 43 | } |
| 43 | 44 | ||
| 44 | -/// Per-run unique, like the export suite's: two suites at once must not write | 45 | +/// Its own directory, gone with the value: two suites at once must not write |
| 45 | -/// each other's files. | 46 | +/// each other's files, and nothing may outlive the test that wrote it. |
| 46 | -fn out_path(name: &str, ext: &str) -> PathBuf { | 47 | +fn out_path(name: &str, ext: &str) -> Scratch { |
| 47 | - let path = std::env::temp_dir().join(format!("ve_lanes_{name}_{}.{ext}", std::process::id())); | 48 | + Scratch::file(&format!("ve_lanes_{name}"), ext) |
| 48 | - let _ = std::fs::remove_file(&path); | ||
| 49 | - path | ||
| 50 | } | 49 | } |
| 51 | 50 | ||
| 52 | /// A hand-written v4 project: `V1` the whole of `test_av`, `V2` the middle | 51 | /// A hand-written v4 project: `V1` the whole of `test_av`, `V2` the middle |
| @@ -57,7 +56,7 @@ fn out_path(name: &str, ext: &str) -> PathBuf { | |||
| 57 | /// per test: two tests sharing one name run in parallel over one file, and the | 56 | /// per test: two tests sharing one name run in parallel over one file, and the |
| 58 | /// first to finish deletes it out from under the second -- which then fails on | 57 | /// first to finish deletes it out from under the second -- which then fails on |
| 59 | /// a file that is simply not there any more. | 58 | /// a file that is simply not there any more. |
| 60 | -fn three_lane_file(name: &str) -> PathBuf { | 59 | +fn three_lane_file(name: &str) -> Scratch { |
| 61 | let path = out_path(name, "edith"); | 60 | let path = out_path(name, "edith"); |
| 62 | // `source <audio stream> <path>`: the number is which audio track of the | 61 | // `source <audio stream> <path>`: the number is which audio track of the |
| 63 | // file plays, not the source index -- both of these are on their first. | 62 | // file plays, not the source index -- both of these are on their first. |
crates/engine/tests/mixed_fps.rsmodified+5 -5
| @@ -18,6 +18,7 @@ use std::time::{Duration, Instant}; | |||
| 18 | 18 | ||
| 19 | use engine::export::{ExportSettings, Format}; | 19 | use engine::export::{ExportSettings, Format}; |
| 20 | use engine::project::{Edge, Lane, Rate, Speed}; | 20 | use engine::project::{Edge, Lane, Rate, Speed}; |
| 21 | +use engine::scratch::Scratch; | ||
| 21 | use engine::{DecodeSession, Frame, PlaybackSession}; | 22 | use engine::{DecodeSession, Frame, PlaybackSession}; |
| 22 | 23 | ||
| 23 | /// The timeline's rate, which `test_av.mp4` (30 fps, 5 s) defines. | 24 | /// The timeline's rate, which `test_av.mp4` (30 fps, 5 s) defines. |
| @@ -313,14 +314,13 @@ fn a_mixed_rate_project_reloads_unchanged() { | |||
| 313 | import_and_place(&mut session, &pal); | 314 | import_and_place(&mut session, &pal); |
| 314 | let duration = session.timeline_duration(); | 315 | let duration = session.timeline_duration(); |
| 315 | let spans = session.clip_spans(); | 316 | let spans = session.clip_spans(); |
| 316 | - let path = std::env::temp_dir().join(format!("edith-mixed-{}.edith", std::process::id())); | 317 | + let path = Scratch::file("edith-mixed", "edith"); |
| 317 | session.save_project(&path).expect("save"); | 318 | session.save_project(&path).expect("save"); |
| 318 | 319 | ||
| 319 | let reloaded = PlaybackSession::open_project(&path).expect("a mixed-rate project reopens"); | 320 | let reloaded = PlaybackSession::open_project(&path).expect("a mixed-rate project reopens"); |
| 320 | assert_eq!(reloaded.clip_spans(), spans, "the same clips, in seconds"); | 321 | assert_eq!(reloaded.clip_spans(), spans, "the same clips, in seconds"); |
| 321 | assert!((reloaded.timeline_duration() - duration).abs() < 1e-9); | 322 | assert!((reloaded.timeline_duration() - duration).abs() < 1e-9); |
| 322 | assert_eq!(reloaded.file_frames(&pal), 60, "the length was recomputed"); | 323 | assert_eq!(reloaded.file_frames(&pal), 60, "the length was recomputed"); |
| 323 | - std::fs::remove_file(&path).ok(); | ||
| 324 | } | 324 | } |
| 325 | 325 | ||
| 326 | /// The project's rate is the user's to pick, exactly as its resolution is. The | 326 | /// The project's rate is the user's to pick, exactly as its resolution is. The |
| @@ -360,7 +360,7 @@ fn the_project_rate_is_picked_and_the_timeline_is_conformed_to_it() { | |||
| 360 | assert_eq!((v.start, v.len()), (a.start, a.len()), "{v:?} vs {a:?}"); | 360 | assert_eq!((v.start, v.len()), (a.start, a.len()), "{v:?} vs {a:?}"); |
| 361 | } | 361 | } |
| 362 | 362 | ||
| 363 | - let path = std::env::temp_dir().join(format!("edith-rate-{}.edith", std::process::id())); | 363 | + let path = Scratch::file("edith-rate", "edith"); |
| 364 | session.save_project(&path).expect("save"); | 364 | session.save_project(&path).expect("save"); |
| 365 | let reloaded = PlaybackSession::open_project(&path).expect("a retimed project reopens"); | 365 | let reloaded = PlaybackSession::open_project(&path).expect("a retimed project reopens"); |
| 366 | assert_eq!(reloaded.meta().frame_rate, 24.0, "the rate it was cut at"); | 366 | assert_eq!(reloaded.meta().frame_rate, 24.0, "the rate it was cut at"); |
| @@ -402,7 +402,7 @@ fn an_export_runs_at_the_rate_the_project_was_cut_at() { | |||
| 402 | let total = (session.timeline_duration() * 24.0).round() as u32; | 402 | let total = (session.timeline_duration() * 24.0).round() as u32; |
| 403 | assert_eq!(total, 24, "one second, in 24ths"); | 403 | assert_eq!(total, 24, "one second, in 24ths"); |
| 404 | 404 | ||
| 405 | - let out = std::env::temp_dir().join(format!("edith-rate-{}.mp4", std::process::id())); | 405 | + let out = Scratch::file("edith-rate", "mp4"); |
| 406 | wait(&session.export_to_with( | 406 | wait(&session.export_to_with( |
| 407 | &out, | 407 | &out, |
| 408 | &ExportSettings { | 408 | &ExportSettings { |
| @@ -454,7 +454,7 @@ fn an_export_of_two_rates_runs_at_the_speed_it_was_shot() { | |||
| 454 | let total = (session.timeline_duration() * FPS).round() as u32; | 454 | let total = (session.timeline_duration() * FPS).round() as u32; |
| 455 | assert_eq!(total, 45, "15 frames of 30 fps and 30 of the 25 fps clip"); | 455 | assert_eq!(total, 45, "15 frames of 30 fps and 30 of the 25 fps clip"); |
| 456 | 456 | ||
| 457 | - let out = std::env::temp_dir().join(format!("edith-mixed-{}.mp4", std::process::id())); | 457 | + let out = Scratch::file("edith-mixed", "mp4"); |
| 458 | wait(&session.export_to_with( | 458 | wait(&session.export_to_with( |
| 459 | &out, | 459 | &out, |
| 460 | &ExportSettings { | 460 | &ExportSettings { |
crates/engine/tests/playback.rsmodified+5 -6
| @@ -13,6 +13,7 @@ use std::time::{Duration, Instant}; | |||
| 13 | 13 | ||
| 14 | use engine::export::{ExportSettings, Format}; | 14 | use engine::export::{ExportSettings, Format}; |
| 15 | use engine::project::Lane; | 15 | use engine::project::Lane; |
| 16 | +use engine::scratch::Scratch; | ||
| 16 | use engine::{Codec, DecodeSession, Frame, PlaybackSession}; | 17 | use engine::{Codec, DecodeSession, Frame, PlaybackSession}; |
| 17 | 18 | ||
| 18 | fn asset(name: &str) -> PathBuf { | 19 | fn asset(name: &str) -> PathBuf { |
| @@ -1056,8 +1057,7 @@ fn a_placement_at_eos_revives_the_session() { | |||
| 1056 | /// and the timeline still ends, instead of stalling on the missing file. | 1057 | /// and the timeline still ends, instead of stalling on the missing file. |
| 1057 | #[test] | 1058 | #[test] |
| 1058 | fn a_vanished_source_is_skipped() { | 1059 | fn a_vanished_source_is_skipped() { |
| 1059 | - let scratch = | 1060 | + let scratch = Scratch::file("video_editor_vanish", "mp4"); |
| 1060 | - std::env::temp_dir().join(format!("video_editor_vanish_{}.mp4", std::process::id())); | ||
| 1061 | std::fs::copy(asset("test_av2.mp4"), &scratch).expect("copy the fixture"); | 1061 | std::fs::copy(asset("test_av2.mp4"), &scratch).expect("copy the fixture"); |
| 1062 | let mut session = open(asset("test_av.mp4")); | 1062 | let mut session = open(asset("test_av.mp4")); |
| 1063 | let first = session.meta().frame_count; | 1063 | let first = session.meta().frame_count; |
| @@ -1315,7 +1315,8 @@ fn an_emptied_timeline_plays_black_saves_loads_and_undoes() { | |||
| 1315 | // in the *same* words whichever format asked, because the fence sits in | 1315 | // in the *same* words whichever format asked, because the fence sits in |
| 1316 | // `export::start` ahead of the format, not in the mp4 path alone. | 1316 | // `export::start` ahead of the format, not in the mp4 path alone. |
| 1317 | for format in [Format::Mp4, Format::Wav, Format::Flac] { | 1317 | for format in [Format::Mp4, Format::Wav, Format::Flac] { |
| 1318 | - let out = std::env::temp_dir().join(format!("ve_nothing_{}", std::process::id())); | 1318 | + let dir = Scratch::dir("ve_nothing"); |
| 1319 | + let out = dir.join("ve_nothing"); | ||
| 1319 | let handle = session.export_to_with( | 1320 | let handle = session.export_to_with( |
| 1320 | &out, | 1321 | &out, |
| 1321 | &ExportSettings { | 1322 | &ExportSettings { |
| @@ -1341,9 +1342,7 @@ fn an_emptied_timeline_plays_black_saves_loads_and_undoes() { | |||
| 1341 | 1342 | ||
| 1342 | // It saves and loads back -- still a project, still two lanes, and still | 1343 | // It saves and loads back -- still a project, still two lanes, and still |
| 1343 | // naming the file whose frame rate the timeline counts in. | 1344 | // naming the file whose frame rate the timeline counts in. |
| 1344 | - let dir = std::env::temp_dir().join(format!("ve_empty_{}", std::process::id())); | 1345 | + let dir = Scratch::dir("ve_empty"); |
| 1345 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 1346 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 1347 | let project = dir.join("empty.edith"); | 1346 | let project = dir.join("empty.edith"); |
| 1348 | session | 1347 | session |
| 1349 | .save_project(&project) | 1348 | .save_project(&project) |
crates/engine/tests/saveload.rsmodified+4 -7
| @@ -11,6 +11,7 @@ use std::path::{Path, PathBuf}; | |||
| 11 | 11 | ||
| 12 | use engine::PlaybackSession; | 12 | use engine::PlaybackSession; |
| 13 | use engine::project::{Lane, Source}; | 13 | use engine::project::{Lane, Source}; |
| 14 | +use engine::scratch::Scratch; | ||
| 14 | 15 | ||
| 15 | fn asset(name: &str) -> PathBuf { | 16 | fn asset(name: &str) -> PathBuf { |
| 16 | PathBuf::from(env!("CARGO_MANIFEST_DIR")) | 17 | PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| @@ -18,13 +19,9 @@ fn asset(name: &str) -> PathBuf { | |||
| 18 | .join(name) | 19 | .join(name) |
| 19 | } | 20 | } |
| 20 | 21 | ||
| 21 | -/// A fresh directory to litter. Canonical, because the saved paths are | 22 | +/// A fresh directory to litter, deleted when the test that holds it ends. |
| 22 | -/// relative to it and `Project` canonicalises what it is handed. | 23 | +fn scratch(name: &str) -> Scratch { |
| 23 | -fn scratch(name: &str) -> PathBuf { | 24 | + Scratch::dir(&format!("ve_saveload_{name}")) |
| 24 | - let dir = std::env::temp_dir().join(format!("ve_saveload_{name}_{}", std::process::id())); | ||
| 25 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 26 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 27 | - std::fs::canonicalize(&dir).expect("canonical scratch dir") | ||
| 28 | } | 25 | } |
| 29 | 26 | ||
| 30 | fn copy_in(dir: &Path, name: &str) -> PathBuf { | 27 | fn copy_in(dir: &Path, name: &str) -> PathBuf { |
crates/engine/tests/silence.rsmodified+2 -2
| @@ -12,6 +12,7 @@ | |||
| 12 | use std::path::PathBuf; | 12 | use std::path::PathBuf; |
| 13 | 13 | ||
| 14 | use engine::project::{Lane, LaneKind, Speed}; | 14 | use engine::project::{Lane, LaneKind, Speed}; |
| 15 | +use engine::scratch::Scratch; | ||
| 15 | use engine::silence::{self, Settings}; | 16 | use engine::silence::{self, Settings}; |
| 16 | use engine::{Clip, Project}; | 17 | use engine::{Clip, Project}; |
| 17 | 18 | ||
| @@ -356,8 +357,7 @@ fn scanning_a_clip_and_cutting_what_it_finds() { | |||
| 356 | 357 | ||
| 357 | // What a jumpcut leaves is ordinary clips, so the file it saves to is the | 358 | // What a jumpcut leaves is ordinary clips, so the file it saves to is the |
| 358 | // same dialect it always was -- no wire change went with this feature. | 359 | // same dialect it always was -- no wire change went with this feature. |
| 359 | - let dir = std::env::temp_dir().join(format!("edith-silence-{}", std::process::id())); | 360 | + let dir = Scratch::dir("edith-silence"); |
| 360 | - std::fs::create_dir_all(&dir).expect("a place to save"); | ||
| 361 | let file = dir.join("cut.edith"); | 361 | let file = dir.join("cut.edith"); |
| 362 | let (sources, lanes, eq, color) = p.without_orphan_sources(); | 362 | let (sources, lanes, eq, color) = p.without_orphan_sources(); |
| 363 | engine::edith::save( | 363 | engine::edith::save( |
crates/engine/tests/speed.rsmodified+3 -2
| @@ -19,6 +19,7 @@ use std::time::{Duration, Instant}; | |||
| 19 | 19 | ||
| 20 | use engine::export::{ExportSettings, Format}; | 20 | use engine::export::{ExportSettings, Format}; |
| 21 | use engine::project::{Lane, Speed}; | 21 | use engine::project::{Lane, Speed}; |
| 22 | +use engine::scratch::Scratch; | ||
| 22 | use engine::{AudioSession, Clip, DecodeSession, ExportHandle, Project}; | 23 | use engine::{AudioSession, Clip, DecodeSession, ExportHandle, Project}; |
| 23 | 24 | ||
| 24 | const RATE: u32 = 44_100; | 25 | const RATE: u32 = 44_100; |
| @@ -96,8 +97,8 @@ fn wait(handle: &ExportHandle, limit: Duration) -> engine::Result<()> { | |||
| 96 | handle.result().expect("a finished export has an outcome") | 97 | handle.result().expect("a finished export has an outcome") |
| 97 | } | 98 | } |
| 98 | 99 | ||
| 99 | -fn out_path(name: &str, ext: &str) -> PathBuf { | 100 | +fn out_path(name: &str, ext: &str) -> Scratch { |
| 100 | - std::env::temp_dir().join(format!("edith-speed-{name}-{}.{ext}", std::process::id())) | 101 | + Scratch::file(&format!("edith-speed-{name}"), ext) |
| 101 | } | 102 | } |
| 102 | 103 | ||
| 103 | /// The headline: a clip at 2x is half as long on the timeline, plays the same | 104 | /// The headline: a clip at 2x is half as long on the timeline, plays the same |
crates/engine/tests/subtitles.rsmodified+3 -5
| @@ -9,6 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | use std::path::PathBuf; | 10 | use std::path::PathBuf; |
| 11 | 11 | ||
| 12 | +use engine::scratch::Scratch; | ||
| 12 | use engine::subtitle::{self, Cue}; | 13 | use engine::subtitle::{self, Cue}; |
| 13 | 14 | ||
| 14 | fn asset(name: &str) -> PathBuf { | 15 | fn asset(name: &str) -> PathBuf { |
| @@ -23,11 +24,8 @@ fn data(name: &str) -> PathBuf { | |||
| 23 | .join(name) | 24 | .join(name) |
| 24 | } | 25 | } |
| 25 | 26 | ||
| 26 | -fn scratch(name: &str) -> PathBuf { | 27 | +fn scratch(name: &str) -> Scratch { |
| 27 | - let dir = std::env::temp_dir().join(format!("ve_subs_{name}_{}", std::process::id())); | 28 | + Scratch::dir(&format!("ve_subs_{name}")) |
| 28 | - let _ = std::fs::remove_dir_all(&dir); | ||
| 29 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 30 | - std::fs::canonicalize(&dir).expect("canonical scratch dir") | ||
| 31 | } | 29 | } |
| 32 | 30 | ||
| 33 | /// The three cues both hand-written fixtures hold, with the markup resolved: | 31 | /// The three cues both hand-written fixtures hold, with the markup resolved: |
crates/engine/tests/vp9.rsmodified+2 -2
| @@ -18,6 +18,7 @@ use std::time::{Duration, Instant}; | |||
| 18 | 18 | ||
| 19 | use engine::demux::{Codec, Demuxer}; | 19 | use engine::demux::{Codec, Demuxer}; |
| 20 | use engine::export::ExportSettings; | 20 | use engine::export::ExportSettings; |
| 21 | +use engine::scratch::Scratch; | ||
| 21 | use engine::{AudioSession, DecodeSession, PlaybackSession, Project}; | 22 | use engine::{AudioSession, DecodeSession, PlaybackSession, Project}; |
| 22 | 23 | ||
| 23 | /// 1280x720@30, 2 s -- see `scripts/gen_fixtures.sh`. | 24 | /// 1280x720@30, 2 s -- see `scripts/gen_fixtures.sh`. |
| @@ -143,8 +144,7 @@ fn a_vp9_source_exports_as_h264() { | |||
| 143 | let session = PlaybackSession::open(asset("test_vp9.mp4")).expect("open test_vp9.mp4"); | 144 | let session = PlaybackSession::open(asset("test_vp9.mp4")).expect("open test_vp9.mp4"); |
| 144 | let meta = *session.meta(); | 145 | let meta = *session.meta(); |
| 145 | let project = Project::single(asset("test_vp9.mp4"), meta.frame_count); | 146 | let project = Project::single(asset("test_vp9.mp4"), meta.frame_count); |
| 146 | - let out = std::env::temp_dir().join(format!("ve_export_vp9_{}.mp4", std::process::id())); | 147 | + let out = Scratch::file("ve_export_vp9", "mp4"); |
| 147 | - let _ = std::fs::remove_file(&out); | ||
| 148 | 148 | ||
| 149 | let handle = engine::export::start(project, meta, &out, &ExportSettings::default()); | 149 | let handle = engine::export::start(project, meta, &out, &ExportSettings::default()); |
| 150 | let started = Instant::now(); | 150 | let started = Instant::now(); |