History

move `Env` test utility into `git-testtools` (#331)

Sebastian Thiel committed 4 years ago

Commit bd3f4d01 parent 15a379a5 files · +111 −36Browse files

Unified · Split

5 files
  1. Cargo.lock +78 −2
  2. git-config/src/file/includes.rs +1 −4
  3. git-config/tests/file/init/from_env.rs +2 −27
  4. git-config/tests/file/init/from_paths/includes/conditional/gitdir/mod.rs +4 −3
  5. tests/tools/src/lib.rs +26 −0
Cargo.lock+78−2
@@ -943,6 +943,21 @@ version = "1.2.0" · 942 unmodified lines
943943 source = "registry+https://github.com/rust-lang/crates.io-index"
944944 checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394"
945945
946+[[package]]
947+name = "futures"
948+version = "0.3.21"
949+source = "registry+https://github.com/rust-lang/crates.io-index"
950+checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e"
951+dependencies = [
952+ "futures-channel",
953+ "futures-core",
954+ "futures-executor",
955+ "futures-io",
956+ "futures-sink",
957+ "futures-task",
958+ "futures-util",
959+]
960+
946961 [[package]]
947962 name = "futures-channel"
948963 version = "0.3.21"
@@ -959,6 +974,17 @@ version = "0.3.21" · 10 unmodified lines
959974 source = "registry+https://github.com/rust-lang/crates.io-index"
960975 checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
961976
977+[[package]]
978+name = "futures-executor"
979+version = "0.3.21"
980+source = "registry+https://github.com/rust-lang/crates.io-index"
981+checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6"
982+dependencies = [
983+ "futures-core",
984+ "futures-task",
985+ "futures-util",
986+]
987+
962988 [[package]]
963989 name = "futures-io"
964990 version = "0.3.21"
@@ -986,6 +1012,29 @@ version = "0.3.21" · 21 unmodified lines
9861012 source = "registry+https://github.com/rust-lang/crates.io-index"
9871013 checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868"
9881014
1015+[[package]]
1016+name = "futures-task"
1017+version = "0.3.21"
1018+source = "registry+https://github.com/rust-lang/crates.io-index"
1019+checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a"
1020+
1021+[[package]]
1022+name = "futures-util"
1023+version = "0.3.21"
1024+source = "registry+https://github.com/rust-lang/crates.io-index"
1025+checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a"
1026+dependencies = [
1027+ "futures-channel",
1028+ "futures-core",
1029+ "futures-io",
1030+ "futures-sink",
1031+ "futures-task",
1032+ "memchr",
1033+ "pin-project-lite",
1034+ "pin-utils",
1035+ "slab",
1036+]
1037+
9891038 [[package]]
9901039 name = "generic-array"
9911040 version = "0.14.5"
@@ -1100,7 +1149,7 @@ dependencies = [ · 108 unmodified lines
11001149 "nom",
11011150 "serde",
11021151 "serde_derive",
1103− "serial_test",
1152+ "serial_test 0.7.0",
11041153 "smallvec",
11051154 "tempfile",
11061155 "thiserror",
@@ -1467,6 +1516,7 @@ dependencies = [ · 360 unmodified lines
14671516 "git-worktree",
14681517 "is_ci",
14691518 "log",
1519+ "serial_test 0.8.0",
14701520 "signal-hook",
14711521 "tempfile",
14721522 "thiserror",
@@ -2587,7 +2637,20 @@ dependencies = [ · 1114 unmodified lines
25872637 "lazy_static",
25882638 "log",
25892639 "parking_lot 0.12.1",
2590− "serial_test_derive",
2640+ "serial_test_derive 0.7.0",
2641+]
2642+
2643+[[package]]
2644+name = "serial_test"
2645+version = "0.8.0"
2646+source = "registry+https://github.com/rust-lang/crates.io-index"
2647+checksum = "7eec42e7232e5ca56aa59d63af3c7f991fe71ee6a3ddd2d3480834cf3902b007"
2648+dependencies = [
2649+ "futures",
2650+ "lazy_static",
2651+ "log",
2652+ "parking_lot 0.12.1",
2653+ "serial_test_derive 0.8.0",
25912654 ]
25922655
25932656 [[package]]
@@ -2603,6 +2666,19 @@ dependencies = [ · 9 unmodified lines
26032666 "syn",
26042667 ]
26052668
2669+[[package]]
2670+name = "serial_test_derive"
2671+version = "0.8.0"
2672+source = "registry+https://github.com/rust-lang/crates.io-index"
2673+checksum = "f1b95bb2f4f624565e8fe8140c789af7e2082c0e0561b5a82a1b678baa9703dc"
2674+dependencies = [
2675+ "proc-macro-error",
2676+ "proc-macro2",
2677+ "quote",
2678+ "rustversion",
2679+ "syn",
2680+]
2681+
26062682 [[package]]
26072683 name = "sha-1"
26082684 version = "0.10.0"
git-config/src/file/includes.rs+1−4
@@ -325,7 +325,7 @@ mod types { · 324 unmodified lines
325325 pub conditional: conditional::Context<'a>,
326326 }
327327
328− impl Options<'_> {
328+ impl<'a> Options<'a> {
329329 /// Provide options to never follow include directives at all.
330330 pub fn no_includes() -> Self {
331331 Options {
@@ -335,9 +335,6 @@ mod types { · 3 unmodified lines
335335 conditional: Default::default(),
336336 }
337337 }
338− }
339−
340− impl<'a> Options<'a> {
341338 /// Provide options to follow includes like git does, provided the required `conditional` and `interpolate` contexts
342339 /// to support `gitdir` and `onbranch` based `includeIf` directives as well as standard `include.path` resolution.
343340 /// Note that the follow-mode is `git`-style, following at most 10 indirections while
git-config/tests/file/init/from_env.rs+2−27
@@ -1,39 +1,14 @@
1−use std::{borrow::Cow, env, fs};
1+use std::{borrow::Cow, fs};
22
33 use git_config::file::includes;
44 use git_config::file::init;
55 use git_config::{file::init::from_env, File};
6+use git_testtools::Env;
67 use serial_test::serial;
78 use tempfile::tempdir;
89
910 use crate::file::init::from_paths::escape_backslashes;
1011
11−pub struct Env<'a> {
12− altered_vars: Vec<&'a str>,
13−}
14−
15−impl<'a> Env<'a> {
16− pub(crate) fn new() -> Self {
17− Env {
18− altered_vars: Vec::new(),
19− }
20− }
21−
22− pub(crate) fn set(mut self, var: &'a str, value: impl Into<String>) -> Self {
23− env::set_var(var, value.into());
24− self.altered_vars.push(var);
25− self
26− }
27−}
28−
29−impl<'a> Drop for Env<'a> {
30− fn drop(&mut self) {
31− for var in &self.altered_vars {
32− env::remove_var(var);
33− }
34− }
35−}
36−
3712 #[test]
3813 #[serial]
3914 fn empty_without_relevant_environment() {
git-config/tests/file/init/from_paths/includes/conditional/gitdir/mod.rs+4−3
@@ -1,5 +1,6 @@
11 mod util;
22
3+use git_testtools::Env;
34 use serial_test::serial;
45 use util::{assert_section_value, Condition, GitEnv};
56
@@ -90,7 +91,7 @@ fn dot_slash_from_environment_causes_error() -> crate::Result { · 84 unmodified lines
9091 let env = GitEnv::repo_name("worktree")?;
9192
9293 {
93− let _environment = crate::file::init::from_env::Env::new()
94+ let _environment = Env::new()
9495 .set("GIT_CONFIG_COUNT", "1")
9596 .set(
9697 "GIT_CONFIG_KEY_0",
@@ -112,7 +113,7 @@ fn dot_slash_from_environment_causes_error() -> crate::Result { · 15 unmodified lines
112113
113114 let absolute_path = escape_backslashes(env.home_dir().join("include.config"));
114115 {
115− let _environment = crate::file::init::from_env::Env::new()
116+ let _environment = Env::new()
116117 .set("GIT_CONFIG_COUNT", "1")
117118 .set("GIT_CONFIG_KEY_0", "includeIf.gitdir:./worktree/.path")
118119 .set("GIT_CONFIG_VALUE_0", &absolute_path);
@@ -130,7 +131,7 @@ fn dot_slash_from_environment_causes_error() -> crate::Result { · 11 unmodified lines
130131 }
131132
132133 {
133− let _environment = crate::file::init::from_env::Env::new()
134+ let _environment = Env::new()
134135 .set("GIT_CONFIG_COUNT", "1")
135136 .set(
136137 "GIT_CONFIG_KEY_0",
tests/tools/src/lib.rs+26−0
@@ -409,3 +409,29 @@ pub fn sleep_forever() -> ! { · 408 unmodified lines
409409 std::thread::sleep(std::time::Duration::from_secs(u64::MAX))
410410 }
411411 }
412+
413+pub struct Env<'a> {
414+ altered_vars: Vec<&'a str>,
415+}
416+
417+impl<'a> Env<'a> {
418+ pub fn new() -> Self {
419+ Env {
420+ altered_vars: Vec::new(),
421+ }
422+ }
423+
424+ pub fn set(mut self, var: &'a str, value: impl Into<String>) -> Self {
425+ std::env::set_var(var, value.into());
426+ self.altered_vars.push(var);
427+ self
428+ }
429+}
430+
431+impl<'a> Drop for Env<'a> {
432+ fn drop(&mut self) {
433+ for var in &self.altered_vars {
434+ std::env::remove_var(var);
435+ }
436+ }
437+}