forked from pacman-repo-builder/pacman-repo-builder
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutdated.rs
234 lines (207 loc) · 6.59 KB
/
outdated.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
use command_extra::CommandExtra;
use pipe_trait::*;
use std::{fs, path::PathBuf, process::Command};
const EXE: &str = env!("CARGO_BIN_EXE_build-pacman-repo");
const ROOT: &str = env!("CARGO_MANIFEST_DIR");
fn work_dir(branch: &'static str) -> PathBuf {
ROOT.pipe(PathBuf::from)
.join("tests")
.join("fixtures")
.join("outdated")
.join(branch)
}
fn setup_test_files() {
let base_dir = ROOT
.pipe(PathBuf::from)
.join("tests")
.join("fixtures")
.join("outdated")
.join("__template__")
.join("repo");
let files = vec![
"out-of-date-by-arch-1.2.3-1-i686.pkg.tar.zst",
"out-of-date-by-arch-1.2.3-1-x86_64.pkg.tar.zst",
"out-of-date-by-epoch-1.2.3-1-any.pkg.tar.zst",
"out-of-date-by-epoch-1:-1.2.3-1-any.pkg.tar.zst",
"out-of-date-by-epoch-2:-1.2.3-1-any.pkg.tar.zst",
"out-of-date-by-pkgrel-0.0.0-1.pkg.tar.zst",
"out-of-date-by-pkgrel-0.0.1-1.pkg.tar.zst",
"out-of-date-by-pkgrel-0.1.0-1.pkg.tar.zst",
"out-of-date-by-pkgrel-1.0.0-1.pkg.tar.zst",
"out-of-date-by-pkgrel-1.2.3-1.pkg.tar.zst",
"out-of-date-by-pkgrel-1.2.3-2.pkg.tar.zst",
"repo.db",
"up-to-date-pkgbuild-1.2.3-1-any.pkg.tar.zst",
"up-to-date-srcinfo-1.2.3-1-any.pkg.tar.zst",
];
// Create the base directory if it doesn't exist
if !base_dir.exists() {
fs::create_dir_all(&base_dir).expect("Failed to create base directory");
}
// Create the files
for file in files {
let file_path = base_dir.join(file);
fs::File::create(file_path).expect("Failed to create file");
}
}
fn init(branch: &'static str) -> Command {
setup_test_files();
Command::new(EXE)
.with_current_dir(work_dir(branch))
.with_arg("outdated")
}
fn output(mut command: Command) -> (String, String, bool) {
let output = command.output().expect("get output from a command");
let stdout = output
.stdout
.pipe(String::from_utf8)
.expect("convert stdout to UTF-8");
let stderr = output
.stderr
.pipe(String::from_utf8)
.expect("convert stderr to UTF-8");
let success = output.status.success();
(stdout, stderr, success)
}
macro_rules! test_case {
($name:ident, $branch:literal, $details:literal, $expected:literal) => {
#[test]
fn $name() {
let (stdout, stderr, success) = init($branch)
.with_arg("--details")
.with_arg($details)
.pipe(output);
eprintln!(" ==> command stdout\n{}", stdout.as_str());
eprintln!(" ==> command stderr\n{}", stderr.as_str());
let actual = (stdout.as_str(), stderr.trim(), success);
let expected = (include_str!($expected), "", true);
assert_eq!(actual, expected);
}
};
}
test_case!(
details_pkgname,
"simple",
"pkgname",
"./expected-output/outdated/simple/details-pkgname.stdout.txt"
);
test_case!(
details_pkg_file_path,
"simple",
"pkg-file-path",
"./expected-output/outdated/simple/details-pkg-file-path.stdout.txt"
);
test_case!(
details_lossy_yaml,
"simple",
"lossy-yaml",
"./expected-output/outdated/simple/details-lossy-yaml.stdout.yaml"
);
test_case!(
details_strict_yaml,
"simple",
"strict-yaml",
"./expected-output/outdated/simple/details-strict-yaml.stdout.yaml"
);
test_case!(
details_pkgname_arch_filter_any,
"arch-filter-any",
"pkgname",
"./expected-output/outdated/arch-filter-any/details-pkgname.stdout.txt"
);
test_case!(
details_pkg_file_path_arch_filter_any,
"arch-filter-any",
"pkg-file-path",
"./expected-output/outdated/arch-filter-any/details-pkg-file-path.stdout.txt"
);
test_case!(
details_lossy_yaml_arch_filter_any,
"arch-filter-any",
"lossy-yaml",
"./expected-output/outdated/arch-filter-any/details-lossy-yaml.stdout.yaml"
);
test_case!(
details_strict_yaml_arch_filter_any,
"arch-filter-any",
"strict-yaml",
"./expected-output/outdated/arch-filter-any/details-strict-yaml.stdout.yaml"
);
test_case!(
details_pkgname_arch_filter_x86_64,
"arch-filter-x86_64",
"pkgname",
"./expected-output/outdated/arch-filter-x86_64/details-pkgname.stdout.txt"
);
test_case!(
details_pkg_file_path_arch_filter_x86_64,
"arch-filter-x86_64",
"pkg-file-path",
"./expected-output/outdated/arch-filter-x86_64/details-pkg-file-path.stdout.txt"
);
test_case!(
details_lossy_yaml_arch_filter_x86_64,
"arch-filter-x86_64",
"lossy-yaml",
"./expected-output/outdated/arch-filter-x86_64/details-lossy-yaml.stdout.yaml"
);
test_case!(
details_strict_yaml_arch_filter_x86_64,
"arch-filter-x86_64",
"strict-yaml",
"./expected-output/outdated/arch-filter-x86_64/details-strict-yaml.stdout.yaml"
);
test_case!(
details_pkg_file_record_failed_builds_empty,
"record-failed-builds-empty",
"pkg-file-path",
"./expected-output/outdated/record-failed-builds-empty/details-pkg-file-path.stdout.txt"
);
test_case!(
details_lossy_record_failed_builds_empty,
"record-failed-builds-empty",
"lossy-yaml",
"./expected-output/outdated/record-failed-builds-empty/details-lossy-yaml.stdout.yaml"
);
test_case!(
details_strict_record_failed_builds_empty,
"record-failed-builds-empty",
"strict-yaml",
"./expected-output/outdated/record-failed-builds-empty/details-strict-yaml.stdout.yaml"
);
test_case!(
details_pkg_file_record_failed_builds_some,
"record-failed-builds-some",
"pkg-file-path",
"./expected-output/outdated/record-failed-builds-some/details-pkg-file-path.stdout.txt"
);
test_case!(
details_lossy_record_failed_builds_some,
"record-failed-builds-some",
"lossy-yaml",
"./expected-output/outdated/record-failed-builds-some/details-lossy-yaml.stdout.yaml"
);
test_case!(
details_strict_record_failed_builds_some,
"record-failed-builds-some",
"strict-yaml",
"./expected-output/outdated/record-failed-builds-some/details-strict-yaml.stdout.yaml"
);
#[test]
fn validate_yaml_output() {
use serde_yaml::{from_str, Value};
macro_rules! load {
($path:literal) => {
include_str!($path)
.split("---")
.skip(1)
.map(from_str::<Value>)
.collect::<Result<Vec<_>, _>>()
.unwrap()
};
}
assert_eq!(
load!("./expected-output/outdated/simple/details-lossy-yaml.stdout.yaml"),
load!("./expected-output/outdated/simple/details-strict-yaml.stdout.yaml"),
);
}