Switch to TOML for configuration
This commit is contained in:
@@ -1,13 +1,31 @@
|
||||
use assert_cmd::prelude::*;
|
||||
use predicates::prelude::*;
|
||||
use std::fs;
|
||||
use std::process::Command;
|
||||
use tempfile::TempDir;
|
||||
|
||||
// NOTE: This tests that the task binary is running and parsing arguments. The details of
|
||||
// subcommands are handled with unit tests.
|
||||
|
||||
/// These tests force config to be read via TASKCHAMPION_CONFIG so that a user's own config file
|
||||
/// (in their homedir) does not interfere with tests.
|
||||
fn test_cmd(dir: &TempDir) -> Result<Command, Box<dyn std::error::Error>> {
|
||||
let config_filename = dir.path().join("config.toml");
|
||||
fs::write(
|
||||
config_filename.clone(),
|
||||
format!("data_dir = {:?}", dir.path()),
|
||||
)?;
|
||||
|
||||
let config_filename = config_filename.to_str().unwrap();
|
||||
let mut cmd = Command::cargo_bin("task")?;
|
||||
cmd.env("TASKCHAMPION_CONFIG", config_filename);
|
||||
Ok(cmd)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut cmd = Command::cargo_bin("task")?;
|
||||
let dir = TempDir::new().unwrap();
|
||||
let mut cmd = test_cmd(&dir)?;
|
||||
|
||||
cmd.arg("--help");
|
||||
cmd.assert()
|
||||
@@ -19,7 +37,8 @@ fn help() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
#[test]
|
||||
fn version() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut cmd = Command::cargo_bin("task")?;
|
||||
let dir = TempDir::new().unwrap();
|
||||
let mut cmd = test_cmd(&dir)?;
|
||||
|
||||
cmd.arg("--version");
|
||||
cmd.assert()
|
||||
@@ -31,7 +50,8 @@ fn version() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
#[test]
|
||||
fn invalid_option() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut cmd = Command::cargo_bin("task")?;
|
||||
let dir = TempDir::new().unwrap();
|
||||
let mut cmd = test_cmd(&dir)?;
|
||||
|
||||
cmd.arg("--no-such-option");
|
||||
cmd.assert()
|
||||
|
||||
Reference in New Issue
Block a user