hegeltest 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +74 -0
- data/docs/README.md +1 -0
- data/docs/adr/0019-report-failures-from-the-cases-the-engine-stamps.md +4 -1
- data/docs/adr/0038-hand-the-engine-a-failure-summary-and-detail.md +96 -0
- data/lib/hegel/generators.rb +15 -6
- data/lib/hegel/lib_hegel/real.rb +74 -33
- data/lib/hegel/lib_hegel.rb +7 -1
- data/lib/hegel/libhegel_version.rb +1 -1
- data/lib/hegel/runner.rb +68 -17
- data/lib/hegel/version.rb +1 -1
- data/sig/hegel.rbs +4 -2
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 23443ceeafec04e3d8ac87a00b58e97b6ebf218b0e94c55a1969e6bd690a153d
|
|
4
|
+
data.tar.gz: 1801cd2655801d797bcea68a0085a1c22641b5772fdf449abdbe0501e3fd195e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 584e98a6618abaa2be4d8cf03298984b84209cf9c78d0e0d4b4a81cf6a7a5b13efde68abd198eabee87a5c951d871d5a5c25a91312949a8f4e360e17cb05f3e6
|
|
7
|
+
data.tar.gz: 6a9fe805a7dfb806ae26e73b58b2473bca4726e7a4fb7a9039d3e755068dd713a1dbd0ea59f0084e0ab41d39731d7fc3d0603cf163cf243e4174eff6c834ad4b
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,78 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.5.4] - 2026-11-20
|
|
6
|
+
|
|
7
|
+
### Engine: libhegel 0.53.0 (was 0.51.6)
|
|
8
|
+
|
|
9
|
+
The [libhegel 0.53.0 release notes](https://github.com/hegeldev/hegel/releases/tag/libhegel/0.53.0)
|
|
10
|
+
describe 0.53.0. The move also includes 0.52.0, and the
|
|
11
|
+
[libhegel changelog at 0.53.0](https://github.com/hegeldev/hegel/blob/libhegel/0.53.0/libhegel/CHANGELOG.md)
|
|
12
|
+
describes both releases.
|
|
13
|
+
|
|
14
|
+
Each platform gem carries `libhegel` 0.53.0. A caller has nothing to
|
|
15
|
+
change. The public methods keep their signatures and return values, and a
|
|
16
|
+
run at `:quiet` or `:normal` verbosity prints the same as before.
|
|
17
|
+
|
|
18
|
+
In 0.53.0, `hegel_generate_date`, `hegel_generate_time`, and
|
|
19
|
+
`hegel_generate_datetime` take one more argument: date options for the
|
|
20
|
+
date draw, and a precision for the two time draws. These bindings pass no
|
|
21
|
+
date options and a precision of nanoseconds. Thus `dates`, `times`,
|
|
22
|
+
`datetimes`, `date_strings`, `time_strings`, and `datetime_strings` draw
|
|
23
|
+
from the same set of values as before. The engine now aims about one draw
|
|
24
|
+
in twenty at a calendar value that often finds bugs, such as a leap day
|
|
25
|
+
near a bound, a year boundary, or the last nanosecond of a day. Thus a
|
|
26
|
+
short run can find such a value more frequently than before.
|
|
27
|
+
|
|
28
|
+
The other functions that 0.53.0 adds, such as the time zone, offset,
|
|
29
|
+
duration, and span draws, are not available from this gem yet.
|
|
30
|
+
|
|
31
|
+
In 0.52.0, the engine prints the output of a test case itself, and its C
|
|
32
|
+
ABI changes. A failing test case now gives the engine a one-line summary
|
|
33
|
+
and, when the engine asks for it, the full diagnostic that Ruby prints for
|
|
34
|
+
the exception. The engine rejects a failure without them. These bindings
|
|
35
|
+
send both. See
|
|
36
|
+
[ADR 0038](docs/adr/0038-hand-the-engine-a-failure-summary-and-detail.md).
|
|
37
|
+
|
|
38
|
+
A run at `:verbose` verbosity prints more on stderr: a line for each
|
|
39
|
+
failing test case, such as `test/foo_test.rb:12: too big: 7
|
|
40
|
+
(RuntimeError)`, and a "Test case stopped" line for a test case that ran
|
|
41
|
+
out of data. A run at `:debug` verbosity also prints the backtrace of each
|
|
42
|
+
failure. A verbose run also records the drawn values of every test case,
|
|
43
|
+
so a verbose run can take longer than before.
|
|
44
|
+
|
|
45
|
+
Before 0.52.0, the engine printed to stderr when it got no output
|
|
46
|
+
callback. Now it prints nothing. These bindings now give the engine its
|
|
47
|
+
own stderr writer, so statistics and verbose output still go to stderr.
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
|
|
51
|
+
- `dates` now returns a proleptic Gregorian `Date`, as its documentation
|
|
52
|
+
says. Before, it built the drawn date with Ruby's default calendar, which
|
|
53
|
+
reads a date before 1582-10-15 as Julian. Thus a drawn date from
|
|
54
|
+
1582-10-05 through 1582-10-14 raised `Date::Error`, and an earlier date
|
|
55
|
+
was a different day than the engine drew. libhegel 0.53.0 aims some
|
|
56
|
+
draws at 1582-10-05 and 1582-10-14, so a short run can now draw them.
|
|
57
|
+
A bound before 1582-10-15 that a caller builds with `Date.new` keeps its
|
|
58
|
+
meaning: the generator reads it as the same day.
|
|
59
|
+
|
|
60
|
+
## [0.5.3] - 2026-11-17
|
|
61
|
+
|
|
62
|
+
### Engine: libhegel 0.51.6 (was 0.51.5)
|
|
63
|
+
|
|
64
|
+
The [libhegel 0.51.6 release notes](https://github.com/hegeldev/hegel/releases/tag/libhegel/0.51.6)
|
|
65
|
+
describe 0.51.6.
|
|
66
|
+
|
|
67
|
+
Each platform gem carries `libhegel` 0.51.6. A caller has nothing to
|
|
68
|
+
change. The public methods keep their signatures and return values.
|
|
69
|
+
|
|
70
|
+
In 0.51.6, the engine frees the output region of a
|
|
71
|
+
`hegel_test_case_clone` or `hegel_test_case_block` handle when that region
|
|
72
|
+
holds no output and the last handle that writes into it is freed. Before,
|
|
73
|
+
the engine kept each region until the test case ended. These bindings do
|
|
74
|
+
not call these two functions, so this fix does not change what a run does
|
|
75
|
+
here.
|
|
76
|
+
|
|
5
77
|
## [0.5.2] - 2026-11-14
|
|
6
78
|
|
|
7
79
|
### Engine: libhegel 0.51.5 (was 0.51.1)
|
|
@@ -568,6 +640,8 @@ The engine is called through the `ffi` gem. Each platform gem carries the
|
|
|
568
640
|
matching `libhegel` 0.32.5 build. The platform-independent gem carries none,
|
|
569
641
|
so a run on it needs `HEGEL_LIBHEGEL_PATH` pointing at a local build.
|
|
570
642
|
|
|
643
|
+
[0.5.4]: https://github.com/meganemura/hegel-ruby/releases/tag/v0.5.4
|
|
644
|
+
[0.5.3]: https://github.com/meganemura/hegel-ruby/releases/tag/v0.5.3
|
|
571
645
|
[0.5.2]: https://github.com/meganemura/hegel-ruby/releases/tag/v0.5.2
|
|
572
646
|
[0.5.1]: https://github.com/meganemura/hegel-ruby/releases/tag/v0.5.1
|
|
573
647
|
[0.5.0]: https://github.com/meganemura/hegel-ruby/releases/tag/v0.5.0
|
data/docs/README.md
CHANGED
|
@@ -44,6 +44,7 @@ An index of the design records for `hegel-ruby`.
|
|
|
44
44
|
- [0035: Defer concurrent state machines and the engine printer](adr/0035-defer-concurrent-state-machines-and-the-engine-printer.md)
|
|
45
45
|
- [0036: Follow Ruby's Unicode version](adr/0036-follow-rubys-unicode-version.md)
|
|
46
46
|
- [0037: Send a maximum at the engine's default sentinel as no bound](adr/0037-send-a-maximum-at-the-engine-default-sentinel-as-no-bound.md)
|
|
47
|
+
- [0038: Hand the engine a failure summary and detail](adr/0038-hand-the-engine-a-failure-summary-and-detail.md)
|
|
47
48
|
|
|
48
49
|
A new decision gets a new record. A changed decision supersedes the old
|
|
49
50
|
record instead of editing it, so the history stays readable.
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## Status
|
|
4
4
|
|
|
5
|
-
Accepted.
|
|
5
|
+
Accepted. Superseded in part by
|
|
6
|
+
[ADR 0038](0038-hand-the-engine-a-failure-summary-and-detail.md): since
|
|
7
|
+
libhegel 0.52, the stamp is read through `hegel_test_case_wants_output`,
|
|
8
|
+
which also answers true for every case of a verbose run.
|
|
6
9
|
|
|
7
10
|
## Context
|
|
8
11
|
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# 0038: Hand the engine a failure summary and detail
|
|
2
|
+
|
|
3
|
+
## Status
|
|
4
|
+
|
|
5
|
+
Accepted. Supersedes in part
|
|
6
|
+
[ADR 0019](0019-report-failures-from-the-cases-the-engine-stamps.md).
|
|
7
|
+
|
|
8
|
+
## Context
|
|
9
|
+
|
|
10
|
+
libhegel 0.52.0 moves the printing of a test case's output into the
|
|
11
|
+
engine. Three changes in its C ABI reach this gem:
|
|
12
|
+
|
|
13
|
+
1. `hegel_test_case_should_capture` is removed. Two calls replace it.
|
|
14
|
+
`hegel_test_case_wants_output` says whether the engine will use what a
|
|
15
|
+
case prints: every case of a verbose run, and each case the engine
|
|
16
|
+
stamps for capture, quiet runs included.
|
|
17
|
+
`hegel_test_case_wants_detail` says whether the engine will use a
|
|
18
|
+
failure's full diagnostic: every case of a debug run, and the stamped
|
|
19
|
+
cases of a normal or verbose run. A quiet run wants no detail.
|
|
20
|
+
2. `hegel_mark_complete` takes a `summary` and a `detail` after the
|
|
21
|
+
`origin`. An INTERESTING case must give a summary of one line when the
|
|
22
|
+
engine wants its output, and a detail when it wants its detail. Each
|
|
23
|
+
string must be valid UTF-8. The engine rejects any other call with
|
|
24
|
+
`HEGEL_E_INVALID_ARG` and completes nothing, so the run cannot go on.
|
|
25
|
+
3. A NULL output callback to `hegel_run_start` now means no destination.
|
|
26
|
+
Before 0.52.0 it meant stderr, and ADR 0035 records that this gem
|
|
27
|
+
passes NULL. The engine exports `hegel_output_stderr` for a caller that
|
|
28
|
+
wants stderr.
|
|
29
|
+
|
|
30
|
+
The engine also adds `hegel_failure_output` and `hegel_failure_diagnostic`,
|
|
31
|
+
which give the failure report that the engine kept. This gem builds its
|
|
32
|
+
report in Ruby (ADR 0035), so it does not need them for this update.
|
|
33
|
+
|
|
34
|
+
Measured against libhegel 0.52.0 on linux-amd64 with Ruby 3.4.10, over 10
|
|
35
|
+
runs each of a property that fails when a drawn integer in 0..1_000_000 is
|
|
36
|
+
above 500_000, with the default 100 test cases: a quiet run gave the body
|
|
37
|
+
101 to 175 cases, of which 5 wanted output and none wanted detail; a
|
|
38
|
+
normal run gave 110 to 148 cases, of which 5 wanted output and 5 wanted
|
|
39
|
+
detail.
|
|
40
|
+
|
|
41
|
+
## Decision
|
|
42
|
+
|
|
43
|
+
The runner reads both flags when a case starts. `wants_output` takes the
|
|
44
|
+
place of the old stamp: the case records its draws and notes only when it
|
|
45
|
+
is true.
|
|
46
|
+
|
|
47
|
+
A failing case gives `hegel_mark_complete` a summary when `wants_output`
|
|
48
|
+
is true, and a detail when `wants_detail` is true. Neither is built
|
|
49
|
+
otherwise, because a backtrace costs more than a shrink probe should pay.
|
|
50
|
+
|
|
51
|
+
- The summary is the caller's own location (the frame ADR 0012 picks for
|
|
52
|
+
the origin), the first line of the message, and the exception class in
|
|
53
|
+
parentheses: `test/foo_test.rb:12: too big: 7 (RuntimeError)`. Ruby puts
|
|
54
|
+
the class after the message when it prints an uncaught exception, so the
|
|
55
|
+
summary does too. The header asks for the location first, as a compiler
|
|
56
|
+
diagnostic gives it. A message of several lines is cut at its first line
|
|
57
|
+
and followed by ` …`, as the header asks and as hegel-rust's
|
|
58
|
+
`render_summary` does.
|
|
59
|
+
- The detail is `Exception#full_message(highlight: false, order: :top)`:
|
|
60
|
+
what Ruby prints for the exception on its own, with its backtrace.
|
|
61
|
+
- Both strings are made valid UTF-8 before they go to the engine. A binary
|
|
62
|
+
string is read as UTF-8. A string in another encoding is converted. A
|
|
63
|
+
byte that is still invalid becomes U+FFFD.
|
|
64
|
+
|
|
65
|
+
`Hegel::LibHegel::Real` passes `hegel_output_stderr` as the output
|
|
66
|
+
callback of every run. This keeps engine output on stderr, as it was
|
|
67
|
+
before 0.52.0, and it is what hegel-rust's `frontends/rust/src/ffi.rs`
|
|
68
|
+
passes when no sink is given. A C function lives as long as the library,
|
|
69
|
+
so it outlives the run, which the header requires of the callback.
|
|
70
|
+
|
|
71
|
+
Reading the engine's failure report through `hegel_failure_output` was
|
|
72
|
+
refused for this update. The engine's document holds only what a frontend
|
|
73
|
+
prints into it, and this gem does not print draws into it (ADR 0035), so
|
|
74
|
+
the report would be empty.
|
|
75
|
+
|
|
76
|
+
## Consequences
|
|
77
|
+
|
|
78
|
+
A normal run prints the same as before. Measured on the property above
|
|
79
|
+
with `show_statistics: true`, the stderr of a normal run was the same
|
|
80
|
+
against 0.51.6 and against 0.52.0. A quiet run prints nothing to stderr;
|
|
81
|
+
`test/hegel/test_runner.rb` asserts this against 0.52.0.
|
|
82
|
+
|
|
83
|
+
A verbose run prints more. Measured against 0.52.0: after each failing
|
|
84
|
+
case, the engine prints the summary, and for a case that stopped early it
|
|
85
|
+
prints "Test case stopped: out of data". The header says that a debug
|
|
86
|
+
run also prints the detail. The draws and notes of a case still
|
|
87
|
+
do not show in the engine's verbose output, as before.
|
|
88
|
+
|
|
89
|
+
A verbose run records the draws of every case, not only of the stamped
|
|
90
|
+
cases, because the engine wants the output of every case. A verbose run
|
|
91
|
+
costs more for this reason. A run at any other verbosity does not change.
|
|
92
|
+
|
|
93
|
+
ADR 0019's rule for keeping a capture still holds. The header says that
|
|
94
|
+
each failure the engine reports is the last case of that origin it runs,
|
|
95
|
+
and that this case wants its output. A newer capture with recorded draws
|
|
96
|
+
replaces an older one, so the last one is the case the engine reports.
|
data/lib/hegel/generators.rb
CHANGED
|
@@ -1103,10 +1103,19 @@ module Hegel
|
|
|
1103
1103
|
# own src/test_case.rs names this full_ranges::MIN_DATE/MAX_DATE, "what
|
|
1104
1104
|
# Hypothesis's dates() spans".
|
|
1105
1105
|
#
|
|
1106
|
+
# hegel.h defines hegel_date_t as a proleptic Gregorian date, and
|
|
1107
|
+
# hegel-rust reads it into chrono's NaiveDate, which is proleptic
|
|
1108
|
+
# Gregorian too. Ruby's Date.new uses the Italian reform by default: it
|
|
1109
|
+
# reads a date before 1582-10-15 as Julian, and it refuses 1582-10-05
|
|
1110
|
+
# through 1582-10-14. Thus this generator reads the bounds with
|
|
1111
|
+
# Date#gregorian and builds the drawn Date with Date::GREGORIAN. Since
|
|
1112
|
+
# libhegel 0.53.0 the engine aims some draws at 1582-10-05 and
|
|
1113
|
+
# 1582-10-14, so a short run can draw a date that Date.new refuses.
|
|
1114
|
+
#
|
|
1106
1115
|
# Opens no span, for the reason UuidsGenerator gives: one native call.
|
|
1107
1116
|
class DatesGenerator < Generator
|
|
1108
|
-
MIN_DATE = Date.new(1, 1, 1)
|
|
1109
|
-
MAX_DATE = Date.new(9999, 12, 31)
|
|
1117
|
+
MIN_DATE = Date.new(1, 1, 1, Date::GREGORIAN)
|
|
1118
|
+
MAX_DATE = Date.new(9999, 12, 31, Date::GREGORIAN)
|
|
1110
1119
|
|
|
1111
1120
|
def initialize(min_value:, max_value:)
|
|
1112
1121
|
@min_value = min_value
|
|
@@ -1114,14 +1123,14 @@ module Hegel
|
|
|
1114
1123
|
end
|
|
1115
1124
|
|
|
1116
1125
|
def do_draw(tc)
|
|
1117
|
-
min_value = @min_value || MIN_DATE
|
|
1118
|
-
max_value = @max_value || MAX_DATE
|
|
1126
|
+
min_value = (@min_value || MIN_DATE).gregorian
|
|
1127
|
+
max_value = (@max_value || MAX_DATE).gregorian
|
|
1119
1128
|
raise Hegel::Error, "dates: max_value < min_value" if max_value < min_value
|
|
1120
1129
|
|
|
1121
1130
|
year, month, day = tc.generate_date(
|
|
1122
1131
|
[min_value.year, min_value.month, min_value.day], [max_value.year, max_value.month, max_value.day]
|
|
1123
1132
|
)
|
|
1124
|
-
Date.new(year, month, day)
|
|
1133
|
+
Date.new(year, month, day, Date::GREGORIAN)
|
|
1125
1134
|
end
|
|
1126
1135
|
end
|
|
1127
1136
|
|
|
@@ -1187,7 +1196,7 @@ module Hegel
|
|
|
1187
1196
|
# +value+'s hour/minute/second/microsecond as an Array of Integers,
|
|
1188
1197
|
# or raises if it is not a String matching FORMAT. This layer does
|
|
1189
1198
|
# not range-check the parsed fields (an hour of 99, say): measured
|
|
1190
|
-
# against libhegel 0.45.0, hegel_generate_time already returns
|
|
1199
|
+
# against libhegel 0.45.0 and 0.53.0, hegel_generate_time already returns
|
|
1191
1200
|
# HEGEL_E_INVALID_ARG for an invalid time, translated by
|
|
1192
1201
|
# LibHegel.check! once #do_draw calls tc.generate_time, the same
|
|
1193
1202
|
# division of labor DomainsGenerator follows for its own
|
data/lib/hegel/lib_hegel/real.rb
CHANGED
|
@@ -143,12 +143,21 @@ module Hegel
|
|
|
143
143
|
"hegel_run_start_blob", [:pointer, :pointer, StringStruct.by_value, :pointer, :pointer, :pointer], :int32
|
|
144
144
|
)
|
|
145
145
|
@hegel_next_test_case_fn = bind("hegel_next_test_case", [:pointer, :pointer, :pointer], :int32)
|
|
146
|
-
@
|
|
147
|
-
|
|
148
|
-
)
|
|
146
|
+
@hegel_test_case_wants_output_fn = bind("hegel_test_case_wants_output", [:pointer, :pointer, :pointer], :int32)
|
|
147
|
+
@hegel_test_case_wants_detail_fn = bind("hegel_test_case_wants_detail", [:pointer, :pointer, :pointer], :int32)
|
|
149
148
|
@hegel_run_free_fn = bind("hegel_run_free", [:pointer, :pointer], :int32)
|
|
150
149
|
@hegel_test_case_free_fn = bind("hegel_test_case_free", [:pointer, :pointer], :int32)
|
|
151
|
-
@hegel_mark_complete_fn = bind(
|
|
150
|
+
@hegel_mark_complete_fn = bind(
|
|
151
|
+
"hegel_mark_complete", [:pointer, :pointer, :uint32, :pointer, :pointer, :pointer], :int32
|
|
152
|
+
)
|
|
153
|
+
# Since libhegel 0.52, a NULL output callback means "print nothing",
|
|
154
|
+
# where it used to mean stderr. The run passes the engine's own
|
|
155
|
+
# stderr writer, so that engine output (statistics, a verbose run's
|
|
156
|
+
# lines) still reaches stderr, as it did before and as hegel-rust's
|
|
157
|
+
# src/ffi.rs does when no sink is given. The symbol is a C function,
|
|
158
|
+
# so its resolved address is the callback value itself.
|
|
159
|
+
@hegel_output_stderr = @handle.find_function("hegel_output_stderr") or
|
|
160
|
+
raise Hegel::Error, "libhegel has no hegel_output_stderr; these bindings need libhegel #{Hegel::LIBHEGEL_VERSION}"
|
|
152
161
|
@hegel_target_fn = bind("hegel_target", [:pointer, :pointer, :double, StringStruct.by_value], :int32)
|
|
153
162
|
@hegel_event_fn = bind("hegel_event", [:pointer, :pointer, StringStruct.by_value], :int32)
|
|
154
163
|
@hegel_event_value_fn = bind(
|
|
@@ -282,14 +291,16 @@ module Hegel
|
|
|
282
291
|
)
|
|
283
292
|
|
|
284
293
|
@hegel_generate_date_fn = bind(
|
|
285
|
-
"hegel_generate_date",
|
|
294
|
+
"hegel_generate_date",
|
|
295
|
+
[:pointer, :pointer, DateStruct.by_value, DateStruct.by_value, :pointer, :pointer], :int32
|
|
286
296
|
)
|
|
287
297
|
@hegel_generate_time_fn = bind(
|
|
288
|
-
"hegel_generate_time",
|
|
298
|
+
"hegel_generate_time",
|
|
299
|
+
[:pointer, :pointer, TimeStruct.by_value, TimeStruct.by_value, :uint32, :pointer], :int32
|
|
289
300
|
)
|
|
290
301
|
@hegel_generate_datetime_fn = bind(
|
|
291
302
|
"hegel_generate_datetime",
|
|
292
|
-
[:pointer, :pointer, DatetimeStruct.by_value, DatetimeStruct.by_value, :pointer], :int32
|
|
303
|
+
[:pointer, :pointer, DatetimeStruct.by_value, DatetimeStruct.by_value, :uint32, :pointer], :int32
|
|
293
304
|
)
|
|
294
305
|
|
|
295
306
|
@hegel_grammar_builder_new_fn = bind(
|
|
@@ -520,12 +531,13 @@ module Hegel
|
|
|
520
531
|
|
|
521
532
|
# +settings+ can be freed by the caller as soon as this call returns:
|
|
522
533
|
# the header documents that hegel_run_start copies the settings it is
|
|
523
|
-
# given rather than borrowing them.
|
|
524
|
-
#
|
|
525
|
-
#
|
|
534
|
+
# given rather than borrowing them. The output callback is always
|
|
535
|
+
# hegel_output_stderr, with NULL user_data (see #initialize). A
|
|
536
|
+
# C function lives as long as the library, so it outlives the run,
|
|
537
|
+
# which the header requires of the callback.
|
|
526
538
|
def run_start(ctx, settings)
|
|
527
539
|
out = FFI::MemoryPointer.new(:pointer)
|
|
528
|
-
code = @hegel_run_start_fn.call(ctx, settings,
|
|
540
|
+
code = @hegel_run_start_fn.call(ctx, settings, @hegel_output_stderr, nil, out)
|
|
529
541
|
LibHegel.check!(self, ctx, code)
|
|
530
542
|
out.read_pointer
|
|
531
543
|
end
|
|
@@ -538,17 +550,29 @@ module Hegel
|
|
|
538
550
|
# version.
|
|
539
551
|
def run_start_blob(ctx, settings, blob)
|
|
540
552
|
out = FFI::MemoryPointer.new(:pointer)
|
|
541
|
-
code = @hegel_run_start_blob_fn.call(ctx, settings, string_view(blob),
|
|
553
|
+
code = @hegel_run_start_blob_fn.call(ctx, settings, string_view(blob), @hegel_output_stderr, nil, out)
|
|
542
554
|
LibHegel.check!(self, ctx, code)
|
|
543
555
|
out.read_pointer
|
|
544
556
|
end
|
|
545
557
|
|
|
546
|
-
# Whether the engine
|
|
547
|
-
#
|
|
548
|
-
# case
|
|
549
|
-
|
|
558
|
+
# Whether the engine will use what +tc+ prints: every case of a
|
|
559
|
+
# verbose run, and each case the engine stamps for capture, quiet
|
|
560
|
+
# runs included. A failure on such a case is material for that
|
|
561
|
+
# failure's report, and a failing one must give #mark_complete a
|
|
562
|
+
# summary. Read once, when the case starts.
|
|
563
|
+
def test_case_wants_output(ctx, tc)
|
|
564
|
+
out = FFI::MemoryPointer.new(:bool)
|
|
565
|
+
code = @hegel_test_case_wants_output_fn.call(ctx, tc, out)
|
|
566
|
+
LibHegel.check!(self, ctx, code)
|
|
567
|
+
out.read_uint8 != 0
|
|
568
|
+
end
|
|
569
|
+
|
|
570
|
+
# Whether the engine will use a failure's full diagnostic for +tc+: a
|
|
571
|
+
# failing case must then give #mark_complete a detail. True implies
|
|
572
|
+
# #test_case_wants_output. Read once, when the case starts.
|
|
573
|
+
def test_case_wants_detail(ctx, tc)
|
|
550
574
|
out = FFI::MemoryPointer.new(:bool)
|
|
551
|
-
code = @
|
|
575
|
+
code = @hegel_test_case_wants_detail_fn.call(ctx, tc, out)
|
|
552
576
|
LibHegel.check!(self, ctx, code)
|
|
553
577
|
out.read_uint8 != 0
|
|
554
578
|
end
|
|
@@ -584,12 +608,19 @@ module Hegel
|
|
|
584
608
|
nil
|
|
585
609
|
end
|
|
586
610
|
|
|
587
|
-
# +origin+ must be non-nil only when +status+
|
|
588
|
-
# HEGEL_STATUS_INTERESTING, per the header
|
|
589
|
-
#
|
|
590
|
-
#
|
|
591
|
-
|
|
592
|
-
|
|
611
|
+
# +origin+, +summary+, and +detail+ must be non-nil only when +status+
|
|
612
|
+
# is HEGEL_STATUS_INTERESTING, per the header. An INTERESTING status
|
|
613
|
+
# needs an origin always, a one-line summary when
|
|
614
|
+
# #test_case_wants_output was true, and a detail when
|
|
615
|
+
# #test_case_wants_detail was true. The engine rejects any other
|
|
616
|
+
# combination with HEGEL_E_INVALID_ARG and completes nothing. This
|
|
617
|
+
# layer neither builds nor validates those strings, only passes
|
|
618
|
+
# through what the caller supplies. nil goes over as NULL through
|
|
619
|
+
# #optional_string.
|
|
620
|
+
def mark_complete(ctx, tc, status, origin, summary: nil, detail: nil)
|
|
621
|
+
code = @hegel_mark_complete_fn.call(
|
|
622
|
+
ctx, tc, status, optional_string(origin), optional_string(summary), optional_string(detail)
|
|
623
|
+
)
|
|
593
624
|
LibHegel.check!(self, ctx, code)
|
|
594
625
|
nil
|
|
595
626
|
end
|
|
@@ -1292,15 +1323,21 @@ module Hegel
|
|
|
1292
1323
|
# the same division of labor #generate_ipv4/#generate_uuid already
|
|
1293
1324
|
# follow, returning raw values for a generator one layer up to turn
|
|
1294
1325
|
# into the caller-facing type. This layer does not validate
|
|
1295
|
-
# year/month/day itself: measured against libhegel 0.45.0,
|
|
1296
|
-
# invalid date (month 13, say) already comes back
|
|
1297
|
-
# HEGEL_E_INVALID_ARG, translated by LibHegel.check! below
|
|
1298
|
-
#
|
|
1299
|
-
#
|
|
1300
|
-
# records the same measured
|
|
1326
|
+
# year/month/day itself: measured against libhegel 0.45.0, and again
|
|
1327
|
+
# against 0.53.0, an invalid date (month 13, say) already comes back
|
|
1328
|
+
# HEGEL_E_INVALID_ARG, translated by LibHegel.check! below. The
|
|
1329
|
+
# header's Returns line for this call names HEGEL_E_INVALID_ARG only
|
|
1330
|
+
# for bounds that hold no allowed weekday and month.
|
|
1331
|
+
# #run_result_failure's own comment records the same measured
|
|
1332
|
+
# behaviour for a different call.
|
|
1333
|
+
#
|
|
1334
|
+
# Since libhegel 0.53.0 the call also takes a hegel_date_options_t
|
|
1335
|
+
# that limits the draw to some weekdays or months. This wrapper
|
|
1336
|
+
# passes NULL, which the header defines as no limit, because no
|
|
1337
|
+
# generator of this gem offers that limit yet.
|
|
1301
1338
|
def generate_date(ctx, tc, min_value, max_value)
|
|
1302
1339
|
out = DateStruct.new
|
|
1303
|
-
code = @hegel_generate_date_fn.call(ctx, tc, date_struct(min_value), date_struct(max_value), out)
|
|
1340
|
+
code = @hegel_generate_date_fn.call(ctx, tc, date_struct(min_value), date_struct(max_value), nil, out)
|
|
1304
1341
|
LibHegel.check!(self, ctx, code)
|
|
1305
1342
|
read_date(out)
|
|
1306
1343
|
end
|
|
@@ -1308,10 +1345,13 @@ module Hegel
|
|
|
1308
1345
|
# hegel_generate_time. +min_value+/+max_value+ are each an
|
|
1309
1346
|
# [hour, minute, second, nanosecond] Array; same struct-passing,
|
|
1310
1347
|
# return shape, and validation division of labor as #generate_date
|
|
1311
|
-
# above, for Hegel::Generators::TimesGenerator.
|
|
1348
|
+
# above, for Hegel::Generators::TimesGenerator. The precision is
|
|
1349
|
+
# nanoseconds; see HEGEL_PRECISION_NANOSECONDS for the reason.
|
|
1312
1350
|
def generate_time(ctx, tc, min_value, max_value)
|
|
1313
1351
|
out = TimeStruct.new
|
|
1314
|
-
code = @hegel_generate_time_fn.call(
|
|
1352
|
+
code = @hegel_generate_time_fn.call(
|
|
1353
|
+
ctx, tc, time_struct(min_value), time_struct(max_value), HEGEL_PRECISION_NANOSECONDS, out
|
|
1354
|
+
)
|
|
1315
1355
|
LibHegel.check!(self, ctx, code)
|
|
1316
1356
|
read_time(out)
|
|
1317
1357
|
end
|
|
@@ -1326,7 +1366,8 @@ module Hegel
|
|
|
1326
1366
|
def generate_datetime(ctx, tc, min_date, min_time, max_date, max_time)
|
|
1327
1367
|
out = DatetimeStruct.new
|
|
1328
1368
|
code = @hegel_generate_datetime_fn.call(
|
|
1329
|
-
ctx, tc, datetime_struct(min_date, min_time), datetime_struct(max_date, max_time),
|
|
1369
|
+
ctx, tc, datetime_struct(min_date, min_time), datetime_struct(max_date, max_time),
|
|
1370
|
+
HEGEL_PRECISION_NANOSECONDS, out
|
|
1330
1371
|
)
|
|
1331
1372
|
LibHegel.check!(self, ctx, code)
|
|
1332
1373
|
[read_date(out[:date]), read_time(out[:time])]
|
data/lib/hegel/lib_hegel.rb
CHANGED
|
@@ -104,6 +104,12 @@ module Hegel
|
|
|
104
104
|
# machine is done, and hegel_state_machine_next_rule once the round is.
|
|
105
105
|
HEGEL_STATE_MACHINE_DONE = -(2**63)
|
|
106
106
|
|
|
107
|
+
# hegel_precision_t (libhegel 0.53.0 and later): hegel_generate_time and
|
|
108
|
+
# hegel_generate_datetime draw a time of day that is a whole number of
|
|
109
|
+
# this unit. These bindings pass nanoseconds, the unit those draws used
|
|
110
|
+
# before the argument existed, so the set of values stays the same.
|
|
111
|
+
HEGEL_PRECISION_NANOSECONDS = 0
|
|
112
|
+
|
|
107
113
|
# hegel_new_collection's max_size accepts UINT64_MAX to mean "no upper
|
|
108
114
|
# bound", in the header's own words. Ruby has no fixed-width integer
|
|
109
115
|
# type to read that constant off, so it is spelled out here as the
|
|
@@ -136,7 +142,7 @@ module Hegel
|
|
|
136
142
|
generate_boolean generate_integer generate_integer_big
|
|
137
143
|
run_result run_result_free run_result_status run_result_error
|
|
138
144
|
run_result_failure_count run_result_failure failure_free failure_origin
|
|
139
|
-
failure_reproduction_blob failure_caveat run_start_blob
|
|
145
|
+
failure_reproduction_blob failure_caveat run_start_blob test_case_wants_output test_case_wants_detail
|
|
140
146
|
start_span stop_span
|
|
141
147
|
new_collection collection_more collection_reject collection_free
|
|
142
148
|
generate_float
|
|
@@ -5,5 +5,5 @@ module Hegel
|
|
|
5
5
|
# Hegel::VERSION (the gem's own release): hegel-go and hegel-typescript keep
|
|
6
6
|
# the two separate too, so bumping the pinned engine can land as its own
|
|
7
7
|
# commit without also releasing a new gem version.
|
|
8
|
-
LIBHEGEL_VERSION = "0.
|
|
8
|
+
LIBHEGEL_VERSION = "0.53.0"
|
|
9
9
|
end
|
data/lib/hegel/runner.rb
CHANGED
|
@@ -202,9 +202,7 @@ module Hegel
|
|
|
202
202
|
# Pulls test cases from +run+ until hegel_next_test_case reports none
|
|
203
203
|
# left (a nil out-parameter, not an error). Never counts iterations
|
|
204
204
|
# itself: test_cases bounds generation, not how many times shrinking
|
|
205
|
-
# and rejected cases call the body.
|
|
206
|
-
# run configured for 20 test cases whose body rejected nearly every case
|
|
207
|
-
# took 581 to 1768 iterations over 30 runs. +stats+ does its own, different counting
|
|
205
|
+
# and rejected cases call the body. +stats+ does its own, different counting
|
|
208
206
|
# -- see GenerationStats above.
|
|
209
207
|
def drive(impl, ctx, run, grammars, stats, captures, &block)
|
|
210
208
|
loop do
|
|
@@ -228,12 +226,16 @@ module Hegel
|
|
|
228
226
|
# leak -- it fails the context's release too, at the end of a run that
|
|
229
227
|
# had already gone wrong enough to raise in here.
|
|
230
228
|
#
|
|
231
|
-
# The case records its draws only when the engine
|
|
232
|
-
#
|
|
233
|
-
#
|
|
229
|
+
# The case records its draws only when the engine wants its output
|
|
230
|
+
# (hegel_test_case_wants_output): a case the engine stamps for capture,
|
|
231
|
+
# quiet runs included, and every case of a verbose run. Both flags are
|
|
232
|
+
# read in here, inside the `ensure`, so the handle is freed even when
|
|
233
|
+
# reading one raises. Yields the test case and the two flags.
|
|
234
234
|
def with_test_case(impl, ctx, tc, grammars)
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
wants_output = impl.test_case_wants_output(ctx, tc)
|
|
236
|
+
wants_detail = impl.test_case_wants_detail(ctx, tc)
|
|
237
|
+
test_case = TestCase.new(impl, ctx, tc, record: wants_output, grammars: grammars)
|
|
238
|
+
yield test_case, wants_output, wants_detail
|
|
237
239
|
ensure
|
|
238
240
|
begin
|
|
239
241
|
test_case&.free_pools
|
|
@@ -244,23 +246,66 @@ module Hegel
|
|
|
244
246
|
|
|
245
247
|
# Runs +block+ against one test-case handle, classifies the outcome,
|
|
246
248
|
# counts it into +stats+, keeps a failure in +captures+, and reports the
|
|
247
|
-
# outcome with hegel_mark_complete. Only a
|
|
248
|
-
# draws (see #with_test_case): a
|
|
249
|
-
# shows, and naming a drawn value costs a read of the
|
|
250
|
-
# which every shrink probe would otherwise pay for. A fatal
|
|
249
|
+
# outcome with hegel_mark_complete. Only a case whose output the engine
|
|
250
|
+
# wants records its draws (see #with_test_case): such a case's failure
|
|
251
|
+
# is what a report shows, and naming a drawn value costs a read of the
|
|
252
|
+
# caller's source, which every shrink probe would otherwise pay for. A fatal
|
|
251
253
|
# exception (#classify re-raises those before returning) skips the rest
|
|
252
254
|
# and still reaches #with_test_case's own `ensure`, so the handle is
|
|
253
255
|
# freed either way; its owner is this loop, not hegel_run_free (see
|
|
254
256
|
# #run_and_finish's comment above).
|
|
257
|
+
#
|
|
258
|
+
# Since libhegel 0.52, a failing case also hands the engine a one-line
|
|
259
|
+
# summary when the engine wants the case's output, and a full detail
|
|
260
|
+
# when it wants the detail. The engine rejects a failure that leaves out
|
|
261
|
+
# either one, and completes nothing. Each is built only when it is
|
|
262
|
+
# wanted, because a backtrace costs more than a shrink probe should pay.
|
|
255
263
|
def run_case(impl, ctx, tc, grammars, stats, captures, &block)
|
|
256
|
-
with_test_case(impl, ctx, tc, grammars) do |test_case|
|
|
264
|
+
with_test_case(impl, ctx, tc, grammars) do |test_case, wants_output, wants_detail|
|
|
257
265
|
status, origin, exception, entries = classify(test_case, &block)
|
|
258
266
|
stats.record(status, origin)
|
|
259
|
-
|
|
260
|
-
|
|
267
|
+
if status == LibHegel::HEGEL_STATUS_INTERESTING
|
|
268
|
+
keep_capture(captures, origin, exception, entries)
|
|
269
|
+
impl.mark_complete(ctx, tc, status, origin, summary: (summary_for(exception) if wants_output),
|
|
270
|
+
detail: (detail_for(exception) if wants_detail))
|
|
271
|
+
else
|
|
272
|
+
impl.mark_complete(ctx, tc, status, origin)
|
|
273
|
+
end
|
|
261
274
|
end
|
|
262
275
|
end
|
|
263
276
|
|
|
277
|
+
# The failure in one line, for hegel_mark_complete: the caller's own
|
|
278
|
+
# location (as #origin_for finds it), the first line of the message, and
|
|
279
|
+
# the exception class in parentheses, the order Ruby itself prints an
|
|
280
|
+
# uncaught exception in. A message of several lines is cut at its first
|
|
281
|
+
# line and followed by a space and an ellipsis, as the header asks and
|
|
282
|
+
# as hegel-rust's render_summary does. The ellipsis is an escape, so
|
|
283
|
+
# this file stays ASCII: mutineer reads source in the locale's encoding.
|
|
284
|
+
# The header rejects a summary with a newline, and a string that is not
|
|
285
|
+
# valid UTF-8, so #utf8 cleans the message first.
|
|
286
|
+
def summary_for(exception)
|
|
287
|
+
message = utf8(exception.message)
|
|
288
|
+
first, rest = message.split("\n", 2)
|
|
289
|
+
line = "#{first}#{" \u2026" unless rest.to_s.strip.empty?} (#{exception.class})".lstrip
|
|
290
|
+
location = caller_location(exception)
|
|
291
|
+
location ? "#{utf8(location.path)}:#{location.lineno}: #{line}" : line
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
# The complete diagnostic, for hegel_mark_complete: what Ruby prints for
|
|
295
|
+
# an uncaught exception, with its message, its class, and its backtrace.
|
|
296
|
+
def detail_for(exception)
|
|
297
|
+
utf8(exception.full_message(highlight: false, order: :top))
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
# +text+ as valid UTF-8, since hegel_mark_complete rejects any other
|
|
301
|
+
# string and then completes nothing. A binary string is read as UTF-8,
|
|
302
|
+
# because Ruby gives raw bytes that encoding; every other encoding is
|
|
303
|
+
# converted. Bytes that are still invalid become U+FFFD.
|
|
304
|
+
def utf8(text)
|
|
305
|
+
text = text.dup.force_encoding(Encoding::UTF_8) if text.encoding == Encoding::BINARY
|
|
306
|
+
text.encode(Encoding::UTF_8, invalid: :replace, undef: :replace).scrub
|
|
307
|
+
end
|
|
308
|
+
|
|
264
309
|
# Keeps the newest capture for each origin, except that an unstamped
|
|
265
310
|
# failure (+entries+ nil) never replaces a stamped one. The engine runs
|
|
266
311
|
# every failure it reports once more at the end of the run, stamped, so
|
|
@@ -405,11 +450,17 @@ module Hegel
|
|
|
405
450
|
# still groups failures consistently, where no origin at all would lose
|
|
406
451
|
# the failure's identity entirely.
|
|
407
452
|
def origin_for(exception)
|
|
408
|
-
|
|
409
|
-
location = locations&.find { |candidate| !infrastructure?(candidate.path) } || locations&.first
|
|
453
|
+
location = caller_location(exception)
|
|
410
454
|
location ? "Raised at #{location.path}:#{location.lineno}" : UNKNOWN_ORIGIN
|
|
411
455
|
end
|
|
412
456
|
|
|
457
|
+
# The backtrace frame #origin_for names: the first one that is the
|
|
458
|
+
# caller's own, else the first one, else nil.
|
|
459
|
+
def caller_location(exception)
|
|
460
|
+
locations = exception.backtrace_locations
|
|
461
|
+
locations&.find { |candidate| !infrastructure?(candidate.path) } || locations&.first
|
|
462
|
+
end
|
|
463
|
+
|
|
413
464
|
# True when +path+ belongs to this library, an installed gem, or Ruby's
|
|
414
465
|
# own standard library, rather than to the caller whose test #origin_for
|
|
415
466
|
# is trying to identify. Location, not framework name, is what this
|
data/lib/hegel/version.rb
CHANGED
data/sig/hegel.rbs
CHANGED
|
@@ -704,6 +704,7 @@ module Hegel
|
|
|
704
704
|
HEGEL_HC_TEST_CASES_TOO_LARGE: Integer
|
|
705
705
|
HEGEL_HC_LARGE_INITIAL_TEST_CASE: Integer
|
|
706
706
|
HEGEL_STATE_MACHINE_DONE: Integer
|
|
707
|
+
HEGEL_PRECISION_NANOSECONDS: Integer
|
|
707
708
|
HEGEL_COLLECTION_MAX_SIZE_UNBOUNDED: Integer
|
|
708
709
|
HEGEL_MAX_SIZE_DEFAULT: Integer
|
|
709
710
|
HEGEL_FLOAT64_SMALLEST_NONZERO_MAGNITUDE_UNRESTRICTED: Float
|
|
@@ -750,11 +751,12 @@ module Hegel
|
|
|
750
751
|
def settings_set_backend: (untyped ctx, untyped s, Integer backend) -> nil
|
|
751
752
|
def run_start: (untyped ctx, untyped settings) -> untyped
|
|
752
753
|
def run_start_blob: (untyped ctx, untyped settings, String blob) -> untyped
|
|
753
|
-
def
|
|
754
|
+
def test_case_wants_output: (untyped ctx, untyped tc) -> bool
|
|
755
|
+
def test_case_wants_detail: (untyped ctx, untyped tc) -> bool
|
|
754
756
|
def next_test_case: (untyped ctx, untyped run) -> untyped?
|
|
755
757
|
def run_free: (untyped ctx, untyped run) -> nil
|
|
756
758
|
def test_case_free: (untyped ctx, untyped tc) -> nil
|
|
757
|
-
def mark_complete: (untyped ctx, untyped tc, Integer status, String? origin) -> nil
|
|
759
|
+
def mark_complete: (untyped ctx, untyped tc, Integer status, String? origin, ?summary: String?, ?detail: String?) -> nil
|
|
758
760
|
def target: (untyped ctx, untyped tc, Float value, String label) -> nil
|
|
759
761
|
def event: (untyped ctx, untyped tc, String label) -> nil
|
|
760
762
|
def event_value: (untyped ctx, untyped tc, String label, Numeric value) -> nil
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hegeltest
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- meganemura
|
|
@@ -84,6 +84,7 @@ files:
|
|
|
84
84
|
- docs/adr/0035-defer-concurrent-state-machines-and-the-engine-printer.md
|
|
85
85
|
- docs/adr/0036-follow-rubys-unicode-version.md
|
|
86
86
|
- docs/adr/0037-send-a-maximum-at-the-engine-default-sentinel-as-no-bound.md
|
|
87
|
+
- docs/adr/0038-hand-the-engine-a-failure-summary-and-detail.md
|
|
87
88
|
- docs/architecture.md
|
|
88
89
|
- lib/hegel.rb
|
|
89
90
|
- lib/hegel/draw_name.rb
|