1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
use std::process::Command;
use std::str;
fn command() -> Command {
Command::new(env!("CARGO_BIN_EXE_mikusays"))
}
#[test]
fn test_cli_list_styles() {
let output = command()
.arg("--list")
.output()
.expect("Failed to execute command");
assert!(output.status.success());
let stdout = str::from_utf8(&output.stdout).expect("Invalid UTF-8");
// Should contain style listing information
assert!(stdout.contains("Available Miku art styles:"));
assert!(stdout.contains("Total styles:"));
assert!(stdout.contains("--- Style"));
}
#[test]
fn test_cli_error_no_text() {
let output = command().output().expect("Failed to execute command");
assert!(!output.status.success());
let stderr = str::from_utf8(&output.stderr).expect("Invalid UTF-8");
assert!(stderr.contains("Error: Text is required when not using --list"));
}
#[test]
fn test_cli_error_conflicting_args() {
let output = command()
.arg("Test")
.arg("--rainbow")
.arg("--color")
.arg("red")
.output()
.expect("Failed to execute command");
assert!(!output.status.success());
let stderr = str::from_utf8(&output.stderr).expect("Invalid UTF-8");
assert!(stderr.contains("cannot be used with"));
}
#[test]
fn test_cli_basic_functionality() {
// Test that the binary runs and produces some output
let output = command()
.arg("--list")
.output()
.expect("Failed to execute command");
assert!(output.status.success());
}
#[test]
fn test_cli_no_color_overrides_solid_color() {
let output = command()
.args(["test", "--style", "0", "--color", "red", "--no-color"])
.env("TERM", "xterm-256color")
.output()
.expect("Failed to execute command");
assert!(output.status.success());
assert!(!output.stdout.contains(&0x1b));
}
#[test]
fn test_cli_no_color_environment_overrides_gradient() {
let output = command()
.args(["test", "--style", "0", "--gradient", "red:blue"])
.env("NO_COLOR", "1")
.env("TERM", "xterm-256color")
.output()
.expect("Failed to execute command");
assert!(output.status.success());
assert!(!output.stdout.contains(&0x1b));
}
#[test]
fn test_cli_rejects_out_of_range_style_without_panicking() {
let output = command()
.args(["test", "--style", "999"])
.output()
.expect("Failed to execute command");
assert_eq!(output.status.code(), Some(2));
let stderr = str::from_utf8(&output.stderr).expect("Invalid UTF-8");
assert!(stderr.contains("style 999 does not exist"));
assert!(!stderr.contains("panicked"));
}
#[test]
fn test_cli_rejects_negative_style() {
let output = command()
.args(["test", "--style", "-1"])
.output()
.expect("Failed to execute command");
assert_eq!(output.status.code(), Some(2));
let stderr = str::from_utf8(&output.stderr).expect("Invalid UTF-8");
assert!(!stderr.contains("panicked"));
}
#[test]
fn test_cli_rejects_out_of_range_saturation() {
let output = command()
.args(["test", "--rainbow", "--saturation", "101"])
.output()
.expect("Failed to execute command");
assert_eq!(output.status.code(), Some(2));
}
#[test]
fn test_cli_rejects_invalid_color() {
let output = command()
.args(["test", "--color", "not-a-color"])
.output()
.expect("Failed to execute command");
assert_eq!(output.status.code(), Some(2));
let stderr = str::from_utf8(&output.stderr).expect("Invalid UTF-8");
assert!(stderr.contains("invalid color 'not-a-color'"));
}
|