Skip to main content

xacli_testing/testing/
app.rs

1//! TestingApp - A testable wrapper for CLI applications
2//!
3//! Provides a builder API for configuring test scenarios and assertions
4//! for CLI applications built with xacli-core.
5
6use std::rc::Rc;
7
8use xacli_core::App;
9
10use super::test::TestCase;
11
12pub struct TestingApp {
13    /// The wrapped application (shared reference)
14    pub(crate) app: Rc<App>,
15
16    /// Global test configuration
17    pub(crate) config: TestConfig,
18}
19
20/// Test configuration for global settings
21#[derive(Debug, Clone)]
22pub struct TestConfig {
23    /// Whether to simulate TTY mode (default: true)
24    pub tty: bool,
25}
26
27impl Default for TestConfig {
28    fn default() -> Self {
29        Self { tty: true }
30    }
31}
32
33impl TestingApp {
34    /// Create a new TestingApp wrapping the given application
35    pub fn new(app: App) -> Self {
36        Self {
37            app: Rc::new(app),
38            config: TestConfig::default(),
39        }
40    }
41
42    /// Set the global test configuration
43    pub fn config(mut self, config: TestConfig) -> Self {
44        self.config = config;
45        self
46    }
47
48    /// Create a new test case with the given name
49    pub fn test(&self, name: impl Into<String>) -> TestCase {
50        TestCase::new(name)
51    }
52}
53
54impl Default for TestingApp {
55    fn default() -> Self {
56        let app = App::new("test_app", "0.1.0");
57        Self::new(app)
58    }
59}