Skip to content

Commit

Permalink
test: add tests to catch 2 mutants
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cljoly committed Mar 19, 2024
1 parent 45a359b commit 96ba69f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
23 changes: 23 additions & 0 deletions rusqlite_migration/src/tests/synch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
4 changes: 2 additions & 2 deletions rusqlite_migration_tokio_async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 96ba69f

Please sign in to comment.