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

test(parser): snapsot testing with insta #265

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

39555
Copy link
Contributor

@39555 39555 commented Nov 8, 2024

This draft includes an example of testing with insta. It requires serde support because Debug snapshots are unmanageably wide:
Screenshot 2024-11-08 at 9 55 28 PM
compared to yaml snapshots:

Screenshot 2024-11-08 at 10 12 17 PM

Usage

  • pass the parsed ast into insta::assert_yaml_snapshot
  • run with cargo insta review
  • accept the snapshot
  • rerun with cargo test
  • if a newly created snapshot differs the test fails

Cons

One inconvenience is that multiline fields in snap files are not formatted which requires always using cargo insta tool to pretty printing snapshots. This might related to mitsuhiko/insta#372 I heven't found a good way to store the text input along with the ast snapshot.

---
source: brush-parser/src/parser.rs
description: "\n#!/usr/bin/env bash\n\nfor f in A B C; do\n\n    # sdfsdf\n    echo \"${f@L}\" >&2\n\n   done\n\n"
---
...

Copy link

github-actions bot commented Nov 8, 2024

Performance Benchmark Report

Benchmark name Baseline (μs) Test/PR (μs) Delta (μs) Delta %
expand_one_string 3.46 μs 3.46 μs 0.00 μs ⚪ Unchanged
instantiate_shell 61.00 μs 60.23 μs -0.77 μs ⚪ Unchanged
instantiate_shell_with_init_scripts 30536.96 μs 31015.17 μs 478.21 μs 🟠 +1.57%
parse_bash_completion 2799.21 μs 2822.63 μs 23.42 μs 🟠 +0.84%
parse_sample_script 4.25 μs 4.22 μs -0.03 μs ⚪ Unchanged
run_echo_builtin_command 90.72 μs 91.47 μs 0.75 μs ⚪ Unchanged
run_one_builtin_command 108.64 μs 110.67 μs 2.03 μs ⚪ Unchanged
run_one_external_command 1913.96 μs 1974.41 μs 60.45 μs 🟠 +3.16%
run_one_external_command_directly 1013.32 μs 1017.33 μs 4.01 μs ⚪ Unchanged

Code Coverage Report: Only Changed Files listed

Package Base Coverage New Coverage Difference
brush-core/src/jobs.rs 🔴 42.42% 🔴 37.23% 🔴 -5.19%
brush-parser/src/parser.rs 🟢 99.14% 🟢 99.16% 🟢 0.02%
Overall Coverage 🟢 77.84% 🟢 77.78% 🔴 -0.06%

Minimum allowed coverage is 70%, this run produced 77.78%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant