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
This commit is contained in:
parent
14b91f5e55
commit
5d7ef02f00
3
.gitignore
vendored
3
.gitignore
vendored
@ -29,3 +29,6 @@ Cargo.lock
|
|||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
**/node_modules/
|
**/node_modules/
|
||||||
|
|
||||||
|
# test artifacts
|
||||||
|
target_dir/
|
||||||
|
@ -4,19 +4,22 @@
|
|||||||
//! ensuring that users can customize their setup and work in different directories.
|
//! ensuring that users can customize their setup and work in different directories.
|
||||||
|
|
||||||
use super::common::*;
|
use super::common::*;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
/// Tests that the PATH positional argument correctly sets the working directory.
|
/// Tests that the PATH positional argument correctly sets the working directory.
|
||||||
#[test]
|
#[test]
|
||||||
fn test_path_as_positional_argument_sets_working_directory() {
|
fn test_path_as_positional_argument_sets_working_directory() {
|
||||||
let mut tester = PtyTester::new();
|
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
|
// 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
|
// Starts the files channel in the specified temporary directory
|
||||||
let cmd = tv_local_config_and_cable_with_args(&[
|
let cmd = tv_local_config_and_cable_with_args(&[
|
||||||
"files",
|
"files",
|
||||||
|
"--input",
|
||||||
|
"UNIQUE16CHARID",
|
||||||
tmp_dir.to_str().unwrap(),
|
tmp_dir.to_str().unwrap(),
|
||||||
]);
|
]);
|
||||||
let mut child = tester.spawn_command_tui(cmd);
|
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(
|
tester.assert_tui_frame_contains(
|
||||||
"╭───────────────────────── files ──────────────────────────╮",
|
"╭───────────────────────── files ──────────────────────────╮",
|
||||||
);
|
);
|
||||||
// Verify that the test file `file1.txt` is present
|
// Verify that the test file is present
|
||||||
tester.assert_tui_frame_contains("file1.txt");
|
tester.assert_tui_frame_contains("UNIQUE16CHARIDfile.txt");
|
||||||
|
|
||||||
// Send Ctrl+C to exit cleanly
|
// Send Ctrl+C to exit cleanly
|
||||||
tester.send(&ctrl('c'));
|
tester.send(&ctrl('c'));
|
||||||
|
@ -85,19 +85,23 @@ fn test_multiple_keybindings_override() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_exact_matching_enabled() {
|
fn test_exact_matching_enabled() {
|
||||||
let mut tester = PtyTester::new();
|
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
|
// This enables exact substring matching instead of the default fuzzy matching
|
||||||
let cmd = tv_local_config_and_cable_with_args(&[
|
let cmd = tv_local_config_and_cable_with_args(&[
|
||||||
"files",
|
"files",
|
||||||
"--exact",
|
"--exact",
|
||||||
"--input",
|
"--input",
|
||||||
"file1",
|
"UNIQUE16CHARIDfile",
|
||||||
Path::new(TARGET_DIR).to_str().unwrap(),
|
tmp_dir.to_str().unwrap(),
|
||||||
]);
|
]);
|
||||||
let mut child = tester.spawn_command_tui(cmd);
|
let mut child = tester.spawn_command_tui(cmd);
|
||||||
|
|
||||||
// Verify the TUI started successfully with exact matching enabled
|
// 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
|
// Send Ctrl+C to exit the application
|
||||||
tester.send(&ctrl('c'));
|
tester.send(&ctrl('c'));
|
||||||
@ -107,21 +111,25 @@ fn test_exact_matching_enabled() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_exact_matching_enabled_fails() {
|
fn test_exact_matching_enabled_fails() {
|
||||||
let mut tester = PtyTester::new();
|
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
|
// This enables exact substring matching instead of the default fuzzy matching
|
||||||
let cmd = tv_local_config_and_cable_with_args(&[
|
let cmd = tv_local_config_and_cable_with_args(&[
|
||||||
"files",
|
"files",
|
||||||
"--exact",
|
"--exact",
|
||||||
"--input",
|
"--input",
|
||||||
"fl1",
|
"UNIQUE16CHARIDfl",
|
||||||
Path::new(TARGET_DIR).to_str().unwrap(),
|
tmp_dir.to_str().unwrap(),
|
||||||
]);
|
]);
|
||||||
let mut child = tester.spawn_command_tui(cmd);
|
let mut child = tester.spawn_command_tui(cmd);
|
||||||
|
|
||||||
// Verify the TUI started successfully with exact matching enabled and no results
|
// 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_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
|
// Send Ctrl+C to exit the application
|
||||||
tester.send(&ctrl('c'));
|
tester.send(&ctrl('c'));
|
||||||
|
@ -4,15 +4,16 @@
|
|||||||
//! ensuring users can enable real-time data updates.
|
//! ensuring users can enable real-time data updates.
|
||||||
|
|
||||||
use super::common::*;
|
use super::common::*;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
/// Tests that --watch enables live monitoring with automatic source command re-execution.
|
/// Tests that --watch enables live monitoring with automatic source command re-execution.
|
||||||
#[test]
|
#[test]
|
||||||
fn test_watch_reloads_source_command() {
|
fn test_watch_reloads_source_command() {
|
||||||
let mut tester = PtyTester::new();
|
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
|
// 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
|
// This monitors the temp directory and updates every 0.5 seconds
|
||||||
let cmd = tv_local_config_and_cable_with_args(&[
|
let cmd = tv_local_config_and_cable_with_args(&[
|
||||||
@ -20,21 +21,23 @@ fn test_watch_reloads_source_command() {
|
|||||||
"0.5",
|
"0.5",
|
||||||
"--source-command",
|
"--source-command",
|
||||||
"ls",
|
"ls",
|
||||||
|
"--input",
|
||||||
|
"UNIQUE16CHARID",
|
||||||
tmp_dir.to_str().unwrap(),
|
tmp_dir.to_str().unwrap(),
|
||||||
]);
|
]);
|
||||||
let mut child = tester.spawn_command_tui(cmd);
|
let mut child = tester.spawn_command_tui(cmd);
|
||||||
|
|
||||||
// Verify the initial file is detected
|
// Verify the initial file is detected
|
||||||
tester.assert_tui_frame_contains("file1.txt");
|
tester.assert_tui_frame_contains("UNIQUE16CHARIDfile.txt");
|
||||||
|
|
||||||
// Create a second file
|
// 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
|
// Wait longer than watch interval
|
||||||
std::thread::sleep(std::time::Duration::from_millis(2000));
|
std::thread::sleep(std::time::Duration::from_millis(2000));
|
||||||
|
|
||||||
// Verify the new file appears after the watch interval
|
// 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
|
// Send Ctrl+C to exit
|
||||||
tester.send(&ctrl('c'));
|
tester.send(&ctrl('c'));
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
//! These are integration tests that combine CLI setup with interactive behavior.
|
//! These are integration tests that combine CLI setup with interactive behavior.
|
||||||
|
|
||||||
use super::common::*;
|
use super::common::*;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
/// Tests that the toggle preview keybinding functionality works correctly.
|
/// Tests that the toggle preview keybinding functionality works correctly.
|
||||||
#[test]
|
#[test]
|
||||||
@ -132,32 +133,32 @@ fn test_scroll_preview_keybindings() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_reload_source_keybinding() {
|
fn test_reload_source_keybinding() {
|
||||||
let mut tester = PtyTester::new();
|
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
|
// 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
|
// Start with the files channel
|
||||||
let cmd = tv_local_config_and_cable_with_args(&[
|
let cmd = tv_local_config_and_cable_with_args(&[
|
||||||
"files",
|
"files",
|
||||||
"--input",
|
"--input",
|
||||||
".txt",
|
"UNIQUE16CHARID",
|
||||||
tmp_dir.to_str().unwrap(),
|
tmp_dir.to_str().unwrap(),
|
||||||
]);
|
]);
|
||||||
let mut child = tester.spawn_command_tui(cmd);
|
let mut child = tester.spawn_command_tui(cmd);
|
||||||
|
|
||||||
// Verify the initial file appears in the TUI
|
// 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
|
// 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
|
// Send Ctrl+R to reload the source command
|
||||||
tester.send(&ctrl('r'));
|
tester.send(&ctrl('r'));
|
||||||
|
|
||||||
// Verify the new file appears in the TUI as well as the existing one
|
// 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("UNIQUE16CHARIDcontrol.txt");
|
||||||
tester.assert_tui_frame_contains("file1.txt");
|
tester.assert_tui_frame_contains("UNIQUE16CHARIDfile.txt");
|
||||||
|
|
||||||
// Send Ctrl+C to exit
|
// Send Ctrl+C to exit
|
||||||
tester.send(&ctrl('c'));
|
tester.send(&ctrl('c'));
|
||||||
|
@ -18,6 +18,8 @@ pub const DEFAULT_CABLE_DIR: &str = "./cable/unix";
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub const DEFAULT_CABLE_DIR: &str = "./cable/windows";
|
pub const DEFAULT_CABLE_DIR: &str = "./cable/windows";
|
||||||
|
|
||||||
|
pub const TARGET_DIR: &str = "./tests/target_dir";
|
||||||
|
|
||||||
pub const DEFAULT_PTY_SIZE: PtySize = PtySize {
|
pub const DEFAULT_PTY_SIZE: PtySize = PtySize {
|
||||||
rows: 30,
|
rows: 30,
|
||||||
cols: 120,
|
cols: 120,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user