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

cargo-insta example #36

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- run: make install_insta
- run: make test
# coverage:
# runs-on: ubuntu-20.04
Expand Down
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ rand = "0.8.5"
log = "0.4"
env_logger = "0.10.0"

insta = "1.29"

[profile.bench]
opt-level = 3
debug = false
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ clippy:
cargo clippy --all-targets --all-features -- -D warnings

test:
cargo test
cargo insta test

benchmarks:
cargo criterion --bench benchmark

install_insta:
cargo install cargo-insta

insta_demo:
cargo insta test --review -- test_aes_encryption_step_by_step

clean_snapshots:
rm -rf tests/snapshots
16 changes: 16 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,29 @@ mod tests {
round: usize,
) {
let after_substituting_bytes = substitute_bytes(&expected_start_of_round, cs).unwrap();
insta::assert_snapshot!(
format!("{after_substituting_bytes:?}"),
format!("{expected_after_substituting_bytes:?}")
);
assert_eq!(
after_substituting_bytes, expected_after_substituting_bytes,
"Substitution is incorrect in round {round}"
);
let after_shift_rows = shift_rows(&after_substituting_bytes, cs).unwrap();
insta::assert_snapshot!(
format!("{after_shift_rows:?}"),
format!("{expected_after_shift_rows:?}")
);
assert_eq!(
after_shift_rows, expected_after_shift_rows,
"Shift rows is incorrect in round {round}"
);
let after_mix_columns = if round != 10 {
let after_mix_columns = mix_columns(&after_shift_rows).unwrap();
insta::assert_snapshot!(
format!("{after_mix_columns:?}"),
format!("{expected_after_mix_columns:?}")
);
assert_eq!(
after_mix_columns, expected_after_mix_columns,
"Mix columns is incorrect in round {round}",
Expand All @@ -40,6 +52,10 @@ mod tests {
after_shift_rows
};
let start_of_next_round = add_round_key(&after_mix_columns, round_key);
insta::assert_snapshot!(
format!("{start_of_next_round:?}"),
format!("{expected_start_of_next_round:?}")
);
assert_eq!(
start_of_next_round, expected_start_of_next_round,
"Start of next round is incorrect in round {round}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 42
expression: "format!(\"{expected_after_mix_columns:?}\")"
---
[0, 81, 47, 209, 177, 200, 137, 255, 84, 118, 109, 205, 250, 27, 153, 234]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 42
expression: "format!(\"{expected_after_mix_columns:?}\")"
---
[117, 236, 9, 147, 32, 11, 99, 51, 83, 192, 207, 124, 187, 37, 208, 220]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 32
expression: "format!(\"{expected_after_shift_rows:?}\")"
---
[135, 110, 70, 166, 242, 76, 231, 140, 77, 144, 74, 216, 151, 236, 195, 149]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 23
expression: "format!(\"{expected_after_substituting_bytes:?}\")"
---
[135, 236, 74, 140, 242, 110, 195, 216, 77, 76, 70, 149, 151, 144, 231, 166]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 42
expression: "format!(\"{expected_after_mix_columns:?}\")"
---
[15, 214, 218, 169, 96, 49, 56, 191, 111, 192, 16, 107, 94, 179, 19, 1]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 32
expression: "format!(\"{expected_after_shift_rows:?}\")"
---
[161, 79, 61, 254, 120, 232, 3, 252, 16, 213, 168, 223, 76, 99, 41, 35]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 23
expression: "format!(\"{expected_after_substituting_bytes:?}\")"
---
[161, 99, 168, 252, 120, 79, 41, 223, 16, 232, 61, 35, 76, 213, 3, 254]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 55
expression: "format!(\"{expected_start_of_next_round:?}\")"
---
[164, 156, 127, 242, 104, 159, 53, 43, 107, 91, 234, 67, 2, 106, 80, 73]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 55
expression: "format!(\"{expected_start_of_next_round:?}\")"
---
[170, 143, 95, 3, 97, 221, 227, 239, 130, 210, 74, 210, 104, 50, 70, 154]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 23
expression: "format!(\"{expected_after_substituting_bytes:?}\")"
---
[172, 115, 207, 123, 239, 193, 17, 223, 19, 181, 214, 181, 69, 35, 90, 184]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 32
expression: "format!(\"{expected_after_shift_rows:?}\")"
---
[172, 193, 214, 184, 239, 181, 90, 123, 19, 35, 207, 223, 69, 115, 17, 181]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 23
expression: "format!(\"{expected_after_substituting_bytes:?}\")"
---
[190, 131, 44, 200, 212, 59, 134, 192, 10, 225, 212, 77, 218, 100, 242, 254]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 32
expression: "format!(\"{expected_after_shift_rows:?}\")"
---
[190, 59, 212, 254, 212, 225, 242, 200, 10, 100, 44, 192, 218, 131, 134, 77]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 42
expression: "format!(\"{expected_after_mix_columns:?}\")"
---
[20, 21, 181, 191, 70, 22, 21, 236, 39, 70, 86, 215, 52, 42, 216, 67]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 32
expression: "format!(\"{expected_after_shift_rows:?}\")"
---
[212, 191, 93, 48, 224, 180, 82, 174, 184, 65, 17, 241, 30, 39, 152, 229]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 23
expression: "format!(\"{expected_after_substituting_bytes:?}\")"
---
[212, 39, 17, 174, 224, 191, 152, 241, 184, 180, 93, 229, 30, 65, 82, 48]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 55
expression: "format!(\"{expected_start_of_next_round:?}\")"
---
[224, 146, 127, 232, 200, 99, 99, 192, 217, 177, 53, 80, 133, 184, 190, 1]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 32
expression: "format!(\"{expected_after_shift_rows:?}\")"
---
[225, 251, 150, 124, 232, 200, 174, 155, 53, 108, 210, 186, 151, 79, 251, 83]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 23
expression: "format!(\"{expected_after_substituting_bytes:?}\")"
---
[225, 79, 210, 155, 232, 251, 251, 186, 53, 200, 150, 83, 151, 108, 174, 124]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 32
expression: "format!(\"{expected_after_shift_rows:?}\")"
---
[233, 49, 125, 181, 203, 50, 44, 114, 61, 46, 137, 95, 175, 9, 7, 148]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 23
expression: "format!(\"{expected_after_substituting_bytes:?}\")"
---
[233, 9, 137, 114, 203, 49, 7, 95, 61, 50, 125, 148, 175, 46, 44, 181]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 55
expression: "format!(\"{expected_start_of_next_round:?}\")"
---
[234, 131, 92, 240, 4, 69, 51, 45, 101, 93, 152, 173, 133, 150, 176, 197]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 55
expression: "format!(\"{expected_start_of_next_round:?}\")"
---
[235, 64, 242, 30, 89, 46, 56, 132, 139, 161, 19, 231, 27, 195, 66, 210]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 55
expression: "format!(\"{expected_start_of_next_round:?}\")"
---
[241, 0, 111, 85, 193, 146, 76, 239, 124, 200, 139, 50, 93, 181, 213, 12]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 32
expression: "format!(\"{expected_after_shift_rows:?}\")"
---
[247, 131, 64, 63, 39, 67, 61, 240, 155, 181, 49, 255, 84, 171, 169, 211]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 23
expression: "format!(\"{expected_after_substituting_bytes:?}\")"
---
[247, 171, 49, 240, 39, 131, 169, 255, 155, 67, 64, 211, 84, 181, 61, 63]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 42
expression: "format!(\"{expected_after_mix_columns:?}\")"
---
[37, 209, 169, 173, 189, 17, 209, 104, 182, 58, 51, 142, 76, 76, 192, 176]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 55
expression: "format!(\"{expected_start_of_next_round:?}\")"
---
[38, 14, 46, 23, 61, 65, 183, 125, 232, 100, 114, 169, 253, 210, 139, 37]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 42
expression: "format!(\"{expected_after_mix_columns:?}\")"
---
[4, 102, 129, 229, 224, 203, 25, 154, 72, 248, 211, 122, 40, 6, 38, 76]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 55
expression: "format!(\"{expected_start_of_next_round:?}\")"
---
[57, 37, 132, 29, 2, 220, 9, 251, 220, 17, 133, 151, 25, 106, 11, 50]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 42
expression: "format!(\"{expected_after_mix_columns:?}\")"
---
[71, 55, 148, 237, 64, 212, 228, 165, 163, 112, 58, 166, 76, 159, 66, 188]
Loading