Skip to content

Commit 5b5a6c2

Browse files
committed
test-with-generated-optstest-examples
1 parent 211ceb2 commit 5b5a6c2

File tree

5 files changed

+26
-65
lines changed

5 files changed

+26
-65
lines changed

.cargo/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[alias]
22
dep-tests = ["run", "--manifest-path", "./tools/dep-tests/Cargo.toml", "--"]
3-
test-with-generated-opts = ["run", "--manifest-path", "./tools/test-with-generated-opts/Cargo.toml", "--"]
3+
test-examples = ["run", "--manifest-path", "./tools/test-examples/Cargo.toml", "--"]

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/tools/dep-tests/Cargo.lock
2-
/tools/test-with-generated-opts/Cargo.lock
2+
/tools/test-examples/Cargo.lock
33
**/target/
44
**/*.rs.bk
55
**/*~
File renamed without changes.

tools/test-with-generated-opts/Cargo.toml renamed to tools/test-examples/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
2-
name = "test-with-generated-opts"
2+
name = "test-examples"
33
version = "0.0.0"
44
edition = "2018"
55
publish = false
6-
description = "Test with `rustc-dep-option-generator`."
6+
description = "Test the examples"
77

88
[dependencies]
99
anyhow = "1.0.26"
@@ -14,14 +14,14 @@ itertools = "0.8.2"
1414
log = "0.4.8"
1515
maplit = "1.0.2"
1616
nom = "5.1.0"
17-
once_cell = "1.3.0"
17+
once_cell = "1.3.1"
1818
regex = "1.3.3"
1919
scraper = "0.11.0"
2020
serde = { version = "1.0.104", features = ["derive"] }
21-
serde_json = "1.0.44"
21+
serde_json = "1.0.45"
2222
shell-escape = "0.1.4"
23-
structopt = "0.3.7"
24-
toml = "0.5.5"
23+
structopt = "0.3.8"
24+
toml = "0.5.6"
2525
ureq = "0.11.3"
2626
url = { version = "2.1.1", features = ["serde"] }
2727
which = { version = "3.1.0", default-features = false }

tools/test-with-generated-opts/src/main.rs renamed to tools/test-examples/src/main.rs

Lines changed: 18 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::ffi::{OsStr, OsString};
2020
use std::io::{self, Read as _, Write as _};
2121
use std::ops::Deref;
2222
use std::path::{Path, PathBuf};
23-
use std::process::{Command, Output, Stdio};
23+
use std::process::{Command, Stdio};
2424
use std::str::FromStr;
2525
use std::time::Instant;
2626
use std::{env, f64, fs};
@@ -30,7 +30,7 @@ struct Opt {
3030
#[structopt(
3131
long,
3232
value_name("PATH"),
33-
default_value("./test-with-generated-opts.toml"),
33+
default_value("./test-examples.toml"),
3434
help("Path to the config")
3535
)]
3636
config: PathBuf,
@@ -60,20 +60,23 @@ fn main() -> anyhow::Result<()> {
6060
write_with_style(Color::Black, false, true, "]")?;
6161
writeln!(buf, " {}", record.args())
6262
})
63-
.filter_module("test_with_generated_opts", LevelFilter::Info)
63+
.filter_module("test_examples", LevelFilter::Info)
6464
.init();
6565

6666
let config = read_toml::<_, Config>(config)?;
6767

6868
scrape_sample_cases(&config)?;
69+
cargo_build_examples_release()?;
6970

7071
let tests = config
7172
.examples
7273
.iter()
7374
.map(|(slug, example)| {
74-
let src = Path::new("./examples").join(slug).with_extension("rs");
75-
let bin = config.bin.expand_path(slug)?;
76-
compile(&src, &bin)?;
75+
let bin = Path::new(".")
76+
.join("target")
77+
.join("release")
78+
.join("examples")
79+
.join(slug);
7780

7881
match example {
7982
Example::Normal(Normal {
@@ -131,8 +134,7 @@ fn scrape_sample_cases(config: &Config) -> anyhow::Result<()> {
131134
}
132135

133136
fn get_html(url: &Url) -> anyhow::Result<Html> {
134-
static USER_AGENT: &str =
135-
"test-with-generated-opts <https://github.com/rust-lang-ja/atcoder-rust-base>";
137+
static USER_AGENT: &str = "test-examples <https://github.com/rust-lang-ja/atcoder-rust-base>";
136138

137139
info!("GET: {}", url);
138140

@@ -387,11 +389,11 @@ fn load_testcases(dir: &Path) -> anyhow::Result<BTreeMap<OsString, (String, Stri
387389
.collect()
388390
}
389391

390-
fn compile(src: &Path, bin: &Path) -> anyhow::Result<()> {
392+
fn cargo_build_examples_release() -> anyhow::Result<()> {
391393
fn run_command<S1: AsRef<OsStr>, S2: AsRef<OsStr>, I: IntoIterator<Item = S2>>(
392394
program: S1,
393395
args: I,
394-
) -> anyhow::Result<Vec<u8>> {
396+
) -> anyhow::Result<()> {
395397
let program = program.as_ref();
396398
let args = args.into_iter().collect::<Vec<_>>();
397399

@@ -405,58 +407,17 @@ fn compile(src: &Path, bin: &Path) -> anyhow::Result<()> {
405407
.format_with("", |s, f| f(&format_args!(" {}", s))),
406408
);
407409

408-
let Output { status, stdout, .. } = Command::new(program)
409-
.args(&args)
410-
.stdin(Stdio::null())
411-
.stderr(Stdio::inherit())
412-
.output()?;
413-
410+
let status = Command::new(program).args(&args).status()?;
414411
if !status.success() {
415412
return Err(anyhow!("{}: {}", program.to_string_lossy(), status));
416413
}
417-
Ok(stdout)
418-
}
419-
420-
if let (Ok(src_metadata), Ok(bin_metadata)) = (src.metadata(), bin.metadata()) {
421-
if src_metadata.modified()? < bin_metadata.modified()? {
422-
info!("{} is up to date.", bin.display());
423-
return Ok(());
424-
}
425-
}
426-
427-
if let Some(parent) = bin.parent() {
428-
if !parent.exists() {
429-
create_dir_all(parent)?;
430-
}
414+
Ok(())
431415
}
432416

433-
let generated_opts = {
434-
let program = which::which("rustc-dep-option-generator")?;
435-
let stdout = run_command(&program, &["--format", "json"])?;
436-
serde_json::from_slice::<Vec<String>>(&stdout)
437-
.with_context(|| format!("{}: invalid output", program.to_string_lossy()))?
438-
};
439-
440-
let program = env::var_os("RUSTC")
441-
.map(Ok)
442-
.unwrap_or_else(|| which::which("rustc").map(Into::into))?;
443-
444-
let args = {
445-
let mut args = vec![
446-
OsString::from("--edition"),
447-
OsString::from("2018"),
448-
OsString::from("-C"),
449-
OsString::from("opt-level=3"),
450-
OsString::from("-o"),
451-
OsString::from(bin),
452-
];
453-
for opt in generated_opts {
454-
args.push(opt.into());
455-
}
456-
args.push(src.to_owned().into());
457-
args
458-
};
459-
run_command(program, args).map(drop)
417+
run_command(
418+
env::var_os("CARGO").unwrap_or_else(|| "cargo".into()),
419+
&["build", "--examples", "--release"],
420+
)
460421
}
461422

462423
fn normal_test(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy