Skip to content

Commit 8320bbe

Browse files
dwijnandEh2406
authored andcommitted
add failing test
1 parent 9bfaf2e commit 8320bbe

File tree

1 file changed

+114
-1
lines changed

1 file changed

+114
-1
lines changed

tests/testsuite/build.rs

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::env;
2-
use std::fs::{self, File};
2+
use std::fs::{self, File, OpenOptions};
33
use std::io::prelude::*;
4+
use std::net::TcpListener;
5+
use std::thread;
46

57
use crate::support::paths::{root, CargoPathExt};
68
use crate::support::registry::Package;
@@ -2394,6 +2396,117 @@ fn rebuild_preserves_out_dir() {
23942396
.run();
23952397
}
23962398

2399+
#[test]
2400+
fn rebuild_on_mid_build_file_modification() {
2401+
let server = TcpListener::bind("127.0.0.1:0").unwrap();
2402+
let addr = server.local_addr().unwrap();
2403+
2404+
let p = project("p")
2405+
.file(
2406+
"Cargo.toml",
2407+
r#"
2408+
[workspace]
2409+
members = ["root", "proc_macro_dep"]
2410+
"#,
2411+
)
2412+
.file(
2413+
"root/Cargo.toml",
2414+
r#"
2415+
[project]
2416+
name = "root"
2417+
version = "0.1.0"
2418+
authors = []
2419+
2420+
[dependencies]
2421+
proc_macro_dep = { path = "../proc_macro_dep" }
2422+
"#,
2423+
)
2424+
.file(
2425+
"root/src/lib.rs",
2426+
r#"
2427+
#[macro_use]
2428+
extern crate proc_macro_dep;
2429+
2430+
#[derive(Noop)]
2431+
pub struct X;
2432+
"#,
2433+
)
2434+
.file(
2435+
"proc_macro_dep/Cargo.toml",
2436+
r#"
2437+
[project]
2438+
name = "proc_macro_dep"
2439+
version = "0.1.0"
2440+
authors = []
2441+
2442+
[lib]
2443+
proc-macro = true
2444+
"#,
2445+
)
2446+
.file(
2447+
"proc_macro_dep/src/lib.rs",
2448+
&format!(
2449+
r#"
2450+
extern crate proc_macro;
2451+
2452+
use std::io::Read;
2453+
use std::net::TcpStream;
2454+
use proc_macro::TokenStream;
2455+
2456+
#[proc_macro_derive(Noop)]
2457+
pub fn noop(_input: TokenStream) -> TokenStream {{
2458+
let mut stream = TcpStream::connect("{}").unwrap();
2459+
let mut v = Vec::new();
2460+
stream.read_to_end(&mut v).unwrap();
2461+
"".parse().unwrap()
2462+
}}
2463+
"#,
2464+
addr
2465+
),
2466+
)
2467+
.build();
2468+
let root = p.root();
2469+
2470+
let t = thread::spawn(move || {
2471+
let socket = server.accept().unwrap().0;
2472+
let mut file = OpenOptions::new()
2473+
.write(true)
2474+
.append(true)
2475+
.open(root.join("root/src/lib.rs"))
2476+
.unwrap();
2477+
writeln!(file, "// modified").expect("Failed to append to root sources");
2478+
drop(file);
2479+
drop(socket);
2480+
drop(server.accept().unwrap());
2481+
});
2482+
2483+
assert_that(
2484+
p.cargo("build"),
2485+
execs().stream().with_status(0)
2486+
// .with_stderr(&format!(
2487+
// "\
2488+
//[COMPILING] proc_macro_dep v0.1.0 ({url}/proc_macro_dep)
2489+
//[COMPILING] root v0.1.0 ({url}/root)
2490+
//[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2491+
//",
2492+
// url = p.url()
2493+
// )),
2494+
);
2495+
2496+
assert_that(
2497+
p.cargo("build"),
2498+
execs().stream().with_status(0).with_stderr(&format!(
2499+
"\
2500+
[COMPILING] root v0.1.0 ({url}/root)
2501+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2502+
",
2503+
url = p.url()
2504+
)),
2505+
);
2506+
2507+
t.join().ok().unwrap();
2508+
}
2509+
23972510
#[test]
23982511
fn dep_no_libs() {
23992512
let foo = project()

0 commit comments

Comments
 (0)