mirror of
https://github.com/alexpasmantier/television.git
synced 2025-07-29 06:11:37 +00:00
test: make file based testing more robust with unique identifiers (#649)
## 📺 PR Description update all file based tests to follow a naming convention in a dedicated testing folder to prevent clashes. Make sure all needed files are in place before running the test ## Checklist <!-- a quick pass through the following items to make sure you haven't forgotten anything --> - [x] my commits **and PR title** follow the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) format - [ ] if this is a new feature, I have added tests to consolidate the feature and prevent regressions - [ ] if this is a bug fix, I have added a test that reproduces the bug (if applicable) - [x] I have added a reasonable amount of documentation to the code where appropriate
This commit is contained in:
parent
4d42a731bf
commit
6b818b927c
3
.gitignore
vendored
3
.gitignore
vendored
@ -29,3 +29,6 @@ Cargo.lock
|
||||
.vscode/
|
||||
|
||||
**/node_modules/
|
||||
|
||||
# test artifacts
|
||||
target_dir/
|
||||
|
@ -4,19 +4,22 @@
|
||||
//! ensuring that users can customize their setup and work in different directories.
|
||||
|
||||
use super::common::*;
|
||||
use std::path::Path;
|
||||
|
||||
/// Tests that the PATH positional argument correctly sets the working directory.
|
||||
#[test]
|
||||
fn test_path_as_positional_argument_sets_working_directory() {
|
||||
let mut tester = PtyTester::new();
|
||||
let tmp_dir = std::env::temp_dir();
|
||||
let tmp_dir = Path::new(TARGET_DIR);
|
||||
|
||||
// Create initial files to be detected
|
||||
std::fs::write(tmp_dir.join("file1.txt"), "").unwrap();
|
||||
std::fs::write(tmp_dir.join("UNIQUE16CHARIDfile.txt"), "").unwrap();
|
||||
|
||||
// Starts the files channel in the specified temporary directory
|
||||
let cmd = tv_local_config_and_cable_with_args(&[
|
||||
"files",
|
||||
"--input",
|
||||
"UNIQUE16CHARID",
|
||||
tmp_dir.to_str().unwrap(),
|
||||
]);
|
||||
let mut child = tester.spawn_command_tui(cmd);
|
||||
@ -25,8 +28,8 @@ fn test_path_as_positional_argument_sets_working_directory() {
|
||||
tester.assert_tui_frame_contains(
|
||||
"╭───────────────────────── files ──────────────────────────╮",
|
||||
);
|
||||
// Verify that the test file `file1.txt` is present
|
||||
tester.assert_tui_frame_contains("file1.txt");
|
||||
// Verify that the test file is present
|
||||
tester.assert_tui_frame_contains("UNIQUE16CHARIDfile.txt");
|
||||
|
||||
// Send Ctrl+C to exit cleanly
|
||||
tester.send(&ctrl('c'));
|
||||
|
@ -85,19 +85,23 @@ fn test_multiple_keybindings_override() {
|
||||
#[test]
|
||||
fn test_exact_matching_enabled() {
|
||||
let mut tester = PtyTester::new();
|
||||
let tmp_dir = Path::new(TARGET_DIR);
|
||||
|
||||
// Create initial file to be detected
|
||||
std::fs::write(tmp_dir.join("UNIQUE16CHARIDfile.txt"), "").unwrap();
|
||||
|
||||
// This enables exact substring matching instead of the default fuzzy matching
|
||||
let cmd = tv_local_config_and_cable_with_args(&[
|
||||
"files",
|
||||
"--exact",
|
||||
"--input",
|
||||
"file1",
|
||||
Path::new(TARGET_DIR).to_str().unwrap(),
|
||||
"UNIQUE16CHARIDfile",
|
||||
tmp_dir.to_str().unwrap(),
|
||||
]);
|
||||
let mut child = tester.spawn_command_tui(cmd);
|
||||
|
||||
// Verify the TUI started successfully with exact matching enabled
|
||||
tester.assert_tui_frame_contains("file1.txt");
|
||||
tester.assert_tui_frame_contains("UNIQUE16CHARIDfile.txt");
|
||||
|
||||
// Send Ctrl+C to exit the application
|
||||
tester.send(&ctrl('c'));
|
||||
@ -107,21 +111,25 @@ fn test_exact_matching_enabled() {
|
||||
#[test]
|
||||
fn test_exact_matching_enabled_fails() {
|
||||
let mut tester = PtyTester::new();
|
||||
let tmp_dir = Path::new(TARGET_DIR);
|
||||
|
||||
// Create initial file to be detected
|
||||
std::fs::write(tmp_dir.join("UNIQUE16CHARIDfile.txt"), "").unwrap();
|
||||
|
||||
// This enables exact substring matching instead of the default fuzzy matching
|
||||
let cmd = tv_local_config_and_cable_with_args(&[
|
||||
"files",
|
||||
"--exact",
|
||||
"--input",
|
||||
"fl1",
|
||||
Path::new(TARGET_DIR).to_str().unwrap(),
|
||||
"UNIQUE16CHARIDfl",
|
||||
tmp_dir.to_str().unwrap(),
|
||||
]);
|
||||
let mut child = tester.spawn_command_tui(cmd);
|
||||
|
||||
// Verify the TUI started successfully with exact matching enabled and no results
|
||||
tester.assert_tui_frame_contains("│> fl1");
|
||||
tester.assert_tui_frame_contains("│> UNIQUE16CHARIDfl");
|
||||
tester.assert_tui_frame_contains("0 / 0");
|
||||
tester.assert_not_tui_frame_contains("file1.txt");
|
||||
tester.assert_not_tui_frame_contains("UNIQUE16CHARIDfile.txt");
|
||||
|
||||
// Send Ctrl+C to exit the application
|
||||
tester.send(&ctrl('c'));
|
||||
|
@ -4,15 +4,16 @@
|
||||
//! ensuring users can enable real-time data updates.
|
||||
|
||||
use super::common::*;
|
||||
use std::path::Path;
|
||||
|
||||
/// Tests that --watch enables live monitoring with automatic source command re-execution.
|
||||
#[test]
|
||||
fn test_watch_reloads_source_command() {
|
||||
let mut tester = PtyTester::new();
|
||||
let tmp_dir = std::env::temp_dir();
|
||||
let tmp_dir = Path::new(TARGET_DIR);
|
||||
|
||||
// Create initial file to be detected
|
||||
std::fs::write(tmp_dir.join("file1.txt"), "").unwrap();
|
||||
std::fs::write(tmp_dir.join("UNIQUE16CHARIDfile.txt"), "").unwrap();
|
||||
|
||||
// This monitors the temp directory and updates every 0.5 seconds
|
||||
let cmd = tv_local_config_and_cable_with_args(&[
|
||||
@ -20,21 +21,23 @@ fn test_watch_reloads_source_command() {
|
||||
"0.5",
|
||||
"--source-command",
|
||||
"ls",
|
||||
"--input",
|
||||
"UNIQUE16CHARID",
|
||||
tmp_dir.to_str().unwrap(),
|
||||
]);
|
||||
let mut child = tester.spawn_command_tui(cmd);
|
||||
|
||||
// Verify the initial file is detected
|
||||
tester.assert_tui_frame_contains("file1.txt");
|
||||
tester.assert_tui_frame_contains("UNIQUE16CHARIDfile.txt");
|
||||
|
||||
// Create a second file
|
||||
std::fs::write(tmp_dir.join("control.txt"), "").unwrap();
|
||||
std::fs::write(tmp_dir.join("UNIQUE16CHARIDcontrol.txt"), "").unwrap();
|
||||
|
||||
// Wait longer than watch interval
|
||||
std::thread::sleep(std::time::Duration::from_millis(2000));
|
||||
|
||||
// Verify the new file appears after the watch interval
|
||||
tester.assert_tui_frame_contains("control.txt");
|
||||
tester.assert_tui_frame_contains("UNIQUE16CHARIDcontrol.txt");
|
||||
|
||||
// Send Ctrl+C to exit
|
||||
tester.send(&ctrl('c'));
|
||||
|
@ -5,6 +5,7 @@
|
||||
//! These are integration tests that combine CLI setup with interactive behavior.
|
||||
|
||||
use super::common::*;
|
||||
use std::path::Path;
|
||||
|
||||
/// Tests that the toggle preview keybinding functionality works correctly.
|
||||
#[test]
|
||||
@ -132,32 +133,32 @@ fn test_scroll_preview_keybindings() {
|
||||
#[test]
|
||||
fn test_reload_source_keybinding() {
|
||||
let mut tester = PtyTester::new();
|
||||
let tmp_dir = std::env::temp_dir();
|
||||
let tmp_dir = Path::new(TARGET_DIR);
|
||||
|
||||
// Create initial file to be detected
|
||||
std::fs::write(tmp_dir.join("file1.txt"), "").unwrap();
|
||||
std::fs::write(tmp_dir.join("UNIQUE16CHARIDfile.txt"), "").unwrap();
|
||||
|
||||
// Start with the files channel
|
||||
let cmd = tv_local_config_and_cable_with_args(&[
|
||||
"files",
|
||||
"--input",
|
||||
".txt",
|
||||
"UNIQUE16CHARID",
|
||||
tmp_dir.to_str().unwrap(),
|
||||
]);
|
||||
let mut child = tester.spawn_command_tui(cmd);
|
||||
|
||||
// Verify the initial file appears in the TUI
|
||||
tester.assert_tui_frame_contains("file1.txt");
|
||||
tester.assert_tui_frame_contains("UNIQUE16CHARIDfile.txt");
|
||||
|
||||
// add another file to be detected
|
||||
std::fs::write(tmp_dir.join("control.txt"), "").unwrap();
|
||||
std::fs::write(tmp_dir.join("UNIQUE16CHARIDcontrol.txt"), "").unwrap();
|
||||
|
||||
// Send Ctrl+R to reload the source command
|
||||
tester.send(&ctrl('r'));
|
||||
|
||||
// Verify the new file appears in the TUI as well as the existing one
|
||||
tester.assert_tui_frame_contains("control.txt");
|
||||
tester.assert_tui_frame_contains("file1.txt");
|
||||
tester.assert_tui_frame_contains("UNIQUE16CHARIDcontrol.txt");
|
||||
tester.assert_tui_frame_contains("UNIQUE16CHARIDfile.txt");
|
||||
|
||||
// Send Ctrl+C to exit
|
||||
tester.send(&ctrl('c'));
|
||||
|
@ -18,6 +18,8 @@ pub const DEFAULT_CABLE_DIR: &str = "./cable/unix";
|
||||
#[cfg(windows)]
|
||||
pub const DEFAULT_CABLE_DIR: &str = "./cable/windows";
|
||||
|
||||
pub const TARGET_DIR: &str = "./tests/target_dir";
|
||||
|
||||
pub const DEFAULT_PTY_SIZE: PtySize = PtySize {
|
||||
rows: 30,
|
||||
cols: 120,
|
||||
|
Loading…
x
Reference in New Issue
Block a user