History

change!: rename `scripted_fixture_*` to not contain 'repo' in the name. (#650)

Further make clear in the documentation that `bash` is used to execute the fixture scripts, previously it wasn't even implied and got lost in history.

Sebastian Thiel committed 3 years ago

Commit dbf6c8c1 parent 94750e11 file · +15 −15Browse files

Unified · Split

tests/tools/src/lib.rs+15−15
@@ -83,7 +83,7 @@ static EXCLUDE_LUT: Lazy<Mutex<Option<git_worktree::fs::Cache<'static>>>> = Lazy · 82 unmodified lines
83/// The major, minor and patch level of the git version on the system.83/// The major, minor and patch level of the git version on the system.
84pub static GIT_VERSION: Lazy<(u8, u8, u8)> = Lazy::new(|| parse_git_version().expect("git version to be parsable"));84pub static GIT_VERSION: Lazy<(u8, u8, u8)> = Lazy::new(|| parse_git_version().expect("git version to be parsable"));
85 85
86/// Define how [scripted_fixture_repo_writable_with_args()] uses produces the writable copy.86/// Define how [scripted_fixture_writable_with_args()] uses produces the writable copy.
87pub enum Creation {87pub enum Creation {
88 /// Run the script once and copy the data from its output to the writable location.88 /// Run the script once and copy the data from its output to the writable location.
89 /// This is fast but won't work if absolute paths are produced by the script.89 /// This is fast but won't work if absolute paths are produced by the script.
@@ -205,7 +205,7 @@ pub fn fixture_bytes(path: impl AsRef<Path>) -> Vec<u8> { · 115 unmodified lines
205 }205 }
206}206}
207 207
208/// Run the executable at `script_name`, like `make_repo.sh` to produce a read-only directory to which208/// Run the script file `script_name` using `bash`, like `make_repo.sh` to produce a read-only directory to which
209/// the path is returned.209/// the path is returned.
210///210///
211/// Note that it persists and the script at `script_name` will only be executed once if it ran without error.211/// Note that it persists and the script at `script_name` will only be executed once if it ran without error.
@@ -227,21 +227,21 @@ pub fn fixture_bytes(path: impl AsRef<Path>) -> Vec<u8> { · 15 unmodified lines
227/// or more specific `.gitignore` configurations in lower levels of the work tree.227/// or more specific `.gitignore` configurations in lower levels of the work tree.
228///228///
229/// The latter is useful if the the script's output is platform specific.229/// The latter is useful if the the script's output is platform specific.
230pub fn scripted_fixture_repo_read_only(script_name: impl AsRef<Path>) -> Result<PathBuf> {230pub fn scripted_fixture_read_only(script_name: impl AsRef<Path>) -> Result<PathBuf> {
231 scripted_fixture_repo_read_only_with_args(script_name, None::<String>)231 scripted_fixture_read_only_with_args(script_name, None::<String>)
232}232}
233 233
234/// Run the executable at `script_name`, like `make_repo.sh` to produce a writable directory to which234/// Run the executable at `script_name`, like `make_repo.sh` to produce a writable directory to which
235/// the tempdir is returned. It will be removed automatically, courtesy of [`tempfile::TempDir`].235/// the tempdir is returned. It will be removed automatically, courtesy of [`tempfile::TempDir`].
236///236///
237/// Note that `script_name` is only executed once, so the data can be copied from its read-only location.237/// Note that `script_name` is only executed once, so the data can be copied from its read-only location.
238pub fn scripted_fixture_repo_writable(script_name: &str) -> Result<tempfile::TempDir> {238pub fn scripted_fixture_writable(script_name: &str) -> Result<tempfile::TempDir> {
239 scripted_fixture_repo_writable_with_args(script_name, None::<String>, Creation::CopyFromReadOnly)239 scripted_fixture_writable_with_args(script_name, None::<String>, Creation::CopyFromReadOnly)
240}240}
241 241
242/// Like [`scripted_fixture_repo_writable()`], but passes `args` to `script_name` while providing control over242/// Like [`scripted_fixture_writable()`], but passes `args` to `script_name` while providing control over
243/// the way files are created with `mode`.243/// the way files are created with `mode`.
244pub fn scripted_fixture_repo_writable_with_args(244pub fn scripted_fixture_writable_with_args(
245 script_name: &str,245 script_name: &str,
246 args: impl IntoIterator<Item = impl Into<String>>,246 args: impl IntoIterator<Item = impl Into<String>>,
247 mode: Creation,247 mode: Creation,
@@ -249,12 +249,12 @@ pub fn scripted_fixture_repo_writable_with_args( · 1 unmodified line
249 let dst = tempfile::TempDir::new()?;249 let dst = tempfile::TempDir::new()?;
250 Ok(match mode {250 Ok(match mode {
251 Creation::CopyFromReadOnly => {251 Creation::CopyFromReadOnly => {
252 let ro_dir = scripted_fixture_repo_read_only_with_args_inner(script_name, args, None)?;252 let ro_dir = scripted_fixture_read_only_with_args_inner(script_name, args, None)?;
253 copy_recursively_into_existing_dir(&ro_dir, dst.path())?;253 copy_recursively_into_existing_dir(&ro_dir, dst.path())?;
254 dst254 dst
255 }255 }
256 Creation::ExecuteScript => {256 Creation::ExecuteScript => {
257 scripted_fixture_repo_read_only_with_args_inner(script_name, args, dst.path().into())?;257 scripted_fixture_read_only_with_args_inner(script_name, args, dst.path().into())?;
258 dst258 dst
259 }259 }
260 })260 })
@@ -279,15 +279,15 @@ pub fn copy_recursively_into_existing_dir(src_dir: impl AsRef<Path>, dst_dir: im · 18 unmodified lines
279 Ok(())279 Ok(())
280}280}
281 281
282/// Like `scripted_fixture_repo_read_only()`], but passes `args` to `script_name`.282/// Like `scripted_fixture_read_only()`], but passes `args` to `script_name`.
283pub fn scripted_fixture_repo_read_only_with_args(283pub fn scripted_fixture_read_only_with_args(
284 script_name: impl AsRef<Path>,284 script_name: impl AsRef<Path>,
285 args: impl IntoIterator<Item = impl Into<String>>,285 args: impl IntoIterator<Item = impl Into<String>>,
286) -> Result<PathBuf> {286) -> Result<PathBuf> {
287 scripted_fixture_repo_read_only_with_args_inner(script_name, args, None)287 scripted_fixture_read_only_with_args_inner(script_name, args, None)
288}288}
289 289
290fn scripted_fixture_repo_read_only_with_args_inner(290fn scripted_fixture_read_only_with_args_inner(
291 script_name: impl AsRef<Path>,291 script_name: impl AsRef<Path>,
292 args: impl IntoIterator<Item = impl Into<String>>,292 args: impl IntoIterator<Item = impl Into<String>>,
293 destination_dir: Option<&Path>,293 destination_dir: Option<&Path>,
@@ -397,7 +397,7 @@ fn scripted_fixture_repo_read_only_with_args_inner( · 103 unmodified lines
397 }397 }
398 assert!(398 assert!(
399 output.status.success(),399 output.status.success(),
400 "repo script failed: stdout: {}\nstderr: {}",400 "fixture script failed: stdout: {}\nstderr: {}",
401 output.stdout.as_bstr(),401 output.stdout.as_bstr(),
402 output.stderr.as_bstr()402 output.stderr.as_bstr()
403 );403 );