diff --git a/tests/common/mod.rs b/tests/common/mod.rs index c452f18ad..7ca7a9ce6 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -13,6 +13,7 @@ // limitations under the License. use std::cell::RefCell; +use std::io::Write; use std::path::{Path, PathBuf}; use tempfile::TempDir; @@ -79,6 +80,15 @@ impl TestEnvironment { pub fn config_path(&self) -> &Path { &self.config_path } + + pub fn write_config(&self, content: &[u8]) { + let mut config_file = std::fs::File::options() + .append(true) + .open(&self.config_path) + .unwrap(); + config_file.write_all(content).unwrap(); + config_file.flush().unwrap(); + } } pub fn get_stdout_string(assert: &assert_cmd::assert::Assert) -> String { diff --git a/tests/test_global_opts.rs b/tests/test_global_opts.rs index 628126902..c5f541623 100644 --- a/tests/test_global_opts.rs +++ b/tests/test_global_opts.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::io::Write; - use crate::common::{get_stdout_string, TestEnvironment}; pub mod common; @@ -76,17 +74,10 @@ fn test_color_config() { let test_env = TestEnvironment::default(); // Test that color is used if it's requested in the config file - let mut config_file = std::fs::File::options() - .append(true) - .open(test_env.config_path()) - .unwrap(); - config_file - .write_all( - br#"[ui] + test_env.write_config( + br#"[ui] color="always""#, - ) - .unwrap(); - config_file.flush().unwrap(); + ); test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo");