Debian Codegraph @

tests/helper/mod.rs

raw ◀ ▶
1 Debian patch touch this file
1 // SPDX-License-Identifier: Apache-2.0 OR MIT
2
3 use std::{
4 path::{Path, PathBuf},
5 str,
6 };
7
8 pub(crate) use fs_err as fs;
9
10 pub(crate) fn fixtures_dir() -> &'static Path {
11 Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/fixtures"))
12 }
13
•14 #[cfg(any())] // unpackaged test-helper git
15 #[track_caller]
16 pub(crate) fn test_project(model: &str) -> (tempfile::TempDir, PathBuf) {
17 let tmpdir = tempfile::tempdir().unwrap();
18 let tmpdir_path = tmpdir.path();
19
20 let model_path;
21 let workspace_root;
22 if model.contains('/') {
23 let mut model = model.splitn(2, '/');
24 model_path = fixtures_dir().join(model.next().unwrap());
25 workspace_root = tmpdir_path.join(model.next().unwrap());
26 assert!(model.next().is_none());
27 } else {
28 model_path = fixtures_dir().join(model);
29 workspace_root = tmpdir_path.to_path_buf();
30 }
31
32 test_helper::git::copy_tracked_files(model_path, tmpdir_path);
33 (tmpdir, workspace_root)
34 }