Skip to content
Myr

Merge pull request #947 from Likio3000/codex/fix-markdown-backticks

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Preserve backticks in Markdown command names

authored by David Peter · committed by GitHub · parents a2d7094, 9bf42b3 · Browse files · 2 files+50 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+50 added−1 removed

  • tests:+21 added−0 removed
  • other:+29 added−1 removed

2 files+50 added−1 removed

modified:src/export/markdown.rs+29 added-1 removed
22 unmodified lines
23 )24 }2526 fn command(&self, cmd: &str) -> String {27 let longest_backtick_run = cmd28 .split(|character| character != '`')29 .map(str::len)30 .max()31 .unwrap_or(0);3233 if longest_backtick_run == 0 {27 format!("`{cmd}`")34 format!("`{cmd}`")35 } else {36 // Use a longer delimiter and keep command backticks separate from it.37 let delimiter = "`".repeat(longest_backtick_run + 1);38 format!("{delimiter} {cmd} {delimiter}")39 }40 }41}4243/// Check Markdown-based data row formatting
11 unmodified lines
5556 let divider = formatter.table_divider(&[Alignment::Left, Alignment::Right, Alignment::Left]);57 assert_eq!(divider, "|:---|---:|:---|\n");58}5960#[test]61fn test_markdown_formatter_command_with_backticks() {62 let formatter = MarkdownExporter::default();6364 for (command, expected) in [65 ("echo `uname`", "`` echo `uname` ``"),66 ("echo ``quoted``", "``` echo ``quoted`` ```"),67 ("`` `quoted` ``", "``` `` `quoted` `` ```"),68 ("`", "`` ` ``"),69 ("echo ```", "```` echo ``` ````"),70 (" echo `uname` ", "`` echo `uname` ``"),71 ] {72 assert_eq!(formatter.command(command), expected, "{command:?}");73 }74}
modified:tests/integration_tests.rs+21 added
928 unmodified lines
929 }930}931932#[test]933fn markdown_export_preserves_backticks_and_pipes_in_command_names() {934 let _settings = snapshot_settings().bind_to_scope();935 assert_cmd_snapshot!(hyperfine_debug()936 .arg("--style=none")937 .arg("--export-markdown=-")938 .arg("--command-name=echo `uname` | cat")939 .arg("sleep 1"), @r"940 success: true941 exit_code: 0942 ----- stdout -----943944 | Command | Mean [s] | Min [s] | Max [s] | Relative |945 |:---|---:|---:|---:|---:|946 | `` echo `uname` \| cat `` | 1.000 ± 0.000 | 1.000 | 1.000 | 1.00 |947948949 ----- stderr -----950 ");951}952953#[test]954fn unused_parameters_are_shown_in_benchmark_name() {955 hyperfine()956 .arg("--runs=2")957 .arg("--parameter-list")
82 unmodified lines