Skip to content

Commit bb9bd41

Browse files
authored
fix(startup): avoid first-launch config warning (#362)
1 parent b57dccf commit bb9bd41

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ fn session_root(config_dir: &Path) -> PathBuf {
208208
}
209209

210210
async fn run_editor_inner(args: Args) -> anyhow::Result<()> {
211+
fs::create_dir_all(Config::config_dir())?;
211212
let config_file = Config::path("config.toml");
212213
let preferences_file = Config::path("preferences.json");
213214
let first_launch = !config_file.exists() && !preferences_file.exists();

tests/first_launch.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::process::Command;
2+
3+
#[test]
4+
fn first_launch_creates_config_directory_before_opening_default_log() {
5+
let config_home = tempfile::tempdir().unwrap();
6+
let config_dir = config_home.path().join("red");
7+
8+
// A non-terminal run stops at raw-mode setup, after runtime config has loaded.
9+
Command::new(env!("CARGO_BIN_EXE_red"))
10+
.env("XDG_CONFIG_HOME", config_home.path())
11+
.output()
12+
.unwrap();
13+
14+
assert!(config_dir.join("red.log").is_file());
15+
assert!(!config_dir.join("config.toml").exists());
16+
}

0 commit comments

Comments
 (0)