use super::common::*;
use std::fs;
#[test]
fn test_plugin_list_empty() {
let temp = create_temp_project();
let output = linthis_cmd()
.args(["plugin", "list"])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
assert_exit_code(&output, 0);
}
#[test]
fn test_plugin_add_invalid_url() {
let temp = create_temp_project();
let output = linthis_cmd()
.args(["plugin", "add", "test-plugin", "not-a-valid-url"])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
let _ = output.status;
}
#[test]
fn test_plugin_add_with_name() {
let temp = create_temp_project();
let output = linthis_cmd()
.args([
"plugin",
"add",
"test-plugin",
"https://example.com/test.git",
])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
assert_exit_code(&output, 0);
let list_output = linthis_cmd()
.args(["plugin", "list"])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
let stdout = String::from_utf8_lossy(&list_output.stdout);
assert!(
stdout.contains("test-plugin") || stdout.contains("example.com"),
"Plugin should appear in list"
);
}
#[test]
fn test_plugin_remove_nonexistent() {
let temp = create_temp_project();
let output = linthis_cmd()
.args(["plugin", "remove", "nonexistent-plugin"])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
let _ = output.status;
}
#[test]
fn test_plugin_add_remove_workflow() {
let temp = create_temp_project();
let add_output = linthis_cmd()
.args([
"plugin",
"add",
"workflow-test",
"https://github.com/example/plugin.git",
])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
assert_exit_code(&add_output, 0);
let remove_output = linthis_cmd()
.args(["plugin", "remove", "workflow-test"])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
assert_exit_code(&remove_output, 0);
let list_output = linthis_cmd()
.args(["plugin", "list"])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
let stdout = String::from_utf8_lossy(&list_output.stdout);
assert!(
!stdout.contains("workflow-test"),
"Plugin should not appear in list after removal"
);
}
#[test]
fn test_plugin_sync_empty() {
let temp = create_temp_project();
let output = linthis_cmd()
.args(["plugin", "sync"])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
assert_exit_code(&output, 0);
}
#[test]
fn test_plugin_global_flag() {
let temp = create_temp_project();
let output = linthis_cmd()
.args(["plugin", "list", "--global"])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
assert_exit_code(&output, 0);
}
#[test]
fn test_plugin_add_duplicate() {
let temp = create_temp_project();
let first_add = linthis_cmd()
.args([
"plugin",
"add",
"dup-test",
"https://example.com/dup.git",
])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
assert_exit_code(&first_add, 0);
let second_add = linthis_cmd()
.args([
"plugin",
"add",
"dup-test",
"https://example.com/dup.git",
])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
let _ = second_add.status;
}
#[test]
fn test_plugin_validate() {
let temp = create_temp_project();
let plugin_dir = temp.path().join(".linthis/plugins/test-validate");
fs::create_dir_all(&plugin_dir).expect("Failed to create plugin dir");
let plugin_toml = r#"[plugin]
name = "test-validate"
version = "0.1.0"
description = "Test plugin"
[linters]
"#;
fs::write(plugin_dir.join("plugin.toml"), plugin_toml)
.expect("Failed to write plugin.toml");
let output = linthis_cmd()
.args(["plugin", "validate", "test-validate"])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
let _ = output.status;
}
#[test]
fn test_plugin_clean() {
let temp = create_temp_project();
let output = linthis_cmd()
.args(["plugin", "clean"])
.current_dir(temp.path())
.output()
.expect("Failed to run linthis");
assert_exit_code(&output, 0);
}