From f14e7f684cb02e50d947ef1648c422fa299afd6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Joly?= Date: Tue, 19 Mar 2024 01:28:52 +0000 Subject: [PATCH] test: add tests to catch 2 mutants The mutants were: ``` MISSED rusqlite_migration_tokio_async/src/lib.rs:2:10: replace + with * in add in 0.2s build + 0.1s test MISSED rusqlite_migration/src/lib.rs:535:35: replace - with + in Migrations<'m>::goto_down in 0.9s build + 1.5s test ``` While we are here, shard mutants to avoid waiting for too long on CI. --- .github/workflows/ci.yml | 5 ++++- rusqlite_migration/src/tests/synch.rs | 23 +++++++++++++++++++++++ rusqlite_migration_tokio_async/src/lib.rs | 4 ++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b1372bb..b28a5bd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -143,6 +143,9 @@ jobs: mutation-tests: name: Mutation tests runs-on: ubuntu-latest + strategy: + matrix: + shard: [0, 1, 2, 3] steps: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 @@ -155,7 +158,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: mutants - args: --colors=always + args: --colors=always --no-shuffle -vV --shard ${{ matrix.shard }}/4 - name: Archive results uses: actions/upload-artifact@v3 if: failure() diff --git a/rusqlite_migration/src/tests/synch.rs b/rusqlite_migration/src/tests/synch.rs index d7d485f..a51997b 100644 --- a/rusqlite_migration/src/tests/synch.rs +++ b/rusqlite_migration/src/tests/synch.rs @@ -530,3 +530,26 @@ fn test_user_version_error() { assert!(e.is_err(), "{:?}", e); insta::assert_debug_snapshot!(e) } + +#[test] +fn test_missing_down_migration() { + let mut conn = Connection::open_in_memory().unwrap(); + let ms = vec![ + M::up("CREATE TABLE t1(a)").down("DROP TABLE t1"), + M::up("CREATE TABLE t2(a)").down("DROP TABLE t2"), + M::up("CREATE TABLE t3(a)"), + M::up("CREATE TABLE t4(a)").down("DROP TABLE t4"), + M::up("CREATE TABLE t5(a)"), + ]; + + let m = Migrations::new(ms); + m.to_version(&mut conn, 4).unwrap(); + + m.to_version(&mut conn, 3).unwrap(); + assert_eq!( + Err(Error::MigrationDefinition( + MigrationDefinitionError::DownNotDefined { migration_index: 2 } + )), + m.to_version(&mut conn, 2) + ); +} diff --git a/rusqlite_migration_tokio_async/src/lib.rs b/rusqlite_migration_tokio_async/src/lib.rs index 7d12d9a..1751e6f 100644 --- a/rusqlite_migration_tokio_async/src/lib.rs +++ b/rusqlite_migration_tokio_async/src/lib.rs @@ -8,7 +8,7 @@ mod tests { #[test] fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); + let result = add(2, 5); + assert_eq!(result, 7); } }