riir
This commit is contained in:
parent
da4bc139eb
commit
68c85e358e
49 changed files with 8848 additions and 5483 deletions
100
tests/manpage_cli.rs
Normal file
100
tests/manpage_cli.rs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
use std::fs;
|
||||
use std::process::Command;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
fn unique_temp_dir(name: &str) -> std::path::PathBuf {
|
||||
let nanos = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.expect("system time")
|
||||
.as_nanos();
|
||||
std::env::temp_dir().join(format!("{name}-{}-{nanos}", std::process::id()))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn manpage_command_uses_synopsis_name() {
|
||||
let root = unique_temp_dir("inshellah-manpage-cli");
|
||||
fs::create_dir_all(&root).expect("temp dir");
|
||||
let manpage = root.join("btrfs-check.8");
|
||||
fs::write(
|
||||
&manpage,
|
||||
r#".SH SYNOPSIS
|
||||
btrfs check [options] <device>
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB\-\-repair\fR
|
||||
try to repair the filesystem
|
||||
"#,
|
||||
)
|
||||
.expect("write manpage");
|
||||
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_inshellah"))
|
||||
.arg("manpage")
|
||||
.arg(&manpage)
|
||||
.output()
|
||||
.expect("run inshellah manpage");
|
||||
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"stderr = {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let stdout = String::from_utf8(output.stdout).expect("stdout");
|
||||
assert!(
|
||||
stdout.contains("export extern \"btrfs check\""),
|
||||
"stdout = {stdout}"
|
||||
);
|
||||
assert!(
|
||||
!stdout.contains("export extern \"btrfs-check\""),
|
||||
"stdout = {stdout}"
|
||||
);
|
||||
|
||||
let _ = fs::remove_dir_all(root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn manpage_command_strips_git_style_subcommand_prefixes() {
|
||||
let root = unique_temp_dir("inshellah-manpage-cli");
|
||||
fs::create_dir_all(&root).expect("temp dir");
|
||||
let manpage = root.join("git.1");
|
||||
fs::write(
|
||||
&manpage,
|
||||
r#".SH SYNOPSIS
|
||||
git [--version] [--help] <command> [<args>]
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB\-\-version\fR
|
||||
show version
|
||||
.SH "GIT COMMANDS"
|
||||
.SS "Main porcelain commands"
|
||||
.PP
|
||||
.BR git-add (1)
|
||||
.RS 4
|
||||
Add file contents to the index.
|
||||
.RE
|
||||
"#,
|
||||
)
|
||||
.expect("write manpage");
|
||||
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_inshellah"))
|
||||
.arg("manpage")
|
||||
.arg(&manpage)
|
||||
.output()
|
||||
.expect("run inshellah manpage");
|
||||
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"stderr = {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let stdout = String::from_utf8(output.stdout).expect("stdout");
|
||||
assert!(
|
||||
stdout.contains("export extern \"git add\""),
|
||||
"stdout = {stdout}"
|
||||
);
|
||||
assert!(
|
||||
!stdout.contains("export extern \"git git-add\""),
|
||||
"stdout = {stdout}"
|
||||
);
|
||||
|
||||
let _ = fs::remove_dir_all(root);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue