varar-minitest 0.8.0 → 0.9.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/varar/minitest.rb +44 -10
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3efbcbfd36df2c90f60ffa46998eee770edaaa0f8f4c3bd9d3e7945d0f1fe2cc
4
- data.tar.gz: dea249b92407d04efd214b791ff168c9c1f59e47ba7e432b1b58b3b13be82f3d
3
+ metadata.gz: 1fcf220dd813224315d12f1014af95780aff0507c1e38decb77b8a0a944dbf60
4
+ data.tar.gz: 3aa4d61f25c245784041edc99df6058d6c710dc4b0970b74db438b42a5f74f65
5
5
  SHA512:
6
- metadata.gz: 2dbc0ea03c80f67829c11466ec6fc415eb73d219c91150546af6551e41be4884c053136e8cd87a9e9ef3e0ebd2d05b4156db8d544f0ff31e54149c605e748b77
7
- data.tar.gz: 64f55291af751ba14c63336741fbff527d3e1c0e0275b6bc1d704e81afdc0036a5a1cadc7bdeacd614847def226f7445c90f01e404407eb169ee365c278495d9
6
+ metadata.gz: e958f0dee52a659bebc1d0edfa9fddac087f315ec2f844b8af90fe9638f460061196a77739352901f13066d734d11b42a5a6209a6e99caed5693cb07bf65cdaf
7
+ data.tar.gz: 47ac4646ba685aa38b61cfbdf415c905d587f15382526bd5b11c0c4ab4826b2196405c62fca849e945191708ddb404ff91b64d7780648a3df4da05cc52d5cf8b
@@ -12,7 +12,7 @@ module Varar
12
12
  # require "varar/minitest"
13
13
  # Varar::Minitest.generate_tests
14
14
  module Minitest
15
- VERSION = '0.8.0'
15
+ VERSION = '0.9.0'
16
16
 
17
17
  module_function
18
18
 
@@ -38,27 +38,58 @@ module Varar
38
38
  # everything.
39
39
  Core::Drifts.prune_baselines(store, oaths.map { |p| Runner.rel_posix(p, root) }, update: update)
40
40
 
41
+ workspace = project_workspace(oaths, root)
42
+
41
43
  oaths.each do |oath_path|
42
- klass = build_test_case(oath_path, root, loaded, store, update, results)
44
+ klass = build_test_case(oath_path, root, loaded, store, update, results, workspace)
43
45
  namespace.const_set("Var_#{identifier(Runner.rel_posix(oath_path, root))}", klass)
44
46
  end
45
47
  end
46
48
 
47
- def build_test_case(oath_path, root, loaded, store, update, results)
49
+ # Whether a section is a standalone example depends on whether another oath
50
+ # references it, which is whole-project knowledge (ADR 0016). Built from the
51
+ # config globs — the full set, for the same reason baseline pruning is.
52
+ # The sources of every oath this plan's steps were spliced in from (ADR
53
+ # 0016). Their hashes go in the run record, so a consumer can tell a stale
54
+ # failure from a live one.
55
+ def referenced_sources(plan, workspace)
56
+ plan.examples.flat_map { |ex| ex.steps.map(&:doc_path) }.compact.uniq.each_with_object({}) do |path, out|
57
+ doc = workspace.docs[path]
58
+ out[path] = doc.source if doc
59
+ end
60
+ end
61
+
62
+ def project_workspace(oaths, root)
63
+ docs = oaths.filter_map do |path|
64
+ Core::Parse.parse(Runner.rel_posix(path, root), File.read(path, encoding: 'UTF-8'))
65
+ rescue SystemCallError
66
+ nil
67
+ end
68
+ Core::Reference.build_workspace(docs)
69
+ end
70
+
71
+ def build_test_case(oath_path, root, loaded, store, update, results, workspace)
48
72
  rel = Runner.rel_posix(oath_path, root)
49
73
  source = File.read(oath_path, encoding: 'UTF-8')
50
- plan = Runner.plan_oath(File.basename(oath_path), source, loaded.registry)
74
+ # `rel`, not the basename: doc.path is an oath's identity in every port,
75
+ # so a relative reference resolves alike and two same-named oaths in
76
+ # different directories stay distinct (ADR 0016).
77
+ plan = Runner.plan_oath(rel, source, loaded.registry, workspace)
78
+ referenced = referenced_sources(plan, workspace)
51
79
  pairs = Runner.examples_with_runs(plan, loaded.create_context, Runner::RecordingReporter.new)
52
80
 
53
81
  klass = Class.new(::Minitest::Test)
54
82
  seen = Hash.new(0)
55
83
  pairs.each do |example, run|
56
- base = example.scope_stack.last || example.name
57
- stem = identifier(base)
84
+ # The example's name (ADR 0017) — unique within the oath, but two names
85
+ # can still collapse to one identifier, so number those.
86
+ stem = identifier(example.name)
58
87
  idx = seen[stem]
59
88
  seen[stem] += 1
60
89
  method_name = idx.zero? ? "test_#{stem}" : "test_#{stem}_#{idx}"
61
- lines = example.steps.map { |step| step.match_span.start_line }.uniq
90
+ # Lines in THIS oath: a step a reference block spliced in from another
91
+ # oath (ADR 0016) contributes none, since its line is not in this file.
92
+ lines = example.steps.reject(&:doc_path).map { |step| step.match_span.start_line }.uniq
62
93
  klass.define_method(method_name) do
63
94
  run.call
64
95
  rescue StandardError => e
@@ -67,18 +98,21 @@ module Varar
67
98
  results.record(rel, source, Core::ExampleResult.new(
68
99
  name: example.name, status: 'failed', lines: lines,
69
100
  failure: Core::Failures.to_failure(e, rel, lines.first || 0)
70
- ))
101
+ ), referenced)
71
102
  raise ::Minitest::Assertion, Runner.render_failure(e, source, rel) if Minitest.var_diff_error?(e)
72
103
 
73
104
  raise
74
105
  else
75
106
  results.record(rel, source, Core::ExampleResult.new(
76
107
  name: example.name, status: 'passed', lines: lines, failure: nil
77
- ))
108
+ ), referenced)
78
109
  end
79
110
  end
80
111
 
81
- Core::Drifts.reconcile_drift(store, rel, source, plan.doc, plan, update: update).each do |drift|
112
+ # A paragraph that became an example (#120) is named on stderr when the
113
+ # baseline is rewritten — a notice, never a failure.
114
+ notify = ->(line) { $stderr.write("#{line}\n") }
115
+ Core::Drifts.reconcile_drift(store, rel, plan.doc, plan, update: update, notify: notify).each do |drift|
82
116
  message = Core::Diagnostics.drift_detected(drift.name, drift.span).message
83
117
  klass.define_method("test_var_drift_#{drift.line}") { raise ::Minitest::Assertion, message }
84
118
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: varar-minitest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aslak Hellesøy
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - '='
31
31
  - !ruby/object:Gem::Version
32
- version: 0.8.0
32
+ version: 0.9.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 0.8.0
39
+ version: 0.9.0
40
40
  description: 'Minitest adapter: one selectable test per Markdown example, with a drift
41
41
  gate.'
42
42
  email:
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  requirements: []
68
- rubygems_version: 4.0.16
68
+ rubygems_version: 4.0.20
69
69
  specification_version: 4
70
70
  summary: Markdown-native BDD — run Markdown oaths as Minitest tests
71
71
  test_files: []