Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: setup miri #74

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,36 @@ jobs:

- name: Run cargo check with every combination of features
run: cargo hack check --feature-powerset --exclude-features db --no-dev-deps

miri:
if: github.event_name == 'push' || github.event_name == 'schedule' ||
github.event.pull_request.head.repo.full_name != github.repository

name: Miri test
runs-on: ubuntu-latest
needs: ["build"]
steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: miri

- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: nextest

- name: Cache Cargo registry
uses: Swatinem/rust-cache@v2

- name: Miri setup
run: cargo miri setup

- name: Miri test
run: cargo miri nextest run --no-fail-fast --all-features
env:
MIRIFLAGS: -Zmiri-disable-isolation
1 change: 1 addition & 0 deletions flareon-cli/tests/migration_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use flareon_cli::migration_generator::{
/// Test that the migration generator can generate a create model migration for
/// a given model which compiles successfully.
#[test]
#[cfg_attr(miri, ignore)] // unsupported operation: extern static `pidfd_spawnp` is not supported by Miri
fn create_model_compile_test() {
let mut generator = MigrationGenerator::new(
PathBuf::from("Cargo.toml"),
Expand Down
1 change: 1 addition & 0 deletions flareon-macros/src/dbtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub(super) fn fn_to_dbtest(test_function_decl: ItemFn) -> syn::Result<TokenStrea

let result = quote! {
#[::tokio::test]
#[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `sqlite3_open_v2`
async fn #sqlite_ident() {
let mut database = flareon::test::TestDatabase::new_sqlite().await.unwrap();

Expand Down
4 changes: 4 additions & 0 deletions flareon-macros/tests/compile_tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#[rustversion::attr(not(nightly), ignore)]
#[test]
#[cfg_attr(miri, ignore)] // unsupported operation: extern static `pidfd_spawnp` is not supported by Miri
fn derive_form() {
let t = trybuild::TestCases::new();
t.pass("tests/ui/derive_form.rs");
}

#[rustversion::attr(not(nightly), ignore)]
#[test]
#[cfg_attr(miri, ignore)] // unsupported operation: extern static `pidfd_spawnp` is not supported by Miri
fn attr_model() {
let t = trybuild::TestCases::new();
t.pass("tests/ui/attr_model.rs");
Expand All @@ -18,6 +20,7 @@ fn attr_model() {

#[rustversion::attr(not(nightly), ignore)]
#[test]
#[cfg_attr(miri, ignore)] // unsupported operation: extern static `pidfd_spawnp` is not supported by Miri
fn func_query() {
let t = trybuild::TestCases::new();
t.pass("tests/ui/func_query.rs");
Expand All @@ -29,6 +32,7 @@ fn func_query() {

#[rustversion::attr(not(nightly), ignore)]
#[test]
#[cfg_attr(miri, ignore)] // unsupported operation: extern static `pidfd_spawnp` is not supported by Miri
fn attr_main() {
let t = trybuild::TestCases::new();
t.pass("tests/ui/attr_main.rs");
Expand Down
4 changes: 4 additions & 0 deletions flareon/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn password_hash() {
let password = Password::new("password".to_string());
let hash = PasswordHash::from_password(&password);
Expand Down Expand Up @@ -873,6 +874,7 @@ mod tests {
const TEST_PASSWORD_HASH: &str = "$argon2id$v=19$m=19456,t=2,p=1$QAAI3EMU1eTLT9NzzBhQjg$khq4zuHsEyk9trGjuqMBFYnTbpqkmn0wXGxFn1nkPBc";

#[test]
#[cfg_attr(miri, ignore)]
fn password_hash_debug() {
let hash = PasswordHash::new(TEST_PASSWORD_HASH).unwrap();
assert_eq!(
Expand All @@ -882,6 +884,7 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn password_hash_verify() {
let password = Password::new("password");
let hash = PasswordHash::from_password(&password);
Expand All @@ -898,6 +901,7 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn password_hash_str() {
let hash = PasswordHash::new(TEST_PASSWORD_HASH).unwrap();
assert_eq!(hash.as_str(), TEST_PASSWORD_HASH);
Expand Down
7 changes: 7 additions & 0 deletions flareon/src/auth/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ mod tests {
use crate::db::MockDatabaseBackend;

#[test]
#[cfg_attr(miri, ignore)]
fn session_auth_hash() {
let user = DatabaseUser::new(
1,
Expand All @@ -389,6 +390,7 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn database_user_traits() {
let user = DatabaseUser::new(
1,
Expand All @@ -406,6 +408,7 @@ mod tests {
}

#[tokio::test]
#[cfg_attr(miri, ignore)]
async fn create_user() {
let mut mock_db = MockDatabaseBackend::new();
mock_db
Expand All @@ -422,6 +425,7 @@ mod tests {
}

#[tokio::test]
#[cfg_attr(miri, ignore)]
async fn get_by_id() {
let mut mock_db = MockDatabaseBackend::new();
let user = DatabaseUser::new(
Expand All @@ -442,6 +446,7 @@ mod tests {
}

#[tokio::test]
#[cfg_attr(miri, ignore)]
async fn authenticate() {
let mut mock_db = MockDatabaseBackend::new();
let user = DatabaseUser::new(
Expand All @@ -464,6 +469,7 @@ mod tests {
}

#[tokio::test]
#[cfg_attr(miri, ignore)]
async fn authenticate_non_existing() {
let mut mock_db = MockDatabaseBackend::new();

Expand All @@ -480,6 +486,7 @@ mod tests {
}

#[tokio::test]
#[cfg_attr(miri, ignore)]
async fn authenticate_invalid_password() {
let mut mock_db = MockDatabaseBackend::new();
let user = DatabaseUser::new(
Expand Down
2 changes: 2 additions & 0 deletions flareon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ mod tests {
}

#[tokio::test]
#[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `sqlite3_open_v2`
async fn flareon_project_builder() {
let project = FlareonProject::builder()
.register_app_with_views(MockFlareonApp {}, "/app")
Expand All @@ -785,6 +786,7 @@ mod tests {
}

#[tokio::test]
#[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `sqlite3_open_v2`
async fn flareon_project_router() {
let project = FlareonProject::builder()
.register_app_with_views(MockFlareonApp {}, "/app")
Expand Down
2 changes: 2 additions & 0 deletions flareon/src/static_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ mod tests {
use crate::{FlareonApp, FlareonProject};

#[test]
#[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `sqlite3_open_v2`
fn static_files_add_and_get_file() {
let mut static_files = StaticFiles::new();
static_files.add_file("test.txt", "This is a test file");
Expand Down Expand Up @@ -338,6 +339,7 @@ mod tests {
}

#[tokio::test]
#[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `sqlite3_open_v2`
async fn static_files_middleware_from_app_context() {
struct App1;
impl FlareonApp for App1 {
Expand Down
1 change: 1 addition & 0 deletions flareon/tests/db.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(feature = "fake")]
#![cfg_attr(miri, ignore)]

use fake::rand::rngs::StdRng;
use fake::rand::SeedableRng;
Expand Down
1 change: 1 addition & 0 deletions flareon/tests/flareon_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ async fn hello(_request: Request) -> flareon::Result<Response> {
}

#[tokio::test]
#[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `sqlite3_open_v2`
async fn flareon_project_router_sub_path() {
struct App1;
impl FlareonApp for App1 {
Expand Down
2 changes: 2 additions & 0 deletions flareon/tests/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async fn parameterized(request: Request) -> flareon::Result<Response> {
}

#[tokio::test]
#[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `sqlite3_open_v2`
async fn test_index() {
let mut client = Client::new(project().await);

Expand All @@ -31,6 +32,7 @@ async fn test_index() {
}

#[tokio::test]
#[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `sqlite3_open_v2`
async fn path_params() {
let mut client = Client::new(project().await);

Expand Down
Loading