Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions crates/benshi/tests/a_task_is_told_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
//! 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")]

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.
Expand All @@ -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();
Expand All @@ -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,
Expand Down
25 changes: 23 additions & 2 deletions crates/benshi/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions crates/benshi/tests/nobody_reads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

Expand All @@ -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
Expand Down Expand Up @@ -163,13 +165,15 @@ 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();
let _daemon = Daemon::saying_to(
&[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()),
],
Expand Down
11 changes: 2 additions & 9 deletions crates/benshi/tests/the_token_is_given.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Loading