Skip to content

Commit 6985788

Browse files
committed
test: fix state pollution
1 parent c5af919 commit 6985788

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

tests/plugin_tests.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ fn test_plugin_system_integration() {
99
let temp_dir = TempDir::new().unwrap();
1010
let plugin_dir = temp_dir.path();
1111

12+
// Get the current working directory to ensure we run commands from the right place
13+
let current_dir = std::env::current_dir().expect("Failed to get current directory");
14+
1215
// Create a mock plugin
1316
let plugin_content = r#"#!/bin/bash
1417
echo "Mock health plugin executed"
@@ -27,6 +30,7 @@ exit 0
2730
// Test list-plugins with our mock plugin
2831
let output = Command::new("cargo")
2932
.args(["run", "--", "--list-plugins"])
33+
.current_dir(&current_dir)
3034
.env(
3135
"PATH",
3236
format!(
@@ -46,6 +50,7 @@ exit 0
4650
// Test calling the external plugin
4751
let output = Command::new("cargo")
4852
.args(["run", "--", "health", "--test", "argument"])
53+
.current_dir(&current_dir)
4954
.env(
5055
"PATH",
5156
format!(
@@ -65,6 +70,7 @@ exit 0
6570
// Test non-existent plugin
6671
let output = Command::new("cargo")
6772
.args(["run", "--", "nonexistent"])
73+
.current_dir(&current_dir)
6874
.output()
6975
.expect("Failed to run nonexistent plugin");
7076

@@ -77,13 +83,37 @@ exit 0
7783
fn test_builtin_commands_still_work() {
7884
// Ensure built-in commands are not affected by plugin system
7985

86+
// Get the current working directory to ensure we run commands from the right place
87+
let current_dir = std::env::current_dir().expect("Failed to get current directory");
88+
89+
// Build the binary first to avoid compilation races
90+
let build_output = Command::new("cargo")
91+
.args(["build"])
92+
.current_dir(&current_dir)
93+
.output()
94+
.expect("Failed to build binary");
95+
96+
if !build_output.status.success() {
97+
eprintln!("Build failed:");
98+
eprintln!("stdout: {}", String::from_utf8_lossy(&build_output.stdout));
99+
eprintln!("stderr: {}", String::from_utf8_lossy(&build_output.stderr));
100+
panic!("Cannot run tests without successful build");
101+
}
102+
80103
// Test help command
81104
let output = Command::new("cargo")
82105
.args(["run", "--", "--help"])
106+
.current_dir(&current_dir)
83107
.output()
84108
.expect("Failed to run help");
85109

86-
assert!(output.status.success());
110+
if !output.status.success() {
111+
eprintln!("Help command failed:");
112+
eprintln!("stdout: {}", String::from_utf8_lossy(&output.stdout));
113+
eprintln!("stderr: {}", String::from_utf8_lossy(&output.stderr));
114+
eprintln!("status: {}", output.status);
115+
}
116+
assert!(output.status.success(), "Help command should succeed");
87117
let stdout = String::from_utf8_lossy(&output.stdout);
88118
assert!(stdout.contains("A cli tool to manage multiple GitHub repositories"));
89119
assert!(stdout.contains("list-plugins"));
@@ -93,6 +123,7 @@ fn test_builtin_commands_still_work() {
93123
let temp_empty_dir = TempDir::new().unwrap();
94124
let output = Command::new("cargo")
95125
.args(["run", "--", "--list-plugins"])
126+
.current_dir(&current_dir)
96127
.env(
97128
"PATH",
98129
format!(
@@ -104,7 +135,16 @@ fn test_builtin_commands_still_work() {
104135
.output()
105136
.expect("Failed to run list-plugins");
106137

107-
assert!(output.status.success());
138+
if !output.status.success() {
139+
eprintln!("List-plugins command failed:");
140+
eprintln!("stdout: {}", String::from_utf8_lossy(&output.stdout));
141+
eprintln!("stderr: {}", String::from_utf8_lossy(&output.stderr));
142+
eprintln!("status: {}", output.status);
143+
}
144+
assert!(
145+
output.status.success(),
146+
"List-plugins command should succeed"
147+
);
108148
let stdout = String::from_utf8_lossy(&output.stdout);
109149
assert!(stdout.contains("No external plugins found"));
110150
}

0 commit comments

Comments
 (0)