diff options
Diffstat (limited to 'test_util')
-rw-r--r-- | test_util/src/builders.rs | 51 | ||||
-rw-r--r-- | test_util/src/lib.rs | 18 |
2 files changed, 29 insertions, 40 deletions
diff --git a/test_util/src/builders.rs b/test_util/src/builders.rs index 0a0f2244f..254490073 100644 --- a/test_util/src/builders.rs +++ b/test_util/src/builders.rs @@ -46,17 +46,15 @@ impl TestContextBuilder { } pub fn for_npm() -> Self { - let mut builder = Self::new(); - builder.use_http_server().add_npm_env_vars(); - builder + Self::new().use_http_server().add_npm_env_vars() } - pub fn use_http_server(&mut self) -> &mut Self { + pub fn use_http_server(mut self) -> Self { self.use_http_server = true; self } - pub fn use_temp_cwd(&mut self) -> &mut Self { + pub fn use_temp_cwd(mut self) -> Self { self.use_temp_cwd = true; self } @@ -65,7 +63,7 @@ impl TestContextBuilder { /// In some cases, that might cause an issue though, so calling /// this will use a separate directory for the deno dir and the /// temp directory. - pub fn use_separate_deno_dir(&mut self) -> &mut Self { + pub fn use_separate_deno_dir(mut self) -> Self { self.use_separate_deno_dir = true; self } @@ -73,41 +71,36 @@ impl TestContextBuilder { /// Copies the files at the specified directory in the "testdata" directory /// to the temp folder and runs the test from there. This is useful when /// the test creates files in the testdata directory (ex. a node_modules folder) - pub fn use_copy_temp_dir(&mut self, dir: impl AsRef<str>) -> &mut Self { + pub fn use_copy_temp_dir(mut self, dir: impl AsRef<str>) -> Self { self.copy_temp_dir = Some(dir.as_ref().to_string()); self } - pub fn cwd(&mut self, cwd: impl AsRef<str>) -> &mut Self { + pub fn cwd(mut self, cwd: impl AsRef<str>) -> Self { self.cwd = Some(cwd.as_ref().to_string()); self } - pub fn env( - &mut self, - key: impl AsRef<str>, - value: impl AsRef<str>, - ) -> &mut Self { + pub fn env(mut self, key: impl AsRef<str>, value: impl AsRef<str>) -> Self { self .envs .insert(key.as_ref().to_string(), value.as_ref().to_string()); self } - pub fn add_npm_env_vars(&mut self) -> &mut Self { + pub fn add_npm_env_vars(mut self) -> Self { for (key, value) in env_vars_for_npm_tests_no_sync_download() { - self.env(key, value); + self = self.env(key, value); } self } - pub fn use_sync_npm_download(&mut self) -> &mut Self { + pub fn use_sync_npm_download(self) -> Self { self.env( // make downloads determinstic "DENO_UNSTABLE_NPM_SYNC_DOWNLOAD", "1", - ); - self + ) } pub fn build(&self) -> TestContext { @@ -218,31 +211,31 @@ pub struct TestCommandBuilder { } impl TestCommandBuilder { - pub fn command_name(&mut self, name: impl AsRef<str>) -> &mut Self { + pub fn command_name(mut self, name: impl AsRef<str>) -> Self { self.command_name = name.as_ref().to_string(); self } - pub fn args(&mut self, text: impl AsRef<str>) -> &mut Self { + pub fn args(mut self, text: impl AsRef<str>) -> Self { self.args = text.as_ref().to_string(); self } pub fn args_vec<T: AsRef<str>, I: IntoIterator<Item = T>>( - &mut self, + mut self, args: I, - ) -> &mut Self { + ) -> Self { self.args_vec = args.into_iter().map(|a| a.as_ref().to_string()).collect(); self } - pub fn stdin(&mut self, text: impl AsRef<str>) -> &mut Self { + pub fn stdin(mut self, text: impl AsRef<str>) -> Self { self.stdin = Some(text.as_ref().to_string()); self } /// Splits the output into stdout and stderr rather than having them combined. - pub fn split_output(&mut self) -> &mut Self { + pub fn split_output(mut self) -> Self { // Note: it was previously attempted to capture stdout & stderr separately // then forward the output to a combined pipe, but this was found to be // too racy compared to providing the same combined pipe to both. @@ -250,23 +243,19 @@ impl TestCommandBuilder { self } - pub fn env( - &mut self, - key: impl AsRef<str>, - value: impl AsRef<str>, - ) -> &mut Self { + pub fn env(mut self, key: impl AsRef<str>, value: impl AsRef<str>) -> Self { self .envs .insert(key.as_ref().to_string(), value.as_ref().to_string()); self } - pub fn env_clear(&mut self) -> &mut Self { + pub fn env_clear(mut self) -> Self { self.env_clear = true; self } - pub fn cwd(&mut self, cwd: impl AsRef<str>) -> &mut Self { + pub fn cwd(mut self, cwd: impl AsRef<str>) -> Self { self.cwd = Some(cwd.as_ref().to_string()); self } diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index 5c6bc97f7..0b6ce1615 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -2076,13 +2076,13 @@ impl<'a> CheckOutputIntegrationTest<'a> { pub fn output(&self) -> TestCommandOutput { let mut context_builder = TestContextBuilder::default(); if self.temp_cwd { - context_builder.use_temp_cwd(); + context_builder = context_builder.use_temp_cwd(); } if let Some(dir) = &self.copy_temp_dir { - context_builder.use_copy_temp_dir(dir); + context_builder = context_builder.use_copy_temp_dir(dir); } if self.http_server { - context_builder.use_http_server(); + context_builder = context_builder.use_http_server(); } let context = context_builder.build(); @@ -2090,22 +2090,22 @@ impl<'a> CheckOutputIntegrationTest<'a> { let mut command_builder = context.new_command(); if !self.args.is_empty() { - command_builder.args(self.args); + command_builder = command_builder.args(self.args); } if !self.args_vec.is_empty() { - command_builder.args_vec(self.args_vec.clone()); + command_builder = command_builder.args_vec(self.args_vec.clone()); } if let Some(input) = &self.input { - command_builder.stdin(input); + command_builder = command_builder.stdin(input); } for (key, value) in &self.envs { - command_builder.env(key, value); + command_builder = command_builder.env(key, value); } if self.env_clear { - command_builder.env_clear(); + command_builder = command_builder.env_clear(); } if let Some(cwd) = &self.cwd { - command_builder.cwd(cwd); + command_builder = command_builder.cwd(cwd); } command_builder.run() |