Skip to content

Commit

Permalink
Add ui tests for Panoramix derive
Browse files Browse the repository at this point in the history
  • Loading branch information
PoignardAzur committed Aug 25, 2021
1 parent fe189cd commit 3e7b5dc
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions druid-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ proc-macro2 = "1.0.19"

[dev-dependencies]
druid = { version = "0.7.0", path = "../druid" }
trybuild = "1.0"

float-cmp = { version = "0.8.0", features = ["std"], default-features = false }
21 changes: 21 additions & 0 deletions druid-derive/tests/ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// https://github.com/dtolnay/trybuild
// trybuild is a crate that essentially runs cargo on the provided files, and checks the output.
// Tests may suddenly fail after a new compiler release, and there's not much we can do about that.
// If the test suite fails because of trybuild:
// - Update your compiler to the latest stable version.
// - If it still fails, update the stderr snapshots. To do so, run the test suite with
// env variable TRYBUILD=overwrite, and submit the file changes in a PR.
use trybuild::TestCases;

#[test]
fn ui() {
let t = TestCases::new();
t.pass("tests/ui/simple-lens.rs");
t.pass("tests/ui/lens-attributes.rs");
t.compile_fail("tests/ui/with-empty-struct.rs");
t.compile_fail("tests/ui/with-tuple-struct.rs");
t.compile_fail("tests/ui/with-enum.rs");
t.compile_fail("tests/ui/with-union.rs");

t.compile_fail("tests/ui/with-snake_case.rs");
}
20 changes: 20 additions & 0 deletions druid-derive/tests/ui/lens-attributes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use druid::*;

#[derive(Lens)]
struct Item {
#[lens(name = "count_lens")]
count: usize,
#[lens(ignore)]
complete: bool,
}

impl Item {
fn count(&self) -> usize {
self.count
}
fn complete(&mut self) {
self.complete = true;
}
}

fn main() {}
12 changes: 12 additions & 0 deletions druid-derive/tests/ui/simple-lens.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use druid::*;

#[derive(Lens)]
struct MyThing {
field_1: i32,
field_2: String,
}

fn main() {
let _ = MyThing::field_1;
let _ = MyThing::field_2;
}
6 changes: 6 additions & 0 deletions druid-derive/tests/ui/with-empty-struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use druid::*;

#[derive(Lens)]
struct Foobar;

fn main() {}
5 changes: 5 additions & 0 deletions druid-derive/tests/ui/with-empty-struct.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Lens implementations can only be derived from structs with named fields
--> $DIR/with-empty-struct.rs:4:1
|
4 | struct Foobar;
| ^^^^^^
9 changes: 9 additions & 0 deletions druid-derive/tests/ui/with-enum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use druid::*;

#[derive(Lens)]
enum Foobar {
Foo(i32),
Bar,
}

fn main() {}
5 changes: 5 additions & 0 deletions druid-derive/tests/ui/with-enum.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Lens implementations cannot be derived from enums
--> $DIR/with-enum.rs:4:1
|
4 | enum Foobar {
| ^^^^
10 changes: 10 additions & 0 deletions druid-derive/tests/ui/with-snake_case.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![allow(non_camel_case_types)]

use druid::*;

#[derive(Lens)]
struct my_thing {
field: i32
}

fn main() {}
5 changes: 5 additions & 0 deletions druid-derive/tests/ui/with-snake_case.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Lens implementations can only be derived from CamelCase types
--> $DIR/with-snake_case.rs:6:8
|
6 | struct my_thing {
| ^^^^^^^^
6 changes: 6 additions & 0 deletions druid-derive/tests/ui/with-tuple-struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use druid::*;

#[derive(Lens)]
struct Foobar(i32, i64);

fn main() {}
5 changes: 5 additions & 0 deletions druid-derive/tests/ui/with-tuple-struct.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Lens implementations can only be derived from structs with named fields
--> $DIR/with-tuple-struct.rs:4:1
|
4 | struct Foobar(i32, i64);
| ^^^^^^
9 changes: 9 additions & 0 deletions druid-derive/tests/ui/with-union.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use druid::*;

#[derive(Lens)]
union Foobar {
foo: i32,
bar: f64,
}

fn main() {}
5 changes: 5 additions & 0 deletions druid-derive/tests/ui/with-union.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Lens implementations cannot be derived from unions
--> $DIR/with-union.rs:4:1
|
4 | union Foobar {
| ^^^^^

0 comments on commit 3e7b5dc

Please sign in to comment.