forked from uutils/coreutils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
170 lines (147 loc) · 5.3 KB
/
mod.rs
File metadata and controls
170 lines (147 loc) · 5.3 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use std::{env, path::PathBuf, process::Command, sync::OnceLock};
static UUDOC_BINARY_PATH: OnceLock<PathBuf> = OnceLock::new();
fn get_uudoc_command() -> Command {
let uudoc_binary = UUDOC_BINARY_PATH.get_or_init(|| {
let coreutils_binary = PathBuf::from(env!("CARGO_BIN_EXE_coreutils"));
coreutils_binary.parent().unwrap().join("uudoc")
});
Command::new(uudoc_binary)
}
#[test]
fn test_manpage_generation() {
let output = get_uudoc_command()
.arg("manpage")
.arg("ls")
.output()
.expect("Failed to execute command");
assert!(
output.status.success(),
"Command failed with status: {}",
output.status
);
assert!(
String::from_utf8_lossy(&output.stderr).contains("Warning: No tldr archive found"),
"stderr should contains tldr alert",
);
let output_str = String::from_utf8_lossy(&output.stdout);
assert!(output_str.contains("\n.TH ls"), "{output_str}");
assert!(output_str.contains('1'), "{output_str}");
assert!(output_str.contains("\n.SH NAME\nls"), "{output_str}");
}
#[test]
fn test_manpage_coreutils() {
let output = get_uudoc_command()
.arg("manpage")
.arg("coreutils")
.output()
.expect("Failed to execute command");
assert!(
output.status.success(),
"Command failed with status: {}",
output.status
);
assert!(
String::from_utf8_lossy(&output.stderr).contains("Warning: No tldr archive found"),
"stderr should contains tldr alert",
);
let output_str = String::from_utf8_lossy(&output.stdout);
assert!(output_str.contains("\n.TH coreutils"), "{output_str}");
assert!(output_str.contains("coreutils"), "{output_str}");
assert!(output_str.contains("\n.SH NAME\ncoreutils"), "{output_str}");
}
#[test]
fn test_manpage_invalid_utility() {
let output = get_uudoc_command()
.arg("manpage")
.arg("nonexistent_utility")
.output()
.expect("Failed to execute command");
// Should fail for invalid utility
assert!(!output.status.success(), "Command should have failed");
}
#[test]
fn test_completion_generation() {
let output = get_uudoc_command()
.arg("completion")
.arg("ls")
.arg("powershell")
.output()
.expect("Failed to execute command");
assert!(
output.status.success(),
"Command failed with status: {}",
output.status
);
assert!(
output.stderr.is_empty(),
"stderr should be empty but got: {}",
String::from_utf8_lossy(&output.stderr)
);
let output_str = String::from_utf8_lossy(&output.stdout);
assert!(
output_str.contains("using namespace System.Management.Automation"),
"{output_str}"
);
}
// Prevent regression to:
//
// ❯ uudoc manpage base64 | rg --fixed-strings -- 'base32'
// The data are encoded as described for the base32 alphabet in RFC 4648.
// to the bytes of the formal base32 alphabet. Use \-\-ignore\-garbage
// The data are encoded as described for the base32 alphabet in RFC 4648.
// to the bytes of the formal base32 alphabet. Use \-\-ignore\-garbage
#[test]
fn test_manpage_base64() {
let output = get_uudoc_command()
.arg("manpage")
.arg("base64")
.env("LANG", "C") // force locale to english to avoid issues with manpage output
.output()
.expect("Failed to execute command");
assert!(
output.status.success(),
"Command failed with status: {}",
output.status
);
assert!(
String::from_utf8_lossy(&output.stderr).contains("Warning: No tldr archive found"),
"stderr should contains tldr alert",
);
let output_str = String::from_utf8_lossy(&output.stdout);
assert!(output_str.contains("base64 alphabet"));
assert!(!output_str.to_ascii_lowercase().contains("base32"));
}
// Test to ensure markdown headers are correctly formatted in generated markdown files
// Prevents regression of https://github.com/uutils/coreutils/issues/10003
#[test]
fn test_markdown_header_format() {
use std::fs;
// Read a sample markdown file from the documentation
// This assumes the docs have been generated (they should be in the repo)
let docs_path = "docs/src/utils/cat.md";
if fs::metadata(docs_path).is_ok() {
let content =
fs::read_to_string(docs_path).expect("Failed to read generated markdown file");
// Verify Options header is in markdown format (## Options)
assert!(
content.contains("## Options"),
"Generated markdown should contain '## Options' header"
);
// Verify no HTML h2 tags for Options (old format)
assert!(
!content.contains("<h2>Options</h2>"),
"Generated markdown should not contain '<h2>Options</h2>' (use markdown format instead)"
);
// Also verify Examples if it exists
if content.contains("## Examples") {
assert!(
content.contains("## Examples"),
"Generated markdown should contain '## Examples' header in markdown format"
);
}
}
}