mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 14:44:12 +00:00
chore: use miri on native-core too
This commit is contained in:
parent
0d95568972
commit
b351345db9
3 changed files with 167 additions and 4 deletions
21
.github/workflows/miri.yml
vendored
21
.github/workflows/miri.yml
vendored
|
@ -1,4 +1,4 @@
|
|||
name: CI
|
||||
name: Miri Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
|
@ -25,11 +25,25 @@ jobs:
|
|||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-latest
|
||||
host_target: i686-pc-windows-msvc
|
||||
- os: ubuntu-latest
|
||||
host_target: x86_64-unknown-linux-gnu
|
||||
# - os: macos-latest
|
||||
# host_target: x86_64-apple-darwin
|
||||
# - os: windows-latest
|
||||
# host_target: i686-pc-windows-msvc
|
||||
# - os: windows-latest
|
||||
# host_target: i686-pc-windows-msvc
|
||||
# - os: windows-latest
|
||||
# host_target: i686-pc-windows-msvc
|
||||
# - os: windows-latest
|
||||
# host_target: i686-pc-windows-msvc
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set the tag GC interval to 1 on linux
|
||||
if: runner.os == 'Linux'
|
||||
run: echo "MIRIFLAGS=-Zmiri-tag-gc=1" >> $GITHUB_ENV
|
||||
|
||||
# Cache the global cargo directory, but NOT the local `target` directory which
|
||||
# we cannot reuse anyway when the nightly changes (and it grows quite large
|
||||
# over time).
|
||||
|
@ -70,3 +84,4 @@ jobs:
|
|||
- name: Test
|
||||
run: |
|
||||
MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo +nightly miri test --package dioxus-core --test miri_stress -- --exact --nocapture
|
||||
MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo +nightly miri test --package dioxus-native-core --test miri_native -- --exact --nocapture
|
||||
|
|
|
@ -27,3 +27,5 @@ dashmap = "5.4.0"
|
|||
[dev-dependencies]
|
||||
rand = "0.8.5"
|
||||
dioxus = { path = "../dioxus", version = "^0.2.1" }
|
||||
dioxus-native-core-macro = { path = "../native-core-macro" }
|
||||
tokio = { version = "*", features = ["full"] }
|
||||
|
|
146
packages/native-core/tests/miri_native.rs
Normal file
146
packages/native-core/tests/miri_native.rs
Normal file
|
@ -0,0 +1,146 @@
|
|||
use dioxus::prelude::*;
|
||||
use dioxus_native_core::*;
|
||||
use dioxus_native_core::{
|
||||
node_ref::{AttributeMask, NodeView},
|
||||
real_dom::RealDom,
|
||||
state::{ParentDepState, State},
|
||||
NodeMask, SendAnyMap,
|
||||
};
|
||||
use dioxus_native_core_macro::{sorted_str_slice, State};
|
||||
use std::{
|
||||
sync::{Arc, Mutex},
|
||||
time::Duration,
|
||||
};
|
||||
use tokio::time::sleep;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct BlablaState {}
|
||||
|
||||
/// Font style are inherited by default if not specified otherwise by some of the supported attributes.
|
||||
impl ParentDepState for BlablaState {
|
||||
type Ctx = ();
|
||||
type DepState = (Self,);
|
||||
|
||||
const NODE_MASK: NodeMask =
|
||||
NodeMask::new_with_attrs(AttributeMask::Static(&sorted_str_slice!(["blabla",])));
|
||||
|
||||
fn reduce<'a>(
|
||||
&mut self,
|
||||
_node: NodeView,
|
||||
_parent: Option<(&'a Self,)>,
|
||||
_ctx: &Self::Ctx,
|
||||
) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, State, Default, Debug)]
|
||||
pub struct NodeState {
|
||||
#[parent_dep_state(blabla)]
|
||||
blabla: BlablaState,
|
||||
}
|
||||
|
||||
mod dioxus_elements {
|
||||
macro_rules! builder_constructors {
|
||||
(
|
||||
$(
|
||||
$(#[$attr:meta])*
|
||||
$name:ident {
|
||||
$(
|
||||
$(#[$attr_method:meta])*
|
||||
$fil:ident: $vil:ident,
|
||||
)*
|
||||
};
|
||||
)*
|
||||
) => {
|
||||
$(
|
||||
#[allow(non_camel_case_types)]
|
||||
$(#[$attr])*
|
||||
pub struct $name;
|
||||
|
||||
impl $name {
|
||||
pub const TAG_NAME: &'static str = stringify!($name);
|
||||
pub const NAME_SPACE: Option<&'static str> = None;
|
||||
|
||||
$(
|
||||
pub const $fil: (&'static str, Option<&'static str>, bool) = (stringify!($fil), None, false);
|
||||
)*
|
||||
}
|
||||
|
||||
impl GlobalAttributes for $name {}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GlobalAttributes {}
|
||||
|
||||
pub trait SvgAttributes {}
|
||||
|
||||
builder_constructors! {
|
||||
blabla {
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_core_is_okay() {
|
||||
use std::time::Duration;
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let colors = use_state(&cx, || vec!["green", "blue", "red"]);
|
||||
let padding = use_state(&cx, || 10);
|
||||
|
||||
use_effect(&cx, colors, |colors| async move {
|
||||
sleep(Duration::from_millis(1000)).await;
|
||||
colors.with_mut(|colors| colors.reverse());
|
||||
});
|
||||
|
||||
use_effect(&cx, padding, |padding| async move {
|
||||
sleep(Duration::from_millis(10)).await;
|
||||
padding.with_mut(|padding| {
|
||||
if *padding < 65 {
|
||||
*padding += 1;
|
||||
} else {
|
||||
*padding = 5;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let big = colors[0];
|
||||
let mid = colors[1];
|
||||
let small = colors[2];
|
||||
|
||||
cx.render(rsx! {
|
||||
blabla {}
|
||||
})
|
||||
}
|
||||
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_time()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
rt.block_on(async {
|
||||
let rdom = Arc::new(Mutex::new(RealDom::<NodeState>::new()));
|
||||
let mut dom = VirtualDom::new(app);
|
||||
|
||||
let muts = dom.rebuild();
|
||||
let (to_update, _diff) = rdom.lock().unwrap().apply_mutations(muts);
|
||||
|
||||
let ctx = SendAnyMap::new();
|
||||
let ctx = SendAnyMap::new();
|
||||
rdom.lock().unwrap().update_state(to_update, ctx);
|
||||
|
||||
for x in 0..10 {
|
||||
dom.wait_for_work().await;
|
||||
|
||||
let mutations = dom.render_immediate();
|
||||
let (to_update, _diff) = rdom.lock().unwrap().apply_mutations(mutations);
|
||||
|
||||
let ctx = SendAnyMap::new();
|
||||
let ctx = SendAnyMap::new();
|
||||
rdom.lock().unwrap().update_state(to_update, ctx);
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue