Help us shape the future of Go! Take the 2026 Go Developer Survey

guards

command
v0.8.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

guards censuses ruby/spec's `ruby_version_is` by SHAPE, because the two shapes move the population in different directions and only one of them has ever been counted.

BLOCK     ruby_version_is "4.0" do … end
          The examples inside are SKIPPED while CUR_VERSION is below the
          threshold. Raising it ADDS them to the population.

INLINE    msg_class = ruby_version_is("4.0") ? "Module" : "module"
          The example RUNS either way; the guard only picks a value. Below
          the threshold it picks the PRE-4.0 branch, so the example holds
          rbgo to a string MRI no longer produces. Raising CUR_VERSION
          changes what these ASSERT without changing how many there are.

Why it exists: #799 asks for a decision about CUR_VERSION and says both directions must be measured before BASELINE is regenerated, because `UPDATE_BASELINE=1` records whatever it sees and would absorb a loss silently. This is the static half of that measurement — the half that needs no sweep, and so can be run on a loaded machine, where a sweep cannot.

⛔ THE SHAPE IS DECIDED BY WHAT OPENS A BLOCK, NOT BY THE PARENTHESES. A first draft keyed on "no parentheses, and the line ends in do". It was wrong twice, and both were found by PRINTING THE SITES instead of only the totals:

ruby_version_is "4.0" do # https://bugs.ruby-lang.org/issues/21844
    a block guard whose trailing comment defeats a `do\s*$` anchor
ruby_version_is("4.0") do
    a block guard that IS parenthesised

Five guards at "4.0" hide in those two shapes, so a census anchored that way reports 56 where there are 61.

⛔ THE EXAMPLE COUNT IS A LOWER BOUND AND SAYS SO. Counting `it` blocks inside a guard needs Ruby `end`-matching, which is a heuristic without a parser — and a static count cannot see shared examples (`it_behaves_like`) at all. The control below restricts the count to exactly the guards a `do\s*$` anchor finds, where #799 measured 56 guards and 167 examples: the guard number reproduces and the example number does not, which places the difference in the counting rather than in the census. Tuning the heuristic until it reached 167 would be fitting the instrument to the expected answer.

Exit status: 0 the census ran; 2 the corpus could not be read — a refusal, not an empty census.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL