reubeno / brush

bash/POSIX-compatible shell implemented in Rust
MIT License
27 stars 4 forks source link

test(parser): snapsot testing with insta #265

Open 39555 opened 2 weeks ago

39555 commented 2 weeks ago

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

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 https://github.com/mitsuhiko/insta/issues/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"
---
...
github-actions[bot] commented 2 weeks ago

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%