Skip to main content

bel7_cli/
testing.rs

1// Copyright (C) 2025-2026 Michael S. Klishin and Contributors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Test helper utilities.
16
17use std::process::Command;
18
19/// Environment variables used for shell detection.
20pub const SHELL_DETECTION_ENV_VARS: &[&str] = &[
21    "SHELL",
22    "NU_VERSION",
23    "FISH_VERSION",
24    "ZSH_VERSION",
25    "BASH_VERSION",
26    "PSModulePath",
27];
28
29/// Extension trait for `std::process::Command` to help with shell detection tests.
30pub trait CommandShellExt {
31    /// Clears environment variables used for shell detection.
32    ///
33    /// This removes `SHELL`, `NU_VERSION`, `FISH_VERSION`, `ZSH_VERSION`,
34    /// `BASH_VERSION`, and `PSModulePath` to ensure consistent shell detection
35    /// behavior in tests.
36    fn clear_shell_detection_env(&mut self) -> &mut Self;
37}
38
39impl CommandShellExt for Command {
40    fn clear_shell_detection_env(&mut self) -> &mut Self {
41        for var in SHELL_DETECTION_ENV_VARS {
42            self.env_remove(var);
43        }
44        self
45    }
46}