]> git.proxmox.com Git - cargo.git/commitdiff
add failing test
authorDale Wijnand <dale.wijnand@gmail.com>
Mon, 30 Apr 2018 17:29:16 +0000 (13:29 -0400)
committerEh2406 <YeomanYaacov@gmail.com>
Wed, 2 Jan 2019 19:09:50 +0000 (14:09 -0500)
tests/testsuite/build.rs

index 4d9cc80e04dd524933517bf3e971bbcc76ff685b..2f6d5debec783ce7a1094f8729a10d94467df68b 100644 (file)
@@ -1,6 +1,8 @@
 use std::env;
-use std::fs::{self, File};
+use std::fs::{self, File, OpenOptions};
 use std::io::prelude::*;
+use std::net::TcpListener;
+use std::thread;
 
 use crate::support::paths::{root, CargoPathExt};
 use crate::support::registry::Package;
@@ -2394,6 +2396,117 @@ fn rebuild_preserves_out_dir() {
         .run();
 }
 
+#[test]
+fn rebuild_on_mid_build_file_modification() {
+    let server = TcpListener::bind("127.0.0.1:0").unwrap();
+    let addr = server.local_addr().unwrap();
+
+    let p = project("p")
+        .file(
+            "Cargo.toml",
+            r#"
+            [workspace]
+            members = ["root", "proc_macro_dep"]
+        "#,
+        )
+        .file(
+            "root/Cargo.toml",
+            r#"
+            [project]
+            name = "root"
+            version = "0.1.0"
+            authors = []
+
+            [dependencies]
+            proc_macro_dep = { path = "../proc_macro_dep" }
+        "#,
+        )
+        .file(
+            "root/src/lib.rs",
+            r#"
+            #[macro_use]
+            extern crate proc_macro_dep;
+
+            #[derive(Noop)]
+            pub struct X;
+        "#,
+        )
+        .file(
+            "proc_macro_dep/Cargo.toml",
+            r#"
+            [project]
+            name = "proc_macro_dep"
+            version = "0.1.0"
+            authors = []
+
+            [lib]
+            proc-macro = true
+        "#,
+        )
+        .file(
+            "proc_macro_dep/src/lib.rs",
+            &format!(
+                r#"
+                extern crate proc_macro;
+
+                use std::io::Read;
+                use std::net::TcpStream;
+                use proc_macro::TokenStream;
+
+                #[proc_macro_derive(Noop)]
+                pub fn noop(_input: TokenStream) -> TokenStream {{
+                    let mut stream = TcpStream::connect("{}").unwrap();
+                    let mut v = Vec::new();
+                    stream.read_to_end(&mut v).unwrap();
+                    "".parse().unwrap()
+                }}
+            "#,
+                addr
+            ),
+        )
+        .build();
+    let root = p.root();
+
+    let t = thread::spawn(move || {
+        let socket = server.accept().unwrap().0;
+        let mut file = OpenOptions::new()
+            .write(true)
+            .append(true)
+            .open(root.join("root/src/lib.rs"))
+            .unwrap();
+        writeln!(file, "// modified").expect("Failed to append to root sources");
+        drop(file);
+        drop(socket);
+        drop(server.accept().unwrap());
+    });
+
+    assert_that(
+        p.cargo("build"),
+        execs().stream().with_status(0)
+//            .with_stderr(&format!(
+//            "\
+//[COMPILING] proc_macro_dep v0.1.0 ({url}/proc_macro_dep)
+//[COMPILING] root v0.1.0 ({url}/root)
+//[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
+//",
+//            url = p.url()
+//        )),
+    );
+
+    assert_that(
+        p.cargo("build"),
+        execs().stream().with_status(0).with_stderr(&format!(
+            "\
+[COMPILING] root v0.1.0 ({url}/root)
+[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
+",
+            url = p.url()
+        )),
+    );
+
+    t.join().ok().unwrap();
+}
+
 #[test]
 fn dep_no_libs() {
     let foo = project()