Skip to content

Commit 368229a

Browse files
committed
Modify the format of test-with-generated-opts.toml
1 parent e3394e2 commit 368229a

File tree

3 files changed

+133
-61
lines changed

3 files changed

+133
-61
lines changed

test-with-generated-opts.toml

Lines changed: 85 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,121 @@
11
# 手元でDropboxのテストケース(ある場合)で確認し、サンプルに含まれていないやつが大きいときはそれらをGitに入れない。
22
# その場合CI上でもサンプルだけテストする。(Dropboxから引っ張るのも面倒だし何より誰のアカウントを使うかという問題がある)
33

4-
[tests.abc054-c]
5-
matching = "Words"
4+
[[tests]]
65
name = "ABC054: C - One-stroke Path"
7-
8-
[tests.abc057-b]
6+
url = "https://atcoder.jp/contests/abc054/tasks/abc054_c"
7+
src = "./examples/abc054-c.rs"
8+
testcases = "./examples/testsets/abc054-c"
99
matching = "Words"
10-
name = "ABC057: B - Checkpoints"
1110

12-
[tests.abc084-d]
11+
[[tests]]
12+
name = "ABC057: B - Checkpoints"
13+
url = "https://atcoder.jp/contests/abc057/tasks/abc057_b"
14+
src = "./examples/abc057-b.rs"
15+
testcases = "./examples/testsets/abc057-b"
1316
matching = "Words"
14-
name = "ABC084: D - 2017-like Number"
1517

16-
[tests.abc118-b]
18+
[[tests]]
19+
name = "ABC084: D - 2017-like Number"
20+
url = "https://atcoder.jp/contests/abc084/tasks/abc084_d"
21+
src = "./examples/abc084-d.rs"
22+
testcases = "./examples/testsets/abc084-d"
1723
matching = "Words"
18-
name = "ABC118: B - Foods Loved by Everyone"
1924

20-
[tests.abc120-d]
25+
[[tests]]
26+
name = "ABC118: B - Foods Loved by Everyone"
27+
url = "https://atcoder.jp/contests/abc118/tasks/abc118_b"
28+
src = "./examples/abc118-b.rs"
29+
testcases = "./examples/testsets/abc118-b"
2130
matching = "Words"
22-
name = "ABC120: D - Decayed Bridges"
2331

24-
[tests.abc121-b]
32+
[[tests]]
33+
name = "ABC120: D - Decayed Bridges"
34+
url = "https://atcoder.jp/contests/abc120/tasks/abc120_d"
35+
src = "./examples/abc120-d.rs"
36+
testcases = "./examples/testsets/abc120-d"
2537
matching = "Words"
26-
name = "ABC121: B - Can you solve this?"
2738

28-
[tests.abc129-f]
39+
[[tests]]
40+
name = "ABC121: B - Can you solve this?"
41+
url = "https://atcoder.jp/contests/abc121/tasks/abc121_b"
42+
src = "./examples/abc121-b.rs"
43+
testcases = "./examples/testsets/abc121-b"
2944
matching = "Words"
30-
name = "ABC129: F - Takahashi's Basics in Education and Learning"
3145

32-
[tests.abc142-d]
46+
[[tests]]
47+
name = "ABC129: F - Takahashi's Basics in Education and Learning"
48+
url = "https://atcoder.jp/contests/abc129/tasks/abc129_f"
49+
src = "./examples/abc129-f.rs"
50+
testcases = "./examples/testsets/abc129-f"
3351
matching = "Words"
52+
53+
[[tests]]
3454
name = "ABC142: D - Disjoint Set of Common Divisors"
55+
url = "https://atcoder.jp/contests/abc142/tasks/abc142_d"
56+
src = "./examples/abc142-d.rs"
57+
testcases = "./examples/testsets/abc142-d"
58+
matching = "Words"
3559

36-
[tests.abc144-d]
60+
[[tests]]
3761
name = "ABC144: D - Water Bottle"
38-
matching = { FloatOr = { abs = 1e-6, rel = 1e-6 }}
62+
url = "https://atcoder.jp/contests/abc144/tasks/abc144_d"
63+
src = "./examples/abc144-d.rs"
64+
testcases = "./examples/testsets/abc144-d"
65+
matching = { FloatOr = { abs = 1e-6, rel = 1e-6 } }
3966

40-
[tests.apg4b-a]
41-
matching = "Exact"
67+
[[tests]]
4268
name = "APG4b: A - 1.00.はじめに"
69+
url = "https://atcoder.jp/contests/APG4b/tasks/APG4b_a"
70+
src = "./examples/apg4b-a.rs"
71+
testcases = "./examples/testsets/apg4b-a"
72+
matching = "Exact"
4373

44-
[tests.apg4b-ex25]
45-
matching = "Words"
74+
[[tests]]
4675
name = "APG4b: EX25 - 集合の操作 / 3.05"
76+
url = "https://atcoder.jp/contests/APG4b/tasks/APG4b_bx"
77+
src = "./examples/apg4b-ex25.rs"
78+
testcases = "./examples/testsets/apg4b-ex25"
79+
matching = "Words"
4780

48-
[tests.apg4b-ex26]
49-
matching = "Exact"
81+
[[tests]]
5082
name = "APG4b: EX26 - 電卓を作ろう3 / 3.06"
83+
url = "https://atcoder.jp/contests/APG4b/tasks/APG4b_bw"
84+
src = "./examples/apg4b-ex26.rs"
85+
testcases = "./examples/testsets/apg4b-ex26"
86+
matching = "Exact"
5187

52-
[tests.arc065-c]
53-
matching = "Words"
88+
[[tests]]
5489
name = "ABC049 / ARC065: C - 白昼夢 / Daydream"
55-
56-
[tests.arc084-c]
90+
url = "https://atcoder.jp/contests/arc065/tasks/arc065_a"
91+
src = "./examples/arc065-c.rs"
92+
testcases = "./examples/testsets/arc065-c"
5793
matching = "Words"
58-
name = "ABC077 / ARC084: C - Snuke Festival"
5994

60-
[tests.atc001-b]
95+
[[tests]]
96+
name = "ABC077 / ARC084: C - Snuke Festival"
97+
url = "https://atcoder.jp/contests/arc084/tasks/arc084_a"
98+
src = "./examples/arc084-c.rs"
99+
testcases = "./examples/testsets/arc084-c"
61100
matching = "Words"
62-
name = "ATC001: B - Union Find"
63101

64-
[tests.atc002-b]
102+
[[tests]]
103+
name = "ATC001: B - Union Find"
104+
url = "https://atcoder.jp/contests/atc001/tasks/unionfind_a"
105+
src = "./examples/atc001-b.rs"
106+
testcases = "./examples/testsets/atc001-b"
65107
matching = "Words"
66-
name = "ATC002: B - n^p mod m"
67108

68-
[tests.practice-a]
109+
[[tests]]
110+
name = "ATC002: B - n^p mod m"
111+
url = "https://atcoder.jp/contests/atc002/tasks/atc002_b"
112+
src = "./examples/atc002-b.rs"
113+
testcases = "./examples/testsets/atc002-b"
69114
matching = "Words"
115+
116+
[[tests]]
70117
name = "practice contest: A - Welcome to AtCoder"
118+
url = "https://atcoder.jp/contests/practice/tasks/practice_1"
119+
src = "./examples/practice-a.rs"
120+
testcases = "./examples/testsets/practice-a"
121+
matching = "Words"

tools/test-with-generated-opts/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ description = "Test with `rustc-dep-option-generator`."
99
anyhow = "1.0.25"
1010
approx = "0.3.2"
1111
env_logger = "0.7.1"
12-
indexmap = { version = "1.3.0", features = ["serde-1"] }
1312
itertools = "0.8.2"
1413
log = "0.4.8"
1514
serde = { version = "1.0.104", features = ["derive"] }

tools/test-with-generated-opts/src/main.rs

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use anyhow::{anyhow, Context as _};
22
use approx::{abs_diff_eq, relative_eq};
33
use env_logger::fmt::Color;
4-
use indexmap::IndexMap;
54
use itertools::Itertools as _;
65
use log::{info, Level, LevelFilter};
76
use serde::Deserialize;
@@ -54,7 +53,7 @@ fn main() -> anyhow::Result<()> {
5453
.filter_module("test_with_generated_opts", LevelFilter::Info)
5554
.init();
5655

57-
let Tests { tests } = fs::read_to_string(&config)
56+
let Config { tests } = fs::read_to_string(&config)
5857
.map_err(anyhow::Error::from)
5958
.and_then(|s| toml::from_str(&s).map_err(Into::into))
6059
.with_context(|| format!("Failed to read {}", config.display()))?;
@@ -63,21 +62,28 @@ fn main() -> anyhow::Result<()> {
6362

6463
let tests = tests
6564
.into_iter()
66-
.map(|(slug, Test { name, matching })| {
67-
let src = Path::new("./examples").join(&slug).with_extension("rs");
68-
let testsets = Path::new("./examples/testsets").join(&slug);
69-
let binary = compile(&src, tempdir.path(), &slug)?;
70-
Ok((name, matching, testsets, binary))
71-
})
65+
.map(
66+
|Test {
67+
name,
68+
url,
69+
src,
70+
testcases,
71+
matching,
72+
}| {
73+
let slug = src.file_stem().unwrap_or_default();
74+
let binary = compile(&src, tempdir.path(), slug)?;
75+
Ok((name, url, matching, testcases, binary))
76+
},
77+
)
7278
.collect::<anyhow::Result<Vec<_>>>()?;
7379

74-
for (name, matching, testsets, binary) in tests {
75-
test(&name, matching, &testsets, &binary)?;
80+
for (name, url, matching, testcases, binary) in tests {
81+
test(&name, &url, matching, &testcases, &binary)?;
7682
}
7783
Ok(())
7884
}
7985

80-
fn compile(src: &Path, tempdir: &Path, dir_name: &str) -> anyhow::Result<PathBuf> {
86+
fn compile(src: &Path, tempdir: &Path, dir_name: &OsStr) -> anyhow::Result<PathBuf> {
8187
fn run_command<S1: AsRef<OsStr>, S2: AsRef<OsStr>, I: IntoIterator<Item = S2>>(
8288
program: S1,
8389
args: I,
@@ -142,20 +148,31 @@ fn compile(src: &Path, tempdir: &Path, dir_name: &str) -> anyhow::Result<PathBuf
142148
Ok(out)
143149
}
144150

145-
fn test(task_name: &str, matching: Matching, testsets: &Path, binary: &Path) -> anyhow::Result<()> {
151+
fn test(
152+
task_name: &str,
153+
url: &str,
154+
matching: Matching,
155+
testcases: &Path,
156+
binary: &Path,
157+
) -> anyhow::Result<()> {
146158
let testsets = {
147-
let find_files = |dir: &str| -> _ {
148-
fs::read_dir(testsets.join(dir))?
149-
.map(|entry| {
150-
let path = entry?.path();
151-
let name = path
152-
.file_stem()
153-
.unwrap_or_default()
154-
.to_string_lossy()
155-
.into_owned();
156-
Ok((name, path))
159+
let find_files = |dir_file_name: &str| -> _ {
160+
let dir = testcases.join(dir_file_name);
161+
fs::read_dir(&dir)
162+
.and_then(|read_dir| {
163+
read_dir
164+
.map(|entry| {
165+
let path = entry?.path();
166+
let name = path
167+
.file_stem()
168+
.unwrap_or_default()
169+
.to_string_lossy()
170+
.into_owned();
171+
Ok((name, path))
172+
})
173+
.collect::<io::Result<HashMap<_, _>>>()
157174
})
158-
.collect::<io::Result<HashMap<_, _>>>()
175+
.with_context(|| format!("Failed to read {}", dir.display()))
159176
};
160177

161178
let (ins, outs) = (find_files("in")?, find_files("out")?);
@@ -168,7 +185,9 @@ fn test(task_name: &str, matching: Matching, testsets: &Path, binary: &Path) ->
168185
.collect::<BTreeMap<_, _>>()
169186
};
170187

171-
info!("Testing {} for {:?}", binary.display(), task_name);
188+
info!("Testing {}", binary.display());
189+
info!(" Name: {:?}", task_name);
190+
info!(" URL: {}", url);
172191

173192
for (test_name, (path_in, path_out)) in testsets {
174193
fn read_to_string(path: &Path) -> anyhow::Result<String> {
@@ -218,13 +237,16 @@ fn test(task_name: &str, matching: Matching, testsets: &Path, binary: &Path) ->
218237
}
219238

220239
#[derive(Debug, Deserialize)]
221-
struct Tests {
222-
tests: IndexMap<String, Test>,
240+
struct Config {
241+
tests: Vec<Test>,
223242
}
224243

225244
#[derive(Debug, Deserialize)]
226245
struct Test {
227246
name: String,
247+
url: String,
248+
src: PathBuf,
249+
testcases: PathBuf,
228250
matching: Matching,
229251
}
230252

0 commit comments

Comments
 (0)