-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib.rs
140 lines (122 loc) · 3.93 KB
/
lib.rs
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
#![feature(exit_status_error)]
#![feature(slice_flatten)]
#![allow(clippy::missing_panics_doc)]
use std::{env, fmt::Write, path::PathBuf, process};
use expect_test::expect_file;
pub fn fmt() {
#[cfg(not(miri))]
{
let mut command = process::Command::new(env::var("CARGO").unwrap());
command.args(["fmt", "--all"]);
let config = "--config=version=Two,imports_granularity=Crate,\
group_imports=StdExternalCrate,use_field_init_shorthand=true,\
format_code_in_doc_comments=true,format_macro_bodies=true,\
format_macro_matchers=true,format_strings=true,wrap_comments=true";
if env::var_os("UPDATE_EXPECT").is_some() {
command
.args(["--", config])
.status()
.unwrap()
.exit_ok()
.unwrap();
} else {
command
.args(["--", "--check", config])
.status()
.unwrap()
.exit_ok()
.unwrap();
}
}
}
pub fn clippy() {
#[cfg(not(miri))]
{
let mut command = process::Command::new(env::var("CARGO").unwrap());
command.args(["clippy", "--workspace"]);
let config = [
["-W", "clippy::all"],
["-W", "clippy::pedantic"],
["-W", "clippy::nursery"],
["-W", "clippy::cargo"],
["-W", "clippy::float_cmp_const"],
["-W", "clippy::empty_structs_with_brackets"],
["-A", "clippy::multiple_crate_versions"],
]
.flatten();
if env::var_os("UPDATE_EXPECT").is_some() {
command
.args(["--fix", "--allow-dirty", "--allow-staged", "--"])
.args(config)
.status()
.unwrap()
.exit_ok()
.unwrap();
} else {
command
.args(["--", "-D", "warnings"])
.args(config)
.status()
.unwrap()
.exit_ok()
.unwrap();
}
}
}
pub fn api() {
#[cfg(not(miri))] // gnu_get_libc_version breaks miri
{
let json_path = rustdoc_json::Builder::default()
.all_features(true)
.build()
.unwrap();
let api = public_api::Builder::from_rustdoc_json(json_path)
.build()
.unwrap()
.to_string();
expect_file![path_from_root("api.golden")].assert_eq(&api);
}
}
pub fn help_for_review2(mut command: clap_builder::Command) {
#[derive(Copy, Clone)]
enum LongOrShortHelp {
Long,
Short,
}
fn write_help(
buffer: &mut impl Write,
cmd: &mut clap_builder::Command,
long_or_short_help: LongOrShortHelp,
) {
write!(
buffer,
"{}",
match long_or_short_help {
LongOrShortHelp::Long => cmd.render_long_help(),
LongOrShortHelp::Short => cmd.render_help(),
}
)
.unwrap();
for sub in cmd.get_subcommands_mut() {
writeln!(buffer).unwrap();
writeln!(buffer, "---").unwrap();
writeln!(buffer).unwrap();
write_help(buffer, sub, long_or_short_help);
}
}
#[cfg(not(miri))] // wrap_help breaks miri
{
command.build();
let mut long = String::new();
let mut short = String::new();
write_help(&mut long, &mut command, LongOrShortHelp::Long);
write_help(&mut short, &mut command, LongOrShortHelp::Short);
expect_file![path_from_root("command-reference.golden")].assert_eq(&long);
expect_file![path_from_root("command-reference-short.golden")].assert_eq(&short);
}
}
fn path_from_root(path: &str) -> PathBuf {
let mut dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
dir.push(path);
dir
}