Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

Commit b93852d

Browse files
WIP: Automation for adding tests
1 parent 08dfe89 commit b93852d

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed

Cargo.lock

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ tempfile = "3.1.0"
1515
[workspace]
1616
members = [
1717
"autofix",
18+
"grabber",
1819
"labeler"
1920
]
2021

grabber/Cargo.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "glacier-grabber"
3+
version = "0.1.0"
4+
authors = ["Langston Barrett <[email protected]>"]
5+
edition = "2021"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
glacier = "0.1.0"
11+
once_cell = { workspace = true }
12+
regex = "1"
13+
reqwest = { workspace = true }
14+
serde = { workspace = true }

grabber/src/github.rs

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use once_cell::sync::Lazy;
2+
use reqwest::blocking::Client;
3+
use serde::{Deserialize, Serialize};
4+
use std::env::{var, VarError};
5+
6+
static CLIENT: Lazy<Client> = Lazy::new(|| {
7+
Client::builder()
8+
.user_agent("rust-lang/glacier")
9+
.build()
10+
.unwrap()
11+
});
12+
13+
pub(crate) struct Config {
14+
token: String,
15+
}
16+
17+
impl Config {
18+
pub(crate) fn from_env(on_glacier: bool) -> Result<Self, VarError> {
19+
Ok(Self {
20+
token: if on_glacier {
21+
var("GITHUB_TOKEN")?
22+
} else {
23+
var("GRAB_TOKEN")?
24+
},
25+
})
26+
}
27+
}
28+
29+
pub(crate) fn get_labeled_issues(
30+
config: &Config,
31+
repo: &str,
32+
label_name: String,
33+
) -> Result<Vec<Issue>, reqwest::Error> {
34+
let url = format!("https://api.github.com/repos/{repo}/issues?labels={label_name}&state=open");
35+
36+
let issues: Vec<Issue> = CLIENT
37+
.get(url)
38+
.bearer_auth(&config.token)
39+
.send()?
40+
.error_for_status()?
41+
.json()?;
42+
43+
// TODO: Pagination, see labeler
44+
45+
Ok(issues)
46+
}
47+
48+
#[derive(Serialize, Debug)]
49+
pub(crate) struct Labels {
50+
pub(crate) labels: Vec<String>,
51+
}
52+
53+
#[derive(Deserialize, Debug)]
54+
pub(crate) struct Issue {
55+
pub(crate) number: usize,
56+
pub(crate) body: String,
57+
}
58+
59+
#[derive(Deserialize, Debug, PartialEq, Eq)]
60+
#[serde(rename_all = "lowercase")]
61+
pub(crate) enum IssueState {
62+
Open,
63+
Closed,
64+
}

grabber/src/main.rs

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use glacier::rayon::iter::ParallelIterator;
2+
3+
mod github;
4+
5+
fn main() {
6+
let config = github::Config::from_env(false).unwrap();
7+
8+
let mut tested_issue_list = glacier::discover("./ices")
9+
.unwrap()
10+
.into_iter()
11+
.map(|ice| ice.id())
12+
.collect::<Vec<_>>();
13+
tested_issue_list.sort_unstable();
14+
tested_issue_list.dedup();
15+
16+
let mut untesteds =
17+
crate::github::get_labeled_issues(&config, "rust-lang/rust", "I-ICE".to_string()).unwrap();
18+
untesteds.retain(|i| !tested_issue_list.contains(&i.number));
19+
for untested in untesteds {
20+
let mut reproduction = Vec::new();
21+
let mut in_code_section = false;
22+
let mut in_code = false;
23+
let mut has_main = false;
24+
for line in untested.body.lines() {
25+
if in_code {
26+
if line.starts_with("```") {
27+
in_code = false;
28+
continue;
29+
}
30+
if line.starts_with("fn main") {
31+
has_main = true;
32+
}
33+
reproduction.push(line);
34+
}
35+
if line.starts_with("### Code") {
36+
in_code_section = true;
37+
} else if line.starts_with('#') && in_code_section {
38+
in_code_section = false;
39+
}
40+
if line.starts_with("```") && in_code_section {
41+
in_code = true;
42+
}
43+
}
44+
if reproduction.is_empty() {
45+
continue;
46+
}
47+
if !has_main {
48+
reproduction.push("");
49+
reproduction.push("fn main() {}");
50+
}
51+
std::fs::write(
52+
format!("./ices/{}.rs", untested.number),
53+
reproduction.join("\n"),
54+
)
55+
.unwrap();
56+
}
57+
58+
let failed = glacier::test_all()
59+
.unwrap()
60+
.filter(|res| {
61+
if let Ok(test) = res {
62+
test.outcome() != glacier::Outcome::ICEd
63+
} else {
64+
true
65+
}
66+
})
67+
.collect::<Result<Vec<glacier::TestResult>, _>>()
68+
.unwrap();
69+
70+
for result in &failed {
71+
std::fs::remove_file(result.path()).unwrap();
72+
}
73+
}

0 commit comments

Comments
 (0)