From 018853ab04360596fb3deb161c6c3b3b040817fa Mon Sep 17 00:00:00 2001 From: Samuel Guerra Date: Thu, 16 Dec 2021 00:50:15 -0300 Subject: [PATCH] Fixed all do commands. --- TODO/_r.md | 2 -- tests/build/Cargo.toml | 4 ++++ tests/build/main.rs | 16 +++------------- tests/build/run.rs | 15 +++++++++++++++ tools/do-tasks/src/main.rs | 17 ++++++++++------- tools/do-tasks/src/util.rs | 2 +- zero-ui/src/widgets/layouts/grid_.rs | 4 ++-- zero-ui/src/widgets/scrollable_.rs | 2 +- 8 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 tests/build/run.rs diff --git a/TODO/_r.md b/TODO/_r.md index 1851d637f..25d81693a 100644 --- a/TODO/_r.md +++ b/TODO/_r.md @@ -1,6 +1,4 @@ * Test animations in two windows, it is causing some panics. thread 'main' panicked at 'assertion failed: !self.view_is_rendering()' * Adjust when respawn stops happening, it can enter an infinite loop in panics like the large image. -* Build tests harness does not build. (error is this: https://github.com/rust-lang/cargo/issues/6915) - restructure project using crates for tests and examples * When reopening an image (like the panorama one in the image example) it doesn't load. diff --git a/tests/build/Cargo.toml b/tests/build/Cargo.toml index 5dea72174..91e55dea5 100644 --- a/tests/build/Cargo.toml +++ b/tests/build/Cargo.toml @@ -8,6 +8,10 @@ edition = "2021" trybuild = "1" zero-ui = { path = "../../zero-ui" } +[lib] +name = "lib" +path = "run.rs" + [[bin]] name = "main" path = "main.rs" \ No newline at end of file diff --git a/tests/build/main.rs b/tests/build/main.rs index 4c8df3755..efdb71b50 100644 --- a/tests/build/main.rs +++ b/tests/build/main.rs @@ -2,18 +2,8 @@ //! //! Use `cargo do test -b property/*` to run all paths that match in the `./cases` folder. +mod run; + fn main() { - if let Some(test) = std::env::var_os("DO_TASKS_TEST_BUILD") { - let mut test = test.to_string_lossy(); - - if ["*", "**"].contains(&test.as_ref()) { - test = "*/*".into(); - } - - std::env::set_current_dir(format!("{}/cases", env!("CARGO_MANIFEST_DIR"))).unwrap(); - - trybuild::TestCases::new().compile_fail(format!("{}.rs", test)); - } else { - eprintln!("run with `cargo do test --build *`"); - } + run::do_request(); } diff --git a/tests/build/run.rs b/tests/build/run.rs new file mode 100644 index 000000000..260e522cb --- /dev/null +++ b/tests/build/run.rs @@ -0,0 +1,15 @@ +pub fn do_request() { + if let Some(test) = std::env::var_os("DO_TASKS_TEST_BUILD") { + let mut test = test.to_string_lossy(); + + if ["*", "**"].contains(&test.as_ref()) { + test = "*/*".into(); + } + + std::env::set_current_dir(env!("CARGO_MANIFEST_DIR")).unwrap(); + + trybuild::TestCases::new().compile_fail(format!("cases/{}.rs", test)); + } else { + eprintln!("run with `cargo do test --build *`"); + } +} \ No newline at end of file diff --git a/tools/do-tasks/src/main.rs b/tools/do-tasks/src/main.rs index a353508be..86032ddc3 100644 --- a/tools/do-tasks/src/main.rs +++ b/tools/do-tasks/src/main.rs @@ -241,10 +241,8 @@ fn run(mut args: Vec<&str>) { // FLAGS: // --dump Write the expanded Rust code to "dump.rs". // USAGE: -// expand some::item -// Prints only the specified item in the main crate. -// expand -p "other-crate" some::item -// Prints only the specified item in the other-crate from workspace. +// expand -p crate-name item::path +// Prints only the specified item in the crate from workspace. // expand -e "example" // Prints the example. // expand --raw @@ -261,6 +259,7 @@ fn expand(mut args: Vec<&str>) { test_args.insert(0, "+nightly"); test(test_args); + TaskInfo::get().stdout_dump = "dump.rs"; for (bin_name, path) in build_test_cases() { let i = path.find("tests").unwrap_or_default(); @@ -270,7 +269,7 @@ fn expand(mut args: Vec<&str>) { &[ "expand", "--manifest-path", - "target/tests/zero-ui/Cargo.toml", + "target/tests/build-tests/Cargo.toml", "--bin", &bin_name, "--all-features", @@ -283,10 +282,14 @@ fn expand(mut args: Vec<&str>) { cmd("cargo", &["expand", "--package", "examples", "--example"], &args); } else { TaskInfo::get().stdout_dump = "dump.rs"; - if take_flag(&mut args, &["-r", "--raw"]) { + if !args.contains(&"-p") && !args.contains(&"--package") { + error("expected crate name"); + } else if take_flag(&mut args, &["-r", "--raw"]) { + let p = take_option(&mut args, &["-p", "--package"], "").unwrap(); + cmd( "cargo", - &["+nightly", "rustc", "--profile=check", "--", "-Zunpretty=expanded"], + &["+nightly", "rustc", "--profile=check", "--package", p[0], "--", "-Zunpretty=expanded"], &args, ); } else { diff --git a/tools/do-tasks/src/util.rs b/tools/do-tasks/src/util.rs index 345089740..c45fd5728 100644 --- a/tools/do-tasks/src/util.rs +++ b/tools/do-tasks/src/util.rs @@ -239,7 +239,7 @@ pub fn examples() -> Vec { // [[bin]] names for build tests last run ("bin-name", "test_file_path"). pub fn build_test_cases() -> Vec<(String, String)> { - match std::fs::read_to_string("target/tests/zero-ui/Cargo.toml") { + match std::fs::read_to_string("target/tests/build-tests/Cargo.toml") { Ok(file) => { let mut bin_names = vec![]; diff --git a/zero-ui/src/widgets/layouts/grid_.rs b/zero-ui/src/widgets/layouts/grid_.rs index 4cfd1e87a..5f2fe5579 100644 --- a/zero-ui/src/widgets/layouts/grid_.rs +++ b/zero-ui/src/widgets/layouts/grid_.rs @@ -181,7 +181,7 @@ pub mod grid { let column_widths: Vec<_> = self.columns.iter_mut().map(|c| c.measure(ctx, c_available_size)).collect(); let row_heights: Vec<_> = self.rows.iter_mut().map(|r| r.measure(ctx, r_available_size)).collect(); - let mut desired_size = PxSize::zero(); + let desired_size = PxSize::zero(); let mut c_desired_widths = vec![Px(0); column_widths.len()]; let mut r_desired_heights = vec![Px(0); row_heights.len()]; @@ -275,7 +275,7 @@ pub mod grid { } fn arrange(&mut self, ctx: &mut LayoutContext, widget_offset: &mut WidgetOffset, final_size: PxSize) { - let _ = (ctx, final_size); + let _ = (ctx, widget_offset, final_size); todo!() } diff --git a/zero-ui/src/widgets/scrollable_.rs b/zero-ui/src/widgets/scrollable_.rs index f99f024f0..57cdd6bf6 100644 --- a/zero-ui/src/widgets/scrollable_.rs +++ b/zero-ui/src/widgets/scrollable_.rs @@ -366,7 +366,7 @@ pub mod scrollable { fn scrollbar_presenter(var: impl IntoVar>, orientation: scrollbar::Orientation) -> impl UiNode { ViewGenerator::presenter( var, - |vars, widget| { + |_vars, _widget| { // TODO }, move |ctx, is_new| {