debugger/testing/
config.rs

1//! Test scenario configuration types
2//!
3//! Defines the data structures for deserializing YAML test scenarios.
4
5use serde::Deserialize;
6use std::path::PathBuf;
7
8/// A complete test scenario loaded from a YAML file
9#[derive(Deserialize, Debug)]
10pub struct TestScenario {
11    /// Name of the test scenario
12    pub name: String,
13    /// Optional description of what the test verifies
14    pub description: Option<String>,
15    /// Optional setup steps to run before the test (e.g., compilation)
16    pub setup: Option<Vec<SetupStep>>,
17    /// Configuration for the debug target
18    pub target: TargetConfig,
19    /// The sequence of test steps to execute
20    pub steps: Vec<TestStep>,
21}
22
23/// A setup step that runs before the test
24#[derive(Deserialize, Debug)]
25pub struct SetupStep {
26    /// Shell command to execute
27    pub shell: String,
28}
29
30/// Configuration for the debug target
31#[derive(Deserialize, Debug)]
32pub struct TargetConfig {
33    /// Path to the program to debug
34    pub program: PathBuf,
35    /// Arguments to pass to the program
36    pub args: Option<Vec<String>>,
37    /// Debug adapter to use (e.g., "lldb-dap", "codelldb", "debugpy")
38    pub adapter: Option<String>,
39    /// Whether to stop at the program entry point
40    #[serde(default)]
41    pub stop_on_entry: bool,
42}
43
44/// A single test step in the execution flow
45#[derive(Deserialize, Debug)]
46#[serde(tag = "action", rename_all = "snake_case")]
47pub enum TestStep {
48    /// Execute a debugger command
49    Command {
50        /// The command to execute (e.g., "break add main", "continue")
51        command: String,
52        /// Optional expectations for the command result
53        expect: Option<CommandExpectation>,
54    },
55    /// Wait for a stop event (breakpoint, step completion, etc.)
56    Await {
57        /// Timeout in seconds (default: 30)
58        timeout: Option<u64>,
59        /// Expected stop event properties
60        expect: Option<StopExpectation>,
61    },
62    /// Inspect local variables and make assertions
63    InspectLocals {
64        /// Variable assertions to check
65        asserts: Vec<VariableAssertion>,
66    },
67    /// Inspect the call stack
68    InspectStack {
69        /// Frame assertions to check
70        asserts: Vec<FrameAssertion>,
71    },
72    /// Check program output
73    CheckOutput {
74        /// Expected substring in output
75        contains: Option<String>,
76        /// Expected exact output
77        equals: Option<String>,
78    },
79    /// Evaluate an expression
80    Evaluate {
81        /// Expression to evaluate
82        expression: String,
83        /// Expected result
84        expect: Option<EvaluateExpectation>,
85    },
86}
87
88/// Expectations for a command result
89#[derive(Deserialize, Debug)]
90pub struct CommandExpectation {
91    /// Whether the command should succeed
92    pub success: Option<bool>,
93    /// Substring that should be in the output
94    pub output_contains: Option<String>,
95}
96
97/// Expectations for a stop event
98#[derive(Deserialize, Debug)]
99pub struct StopExpectation {
100    /// Expected stop reason (e.g., "breakpoint", "step", "exited")
101    pub reason: Option<String>,
102    /// Expected source file name (partial match)
103    pub file: Option<String>,
104    /// Expected line number
105    pub line: Option<u32>,
106    /// Expected exit code (for "exited" reason)
107    pub exit_code: Option<i64>,
108    /// Expected thread ID
109    pub thread_id: Option<i64>,
110}
111
112/// Assertion for a variable
113#[derive(Deserialize, Debug)]
114pub struct VariableAssertion {
115    /// Variable name to check
116    pub name: String,
117    /// Expected value (exact match)
118    pub value: Option<String>,
119    /// Expected value substring (partial match)
120    pub value_contains: Option<String>,
121    /// Expected type name
122    #[serde(rename = "type")]
123    pub type_name: Option<String>,
124}
125
126/// Assertion for a stack frame
127#[derive(Deserialize, Debug)]
128pub struct FrameAssertion {
129    /// Frame index (0 = current/innermost)
130    pub index: usize,
131    /// Expected function name
132    pub function: Option<String>,
133    /// Expected source file (partial match)
134    pub file: Option<String>,
135    /// Expected line number
136    pub line: Option<u32>,
137}
138
139/// Expectations for an evaluate result
140#[derive(Deserialize, Debug)]
141pub struct EvaluateExpectation {
142    /// Expected result value
143    pub result: Option<String>,
144    /// Expected result substring
145    pub result_contains: Option<String>,
146    /// Expected type name
147    #[serde(rename = "type")]
148    pub type_name: Option<String>,
149}