ok/jj
1
0
Fork 0
forked from mirrors/jj

test: add helper for writing config file to TestEnvironment

This commit is contained in:
Martin von Zweigbergk 2022-04-01 23:22:13 -07:00 committed by Martin von Zweigbergk
parent e7648b6342
commit 257b85a1b5
2 changed files with 13 additions and 12 deletions

View file

@ -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 {

View file

@ -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");