varar-minitest 0.7.0 → 0.8.1

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 +69 -14
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86febd4dfd67b8c07b54bfa9520354306f3c2286cff31c16e5cf2584e2278bac
4
- data.tar.gz: 44544826879aec62fe942aa544725ea1524df11dfe7a49d60c86c3f287a655d8
3
+ metadata.gz: 22ad2f75ce8cdd3344dfd3476214668b7a70504a5069a88f545a52ebc28b5fcf
4
+ data.tar.gz: 9b423a22bac3427ff99f03f8a00bc5ff0cbde4fb886197d55efef0b467e4e5f1
5
5
  SHA512:
6
- metadata.gz: c87fda6a6126f22d6c806b7023aa3131c7104aad42336fdc04f865aef5d19911d8a45f9afa8b81639f2cb00cb6e250ea3f688c9f093de7d0552900ebdae350fb
7
- data.tar.gz: ff74a446beea0e1c70ad6ff6e003afa30c3808d6e9bc0e4954409ab5fba3454e8e6f447dcc9d8cf7c7b9110524f6b74d9d1ff1dee2df17ccad18b48790e880ba
6
+ metadata.gz: 9e541d6817a9680027b002bcee219dea2ea60011981bc67b4d789104d8580533402f22e2285f1509c98449a9c1bf84789c73e21e4cc03507892bd66cb3cc2638
7
+ data.tar.gz: 2d29d85a17b10c820f41221f992aea51cc48b5577456abf17020afbd2782c22f5a20cc025e1ad8461d9445c632de5604eae1c5156c5d8e6e6b37e2c684cfa34c
@@ -4,36 +4,78 @@ require 'minitest'
4
4
  require 'varar/runner'
5
5
 
6
6
  module Varar
7
- # Minitest adapter. One call turns every spec matched by varar.config.json into
8
- # a generated Minitest::Test subclass — one class per spec file, one test
9
- # method per example. Mirrors var-unittest.
7
+ # Minitest adapter. One call turns every oath matched by varar.config.json into
8
+ # a generated Minitest::Test subclass — one class per oath file, one test
9
+ # method per example. Mirrors varar-unittest.
10
10
  #
11
- # # test/var_test.rb
11
+ # # test/varar_test.rb
12
12
  # require "varar/minitest"
13
13
  # Varar::Minitest.generate_tests
14
14
  module Minitest
15
- VERSION = '0.7.0'
15
+ VERSION = '0.8.1'
16
16
 
17
17
  module_function
18
18
 
19
19
  def generate_tests(namespace = Object, root: nil)
20
20
  root ||= File.dirname(caller_locations(1, 1).first.path)
21
21
  root = File.expand_path(root)
22
- cfg = Config.read_var_config(root)
22
+ cfg = Config.read_config(root)
23
23
  loaded = Runner.load_steps(cfg.steps, root)
24
24
  store = Runner.create_file_baseline_store(root)
25
25
  update = %w[1 true].include?(ENV.fetch('VARAR_UPDATE', nil))
26
26
 
27
- Runner.find_specs(cfg.docs_include, cfg.docs_exclude, root).each do |spec_path|
28
- klass = build_test_case(spec_path, root, loaded, store, update)
29
- namespace.const_set("Var_#{identifier(Runner.rel_posix(spec_path, root))}", klass)
27
+ oaths = Runner.find_oaths(cfg.docs_include, cfg.docs_exclude, root)
28
+ # Run results for the language server (ADR 0014). Minitest.after_run, not
29
+ # at_exit: at_exit handlers run last-registered-first, so ours would fire
30
+ # before Minitest's own — i.e. before a single test had run.
31
+ results = Runner::Results.new
32
+ ::Minitest.after_run { results.flush_all(root) }
33
+
34
+ # Drop baselines for oaths the config no longer discovers. Reconciliation is
35
+ # per-oath and never sees a path that has gone, so the lock would otherwise
36
+ # accumulate dead entries forever (#70). Once per run, keyed off the config
37
+ # globs — which here IS the full set, since generate_tests always discovers
38
+ # everything.
39
+ Core::Drifts.prune_baselines(store, oaths.map { |p| Runner.rel_posix(p, root) }, update: update)
40
+
41
+ workspace = project_workspace(oaths, root)
42
+
43
+ oaths.each do |oath_path|
44
+ klass = build_test_case(oath_path, root, loaded, store, update, results, workspace)
45
+ namespace.const_set("Var_#{identifier(Runner.rel_posix(oath_path, root))}", klass)
46
+ end
47
+ end
48
+
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
30
67
  end
68
+ Core::Reference.build_workspace(docs)
31
69
  end
32
70
 
33
- def build_test_case(spec_path, root, loaded, store, update)
34
- rel = Runner.rel_posix(spec_path, root)
35
- source = File.read(spec_path, encoding: 'UTF-8')
36
- plan = Runner.plan_spec(File.basename(spec_path), source, loaded.registry)
71
+ def build_test_case(oath_path, root, loaded, store, update, results, workspace)
72
+ rel = Runner.rel_posix(oath_path, root)
73
+ source = File.read(oath_path, encoding: 'UTF-8')
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)
37
79
  pairs = Runner.examples_with_runs(plan, loaded.create_context, Runner::RecordingReporter.new)
38
80
 
39
81
  klass = Class.new(::Minitest::Test)
@@ -44,16 +86,29 @@ module Varar
44
86
  idx = seen[stem]
45
87
  seen[stem] += 1
46
88
  method_name = idx.zero? ? "test_#{stem}" : "test_#{stem}_#{idx}"
89
+ # Lines in THIS oath: a step a reference block spliced in from another
90
+ # oath (ADR 0016) contributes none, since its line is not in this file.
91
+ lines = example.steps.reject(&:doc_path).map { |step| step.match_span.start_line }.uniq
47
92
  klass.define_method(method_name) do
48
93
  run.call
49
94
  rescue StandardError => e
95
+ # Recorded here, where the error object is still in hand: to_failure
96
+ # reads the anchor the executor attached to it.
97
+ results.record(rel, source, Core::ExampleResult.new(
98
+ name: example.name, status: 'failed', lines: lines,
99
+ failure: Core::Failures.to_failure(e, rel, lines.first || 0)
100
+ ), referenced)
50
101
  raise ::Minitest::Assertion, Runner.render_failure(e, source, rel) if Minitest.var_diff_error?(e)
51
102
 
52
103
  raise
104
+ else
105
+ results.record(rel, source, Core::ExampleResult.new(
106
+ name: example.name, status: 'passed', lines: lines, failure: nil
107
+ ), referenced)
53
108
  end
54
109
  end
55
110
 
56
- Core::Drifts.reconcile_drift(store, rel, source, plan.var_doc, plan, update: update).each do |drift|
111
+ Core::Drifts.reconcile_drift(store, rel, source, plan.doc, plan, update: update).each do |drift|
57
112
  message = Core::Diagnostics.drift_detected(drift.name, drift.span).message
58
113
  klass.define_method("test_var_drift_#{drift.line}") { raise ::Minitest::Assertion, message }
59
114
  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.7.0
4
+ version: 0.8.1
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.7.0
32
+ version: 0.8.1
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.7.0
39
+ version: 0.8.1
40
40
  description: 'Minitest adapter: one selectable test per Markdown example, with a drift
41
41
  gate.'
42
42
  email:
@@ -67,5 +67,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  requirements: []
68
68
  rubygems_version: 4.0.16
69
69
  specification_version: 4
70
- summary: Markdown-native BDD — run Markdown specs as Minitest tests
70
+ summary: Markdown-native BDD — run Markdown oaths as Minitest tests
71
71
  test_files: []