aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-21 12:23:09 +0100
committerMartin Fischer <martin@push-f.com>2021-11-21 19:52:57 +0100
commit23fcd4ef079ad2b4aed69b4f363cbb9e7102c4ed (patch)
tree2fbf27f77274df35b31504e9b6cde5ed0a53455c
parent57641e00d6ed1fd7689c3079abb10f67d5387143 (diff)
add ui tests (inspired by trybuild)
-rw-r--r--src/lib.rs35
-rw-r--r--ui-tests/.cargo/config.toml2
-rw-r--r--ui-tests/Cargo.toml11
-rw-r--r--ui-tests/src/bin/assoc_type_no_bound.rs8
-rw-r--r--ui-tests/src/bin/assoc_type_no_bound.stderr5
-rw-r--r--ui-tests/src/bin/assoc_type_undefined.rs6
-rw-r--r--ui-tests/src/bin/assoc_type_undefined.stderr5
-rw-r--r--ui-tests/src/bin/gats.rs8
-rw-r--r--ui-tests/src/bin/gats.stderr5
-rw-r--r--ui-tests/src/bin/method_generics_conflict.rs7
-rw-r--r--ui-tests/src/bin/method_generics_conflict.stderr5
11 files changed, 97 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c0286f8..fc81e42 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -448,3 +448,38 @@ fn path_segment_for_trait(sometrait: &ItemTrait) -> PathSegment {
#[doc = include_str!("../tests/doctests.md")]
#[cfg(doctest)]
struct Doctests;
+
+#[test]
+fn ui() {
+ use std::process::Command;
+
+ for entry in std::fs::read_dir("ui-tests/src/bin").unwrap().flatten() {
+ if entry.path().extension().unwrap() == "rs" {
+ let output = Command::new("cargo")
+ .arg("check")
+ .arg("--quiet")
+ .arg("--bin")
+ .arg(entry.path().file_stem().unwrap())
+ .current_dir("ui-tests")
+ .output()
+ .unwrap();
+ let received_stderr = std::str::from_utf8(&output.stderr)
+ .unwrap()
+ .lines()
+ .filter(|l| !l.starts_with("error: could not compile"))
+ .collect::<Vec<_>>()
+ .join("\n");
+ let expected_stderr =
+ std::fs::read_to_string(entry.path().with_extension("stderr")).unwrap_or_default();
+ if received_stderr != expected_stderr {
+ println!(
+ "EXPECTED:\n{banner}\n{expected}{banner}\n\nACTUAL OUTPUT:\n{banner}\n{actual}{banner}",
+ banner = "-".repeat(30),
+ expected = expected_stderr,
+ actual = received_stderr
+ );
+ panic!("failed");
+ }
+ }
+ }
+}
diff --git a/ui-tests/.cargo/config.toml b/ui-tests/.cargo/config.toml
new file mode 100644
index 0000000..ec6a5d0
--- /dev/null
+++ b/ui-tests/.cargo/config.toml
@@ -0,0 +1,2 @@
+[build]
+target-dir = "../target"
diff --git a/ui-tests/Cargo.toml b/ui-tests/Cargo.toml
new file mode 100644
index 0000000..5b30a66
--- /dev/null
+++ b/ui-tests/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "dynamize-tests"
+version = "0.0.0"
+edition = "2021"
+publish = false
+
+[patch.crates-io]
+dynamize = { path = ".." }
+
+[dependencies]
+dynamize = "0.2.0"
diff --git a/ui-tests/src/bin/assoc_type_no_bound.rs b/ui-tests/src/bin/assoc_type_no_bound.rs
new file mode 100644
index 0000000..79c91a2
--- /dev/null
+++ b/ui-tests/src/bin/assoc_type_no_bound.rs
@@ -0,0 +1,8 @@
+#[dynamize::dynamize]
+trait Trait {
+ type A;
+
+ fn f(&self) -> Self::A;
+}
+
+fn main() {}
diff --git a/ui-tests/src/bin/assoc_type_no_bound.stderr b/ui-tests/src/bin/assoc_type_no_bound.stderr
new file mode 100644
index 0000000..c6a118b
--- /dev/null
+++ b/ui-tests/src/bin/assoc_type_no_bound.stderr
@@ -0,0 +1,5 @@
+error: associated type is either undefined or doesn't have a trait bound
+ --> src/bin/assoc_type_no_bound.rs:5:26
+ |
+5 | fn f(&self) -> Self::A;
+ | ^
diff --git a/ui-tests/src/bin/assoc_type_undefined.rs b/ui-tests/src/bin/assoc_type_undefined.rs
new file mode 100644
index 0000000..8faa0f3
--- /dev/null
+++ b/ui-tests/src/bin/assoc_type_undefined.rs
@@ -0,0 +1,6 @@
+#[dynamize::dynamize]
+trait Trait {
+ fn f(&self) -> Self::A;
+}
+
+fn main() {}
diff --git a/ui-tests/src/bin/assoc_type_undefined.stderr b/ui-tests/src/bin/assoc_type_undefined.stderr
new file mode 100644
index 0000000..5fb8bf3
--- /dev/null
+++ b/ui-tests/src/bin/assoc_type_undefined.stderr
@@ -0,0 +1,5 @@
+error: associated type is either undefined or doesn't have a trait bound
+ --> src/bin/assoc_type_undefined.rs:3:26
+ |
+3 | fn f(&self) -> Self::A;
+ | ^
diff --git a/ui-tests/src/bin/gats.rs b/ui-tests/src/bin/gats.rs
new file mode 100644
index 0000000..ca75563
--- /dev/null
+++ b/ui-tests/src/bin/gats.rs
@@ -0,0 +1,8 @@
+#[dynamize::dynamize]
+pub trait MyTrait {
+ type A<'a>: Into<&'a str>;
+
+ fn test1<'b>(&self) -> Self::A<'b>;
+}
+
+fn main() {}
diff --git a/ui-tests/src/bin/gats.stderr b/ui-tests/src/bin/gats.stderr
new file mode 100644
index 0000000..e8c73c4
--- /dev/null
+++ b/ui-tests/src/bin/gats.stderr
@@ -0,0 +1,5 @@
+error: dynamize does not (yet?) support generic associated types
+ --> src/bin/gats.rs:3:12
+ |
+3 | type A<'a>: Into<&'a str>;
+ | ^^
diff --git a/ui-tests/src/bin/method_generics_conflict.rs b/ui-tests/src/bin/method_generics_conflict.rs
new file mode 100644
index 0000000..e76e05f
--- /dev/null
+++ b/ui-tests/src/bin/method_generics_conflict.rs
@@ -0,0 +1,7 @@
+#[dynamize::dynamize]
+trait Trait {
+ fn a<A>(&self, a: A);
+ fn b<A: std::fmt::Display>(&self, a: A);
+}
+
+fn main() {}
diff --git a/ui-tests/src/bin/method_generics_conflict.stderr b/ui-tests/src/bin/method_generics_conflict.stderr
new file mode 100644
index 0000000..71a7356
--- /dev/null
+++ b/ui-tests/src/bin/method_generics_conflict.stderr
@@ -0,0 +1,5 @@
+error: dynamize failure: there exists a same-named method generic with different bounds
+ --> src/bin/method_generics_conflict.rs:4:10
+ |
+4 | fn b<A: std::fmt::Display>(&self, a: A);
+ | ^