From dfa571dc7befca3a3ae06398b2386a8ba3d0e02a Mon Sep 17 00:00:00 2001 From: noctuum <25441068+noctuum@users.noreply.github.com> Date: Sat, 17 Oct 2026 01:11:44 +0000 Subject: [PATCH] test(benshi): read no list where a test counts On defaults the list's task adds a line and a bus connection. --- crates/benshi/tests/a_task_is_told_of.rs | 10 +++++++-- crates/benshi/tests/common/mod.rs | 25 +++++++++++++++++++++-- crates/benshi/tests/nobody_reads.rs | 8 ++++++-- crates/benshi/tests/the_token_is_given.rs | 11 ++-------- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/crates/benshi/tests/a_task_is_told_of.rs b/crates/benshi/tests/a_task_is_told_of.rs index 146c219..7c973b0 100644 --- a/crates/benshi/tests/a_task_is_told_of.rs +++ b/crates/benshi/tests/a_task_is_told_of.rs @@ -5,7 +5,9 @@ //! happens. //! //! The binary itself is run, in a session the test chose. No session bus is -//! there, so the first attempt of detection fails in a way that passes. +//! there, so the first attempt of detection fails in a way that passes. The +//! settings read the list at no time, so every line said after the start is +//! said of detection. #![cfg(target_os = "linux")] @@ -13,7 +15,7 @@ mod common; use std::time::Duration; -use common::{Daemon, Directory}; +use common::{Daemon, Directory, reading_nothing}; /// What the daemon says of the first attempt of detection in a session with /// no session bus, up to the reason. @@ -27,9 +29,11 @@ const SAID_TWICE: Duration = Duration::from_secs(2); fn the_daemon_says_that_detection_is_started_again() { let temporary = Directory::of("t-again"); let runtime = temporary.path().join("run"); + let config = reading_nothing(temporary.path()); let data = temporary.path().join("data"); let daemon = Daemon::start(&[ ("XDG_RUNTIME_DIR", runtime.as_os_str()), + ("XDG_CONFIG_HOME", config.as_os_str()), ("BENSHI_DATA_DIR", data.as_os_str()), ]); let started = daemon.says(); @@ -50,10 +54,12 @@ fn a_daemon_that_cannot_say_it_goes_on_running() { // one it cannot write. let temporary = Directory::of("t-unheard"); let runtime = temporary.path().join("run"); + let config = reading_nothing(temporary.path()); let data = temporary.path().join("data"); let mut daemon = Daemon::heard_for( &[ ("XDG_RUNTIME_DIR", runtime.as_os_str()), + ("XDG_CONFIG_HOME", config.as_os_str()), ("BENSHI_DATA_DIR", data.as_os_str()), ], 4, diff --git a/crates/benshi/tests/common/mod.rs b/crates/benshi/tests/common/mod.rs index 0783690..e5f620d 100644 --- a/crates/benshi/tests/common/mod.rs +++ b/crates/benshi/tests/common/mod.rs @@ -6,11 +6,11 @@ //! never counts on a socket of its own being gone the moment it lets go of it. use std::ffi::OsStr; -use std::fs::File; +use std::fs::{self, File}; use std::io::{BufRead, BufReader, ErrorKind, Read, Write}; use std::os::fd::OwnedFd; use std::os::unix::net::UnixStream; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::process::{Child, Command, ExitStatus, Stdio}; use std::sync::mpsc::{self, Receiver}; use std::thread::{self, JoinHandle}; @@ -46,6 +46,9 @@ const STARTED: &str = "benshi: recording in "; pub const NO_SETTINGS: &str = "benshi: default settings: no configuration directory: no absolute \ path in `XDG_CONFIG_HOME` or `HOME`"; +/// Settings that read the list at no time. +const READING_NOTHING: &str = "[list]\nrefresh = \"off\"\nat_start = false\non_miss = \"off\"\n"; + /// The flag that asks for a daemon without a tray icon. pub const NO_TRAY: &str = "--no-tray"; @@ -266,6 +269,24 @@ impl Directory { } } +/// A configuration directory in `temporary`, for `XDG_CONFIG_HOME`, whose +/// settings read the list at no time. +/// +/// On the defaults the list's task reads the list as the daemon starts and +/// says what came of it. That line comes from a task of its own, in no set +/// order with what is said of detection, so a test that reads the lines after +/// the start by their place cannot count on any of them. +// Dead in a test binary that keeps no daemon from reading the list. +#[allow(dead_code)] +pub fn reading_nothing(temporary: &Path) -> PathBuf { + let config = temporary.join("config"); + fs::create_dir_all(config.join("benshi")).expect("a configuration directory"); + fs::write(config.join("benshi").join("config.toml"), READING_NOTHING) + .expect("a file of settings"); + + config +} + /// A stream that is full, and the end of it that nobody reads. /// /// The test keeps that end for as long as the daemon runs: a write to a diff --git a/crates/benshi/tests/nobody_reads.rs b/crates/benshi/tests/nobody_reads.rs index f35119c..846f556 100644 --- a/crates/benshi/tests/nobody_reads.rs +++ b/crates/benshi/tests/nobody_reads.rs @@ -10,7 +10,8 @@ //! the other end and does not read it. A service of systemd has a stream //! socket for its stderr. The session bus is a socket of the test's that lets //! a connection in and lets go of it, so an attempt of detection is a -//! connection the test counts. +//! connection the test counts. The settings of that daemon read the list at +//! no time, so the list's task makes no connection of its own. #![cfg(target_os = "linux")] @@ -25,7 +26,8 @@ use std::thread; use std::time::{Duration, Instant}; use common::{ - Daemon, Directory, NO_SOURCE, NO_TRAY, PATIENCE, SUCCEEDED, nobody_reads, sources_of, + Daemon, Directory, NO_SOURCE, NO_TRAY, PATIENCE, SUCCEEDED, nobody_reads, reading_nothing, + sources_of, }; /// How many times detection has reached for the session bus once it has been @@ -163,6 +165,7 @@ fn a_daemon_on_the_fallback_that_nobody_reads_answers_a_client() { fn a_daemon_nobody_reads_starts_detection_again() { let temporary = Directory::of("u-again"); let runtime = temporary.path().join("run"); + let config = reading_nothing(temporary.path()); let data = temporary.path().join("data"); let bus = Bus::at(&temporary.path().join("bus")); let (_unread, stderr) = nobody_reads(); @@ -170,6 +173,7 @@ fn a_daemon_nobody_reads_starts_detection_again() { &[OsStr::new(NO_TRAY)], &[ ("XDG_RUNTIME_DIR", runtime.as_os_str()), + ("XDG_CONFIG_HOME", config.as_os_str()), ("BENSHI_DATA_DIR", data.as_os_str()), ("DBUS_SESSION_BUS_ADDRESS", bus.address.as_os_str()), ], diff --git a/crates/benshi/tests/the_token_is_given.rs b/crates/benshi/tests/the_token_is_given.rs index 1fd66b8..4db531c 100644 --- a/crates/benshi/tests/the_token_is_given.rs +++ b/crates/benshi/tests/the_token_is_given.rs @@ -11,21 +11,14 @@ mod common; use std::ffi::OsStr; -use std::fs; use std::path::Path; -use common::{Daemon, Directory}; - -/// The settings of a daemon that reads the list at no time. -const READING_NOTHING: &str = "[list]\nrefresh = \"off\"\nat_start = false\non_miss = \"off\"\n"; +use common::{Daemon, Directory, reading_nothing}; /// A session of its own in `temporary`, with settings that read the list at /// no time. fn a_session(temporary: &Path) -> Vec<(&'static str, std::ffi::OsString)> { - let config = temporary.join("config"); - fs::create_dir_all(config.join("benshi")).expect("a configuration directory"); - fs::write(config.join("benshi").join("config.toml"), READING_NOTHING) - .expect("a file of settings"); + let config = reading_nothing(temporary); vec![ ("XDG_RUNTIME_DIR", temporary.join("run").into_os_string()),