padded_cell 0.4.0 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c460bc9c30d1aceca5e6e4dd764503b7871971c2da3c8aaa7e497581717f92f
4
- data.tar.gz: f72d0d43ff6ba9fe4505bc2c1293fefc073c89c905b0ae8fa4f8fb27784d597d
3
+ metadata.gz: 65b36985fd4aeb5bce28e8f3598aaedf6a2b426299bba5efe878fb29d73e7076
4
+ data.tar.gz: 621ee3f6059b676e22d5cd556ec175d4726eb0bef36e4a88a64984a021f18530
5
5
  SHA512:
6
- metadata.gz: c72c3a035714f8c70cb2a93461cde0c447e2417f954af98e23dc689e3b375bda3bd1132527fe0110b2e964ac33c45999e975146d214f7e71230e96e2eb383818
7
- data.tar.gz: fb6a39de58a92cf0abb8fc3bedfb8f8d72fa3fa14179508e27d416c259e77c73fda818daee6d06ea7f83f95b72432776c1a63a8ba0d692cbb82df73454e28371
6
+ metadata.gz: 7aeb2739c07b7fd60a28c316c44aef13647eb96f51b77ff712d0ccbabb9690ed0d909811767f7071ae22abab6ccd8ddccd7e75c2b174d1493fd8cbeb2c1cbbc1
7
+ data.tar.gz: 6b4f4eabc20224e2f12dd6bb5824a21473b222ecf304297c2bd1d38fd873b8f10818c144742a4f875b4085d0fe7442663f85cbd629090d493575368422d8cdbb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.0](https://github.com/seuros/padded_cell/compare/v0.4.0...v0.5.0) (2026-11-27)
4
+
5
+
6
+ ### Features
7
+
8
+ * honor Minitest 6.1's abstract_test_case! ([387ae4f](https://github.com/seuros/padded_cell/commit/387ae4f63d5816caed779fc6dcf667942683c4af))
9
+ * refuse to run after minitest/autorun installed its at_exit ([bd3e81d](https://github.com/seuros/padded_cell/commit/bd3e81d40940fe791f086601e69d1c0f4a7c57e9))
10
+
3
11
  ## 0.4.0 (2026-11-08)
4
12
 
5
13
  - `PADDED_CELL_ASYLUM`: retries failures from the environment. N retries,
data/Cargo.lock CHANGED
@@ -226,7 +226,7 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
226
226
 
227
227
  [[package]]
228
228
  name = "padded_cell"
229
- version = "0.4.0"
229
+ version = "0.5.0"
230
230
  dependencies = [
231
231
  "ruby-prism",
232
232
  "supervisor-machines",
@@ -236,7 +236,7 @@ dependencies = [
236
236
 
237
237
  [[package]]
238
238
  name = "padded_cell_native"
239
- version = "0.4.0"
239
+ version = "0.5.0"
240
240
  dependencies = [
241
241
  "deadline-machines",
242
242
  "magnus",
data/README.md CHANGED
@@ -42,7 +42,7 @@ down. The other 44 never noticed.
42
42
 
43
43
  ## Installation
44
44
 
45
- Requires CRuby 4.0 or newer and Minitest 6, on Linux, macOS or FreeBSD.
45
+ Requires CRuby 4.0 or newer and Minitest 6.1+, on Linux, macOS or FreeBSD.
46
46
  padded_cell is built on `fork`: Windows, JRuby and TruffleRuby are not
47
47
  supported.
48
48
 
@@ -104,6 +104,12 @@ errors, 3 when only coverage is below a threshold, 130 when interrupted.
104
104
  Loaded tests are the source of truth: inherited, `define_method` and other
105
105
  dynamic tests run even though static discovery cannot see them.
106
106
 
107
+ Minitest 6.1's `abstract_test_case!` is honored: a base class that calls it
108
+ runs its tests only in its subclasses, wherever it is defined (support files
109
+ included). padded_cell reads the call from the class body, so it has to be a
110
+ plain `abstract_test_case!` statement there, not one made from a block, a
111
+ method, an included module or for another class.
112
+
107
113
  ### Isolation
108
114
 
109
115
  `--isolation test` forks a cell per test. Forking a preloaded process is
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "padded_cell"
3
- version = "0.4.0"
3
+ version = "0.5.0"
4
4
  description = "Static Minitest discovery and test scheduling for the padded_cell gem"
5
5
  publish = false
6
6
  edition.workspace = true
@@ -107,3 +107,49 @@ fn discover_files_reports_the_first_unreadable_file() {
107
107
  fn ids_of(discovery: &Discovery) -> Vec<String> {
108
108
  discovery.iter().map(|test| test.id()).collect()
109
109
  }
110
+
111
+ #[test]
112
+ fn abstract_test_cases_run_none_of_their_own_tests() {
113
+ let source = concat!(
114
+ "class ShapeTest < Minitest::Test\n",
115
+ " abstract_test_case!\n",
116
+ " def test_area; end\n",
117
+ "end\n",
118
+ "module Shapes\n",
119
+ " class SquareTest < ShapeTest\n def test_side; end\n end\n",
120
+ " class BaseTest < ActiveSupport::TestCase\n",
121
+ " test 'shared' do; end\n",
122
+ " abstract_test_case!(self)\n",
123
+ " end\n",
124
+ "end\n",
125
+ );
126
+ let found = discover(source.as_bytes());
127
+ assert_eq!(ids_of(&found), ["Shapes::SquareTest#test_side"]);
128
+ assert_eq!(found.abstract_classes(), ["ShapeTest", "Shapes::BaseTest"]);
129
+ }
130
+
131
+ #[test]
132
+ fn only_a_bare_statement_of_the_class_body_declares_it_abstract() {
133
+ let bodies = [
134
+ "def self.x = abstract_test_case!",
135
+ "included { abstract_test_case! }",
136
+ "abstract_test_case!(Other)",
137
+ "self.abstract_test_case!",
138
+ "class Inner\n abstract_test_case!\n end",
139
+ ];
140
+ for body in bodies {
141
+ let source = format!("class ATest < Minitest::Test\n {body}\n def test_a; end\nend");
142
+ let found = discover(source.as_bytes());
143
+ assert_eq!(ids_of(&found), ["ATest#test_a"], "source: {source:?}");
144
+ assert_eq!(found.abstract_classes(), [] as [&str; 0], "source: {source:?}");
145
+ }
146
+ }
147
+
148
+ #[test]
149
+ fn abstract_classes_need_a_known_name_and_a_test_superclass() {
150
+ let source = concat!(
151
+ "class Helper < Object\n abstract_test_case!\nend\n",
152
+ "class foo::DynamicTest < Minitest::Test\n abstract_test_case!\nend\n",
153
+ );
154
+ assert_eq!(discover(source.as_bytes()).abstract_classes(), [] as [&str; 0]);
155
+ }
@@ -3,14 +3,17 @@
3
3
  //! A test class is a class whose superclass constant ends in `Test` or
4
4
  //! `TestCase` (`Minitest::Test`, `ActiveSupport::TestCase`, an app's own
5
5
  //! `BaseTest`...). Its tests are `def test_*` methods and Rails'
6
- //! `test "name"` declarations. Nothing is evaluated.
6
+ //! `test "name"` declarations. A class that calls `abstract_test_case!`
7
+ //! in its body (Minitest 6.1+) runs none of its own tests: it is listed in
8
+ //! [`Discovery::abstract_classes`] instead. Nothing is evaluated.
7
9
 
8
10
  use std::iter::FusedIterator;
9
11
  use std::path::Path;
10
12
  use std::slice;
11
13
 
12
14
  use ruby_prism::{
13
- CallNode, ClassNode, DefNode, Location, ModuleNode, Node, SingletonClassNode, Visit,
15
+ CallNode, ClassNode, DefNode, Location, ModuleNode, Node, SingletonClassNode, StatementsNode,
16
+ Visit,
14
17
  };
15
18
 
16
19
  use crate::FileError;
@@ -25,6 +28,7 @@ mod tests;
25
28
  pub struct Discovery {
26
29
  classes: Vec<String>,
27
30
  tests: Vec<Entry>,
31
+ abstract_classes: Vec<String>,
28
32
  }
29
33
 
30
34
  #[derive(Debug, Clone, PartialEq, Eq)]
@@ -65,6 +69,13 @@ impl Discovery {
65
69
  &self.classes
66
70
  }
67
71
 
72
+ /// Names of the test classes declared `abstract_test_case!`, in order of
73
+ /// appearance. Their own tests are not in [`Discovery::iter`].
74
+ #[must_use]
75
+ pub fn abstract_classes(&self) -> &[String] {
76
+ &self.abstract_classes
77
+ }
78
+
68
79
  /// Number of tests.
69
80
  #[must_use]
70
81
  pub const fn len(&self) -> usize {
@@ -226,17 +237,28 @@ impl<'pr> Visitor<'pr> {
226
237
  scope_start: 0,
227
238
  dynamic: false,
228
239
  test_class: TestClass::Outside,
229
- discovery: Discovery { classes: Vec::new(), tests: Vec::new() },
240
+ discovery: Discovery {
241
+ classes: Vec::new(),
242
+ tests: Vec::new(),
243
+ abstract_classes: Vec::new(),
244
+ },
230
245
  }
231
246
  }
232
247
 
233
- fn within(&mut self, path: &Node<'pr>, test: bool, visit: impl FnOnce(&mut Self)) {
248
+ fn within(&mut self, path: &Node<'pr>, kind: Kind, visit: impl FnOnce(&mut Self)) {
234
249
  let (depth, scope_start, dynamic, test_class) =
235
250
  (self.scope.len(), self.scope_start, self.dynamic, self.test_class);
236
251
  let constant = self.push_constant(path).is_some();
237
252
  self.dynamic |= !constant;
238
- self.test_class =
239
- if test && !self.dynamic { TestClass::Pending } else { TestClass::Outside };
253
+ self.test_class = match kind {
254
+ Kind::Test if !self.dynamic => TestClass::Pending,
255
+ Kind::Abstract if !self.dynamic => {
256
+ let name = self.class_name();
257
+ self.discovery.abstract_classes.push(name);
258
+ TestClass::Outside
259
+ }
260
+ _ => TestClass::Outside,
261
+ };
240
262
  visit(self);
241
263
  self.scope.truncate(depth);
242
264
  (self.scope_start, self.dynamic, self.test_class) = (scope_start, dynamic, test_class);
@@ -255,8 +277,15 @@ impl<'pr> Visitor<'pr> {
255
277
  Some(())
256
278
  }
257
279
 
258
- /// Stores the current namespace as a class name, joined once.
280
+ /// Stores the current namespace as a class name.
259
281
  fn add_class(&mut self) -> usize {
282
+ let class = self.class_name();
283
+ self.discovery.classes.push(class);
284
+ self.discovery.classes.len() - 1
285
+ }
286
+
287
+ /// The current namespace, joined once.
288
+ fn class_name(&self) -> String {
260
289
  let names = &self.scope[self.scope_start..];
261
290
  let length =
262
291
  names.iter().map(|name| name.len()).sum::<usize>() + 2 * names.len().saturating_sub(1);
@@ -267,8 +296,7 @@ impl<'pr> Visitor<'pr> {
267
296
  }
268
297
  class.push_str(name);
269
298
  }
270
- self.discovery.classes.push(class);
271
- self.discovery.classes.len() - 1
299
+ class
272
300
  }
273
301
 
274
302
  const fn in_test_class(&self) -> bool {
@@ -297,14 +325,24 @@ impl<'pr> Visitor<'pr> {
297
325
 
298
326
  impl<'pr> Visit<'pr> for Visitor<'pr> {
299
327
  fn visit_module_node(&mut self, node: &ModuleNode<'pr>) {
300
- self.within(&node.constant_path(), false, |visitor| {
328
+ self.within(&node.constant_path(), Kind::Plain, |visitor| {
301
329
  ruby_prism::visit_module_node(visitor, node);
302
330
  });
303
331
  }
304
332
 
305
333
  fn visit_class_node(&mut self, node: &ClassNode<'pr>) {
306
- let test = node.superclass().is_some_and(|superclass| test_superclass(&superclass));
307
- self.within(&node.constant_path(), test, |visitor| {
334
+ let kind = if !node.superclass().is_some_and(|superclass| test_superclass(&superclass)) {
335
+ Kind::Plain
336
+ } else if node
337
+ .body()
338
+ .and_then(|body| body.as_statements_node())
339
+ .is_some_and(|body| abstract_body(&body))
340
+ {
341
+ Kind::Abstract
342
+ } else {
343
+ Kind::Test
344
+ };
345
+ self.within(&node.constant_path(), kind, |visitor| {
308
346
  ruby_prism::visit_class_node(visitor, node);
309
347
  });
310
348
  }
@@ -340,6 +378,36 @@ impl<'pr> Visit<'pr> for Visitor<'pr> {
340
378
  }
341
379
  }
342
380
 
381
+ /// What a namespace being entered is.
382
+ #[derive(Debug, Clone, Copy)]
383
+ enum Kind {
384
+ /// A module, or a class that is not a test class.
385
+ Plain,
386
+ /// A test class.
387
+ Test,
388
+ /// A test class declared `abstract_test_case!`: its tests run only in
389
+ /// its subclasses.
390
+ Abstract,
391
+ }
392
+
393
+ /// Whether a class body calls `abstract_test_case!` (or
394
+ /// `abstract_test_case!(self)`) as one of its own statements. A call inside
395
+ /// a block or a method may run for another class, or never.
396
+ fn abstract_body(body: &StatementsNode<'_>) -> bool {
397
+ body.body().iter().any(|statement| {
398
+ statement.as_call_node().is_some_and(|call| {
399
+ call.receiver().is_none()
400
+ && call.block().is_none()
401
+ && call.name().as_slice() == b"abstract_test_case!"
402
+ && call.arguments().is_none_or(|arguments| {
403
+ let arguments = arguments.arguments();
404
+ arguments.len() == 1
405
+ && arguments.iter().all(|argument| argument.as_self_node().is_some())
406
+ })
407
+ })
408
+ })
409
+ }
410
+
343
411
  /// Whether a superclass is a constant path ending in `Test` or `TestCase`.
344
412
  fn test_superclass(node: &Node<'_>) -> bool {
345
413
  constant_tail(node).is_some_and(|name| name.ends_with("Test") || name.ends_with("TestCase"))
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "padded_cell_native"
3
- version = "0.4.0"
3
+ version = "0.5.0"
4
4
  description = "Ruby bindings for the padded_cell crate"
5
5
  publish = false
6
6
  edition.workspace = true
@@ -86,13 +86,17 @@ fn discover(ruby: &Ruby, source: RString) -> Result<RArray, Error> {
86
86
 
87
87
  /// Reads and parses on scoped threads: none is left running when Ruby forks
88
88
  /// next.
89
- fn discover_files(ruby: &Ruby, paths: RArray) -> Result<RArray, Error> {
90
- let found = with_bytes(&strings(paths)?, |paths| {
89
+ fn discoveries(ruby: &Ruby, paths: RArray) -> Result<Vec<Discovery>, Error> {
90
+ with_bytes(&strings(paths)?, |paths| {
91
91
  let paths: Vec<&Path> =
92
92
  paths.iter().map(|path| Path::new(OsStr::from_bytes(path))).collect();
93
93
  padded_cell::discover_files(&paths)
94
94
  })
95
- .map_err(|error| file_error(ruby, &error))?;
95
+ .map_err(|error| file_error(ruby, &error))
96
+ }
97
+
98
+ fn discover_files(ruby: &Ruby, paths: RArray) -> Result<RArray, Error> {
99
+ let found = discoveries(ruby, paths)?;
96
100
  let files = ruby.ary_new_capa(found.len());
97
101
  for discovery in &found {
98
102
  files.push(rows(ruby, discovery)?)?;
@@ -100,6 +104,13 @@ fn discover_files(ruby: &Ruby, paths: RArray) -> Result<RArray, Error> {
100
104
  Ok(files)
101
105
  }
102
106
 
107
+ /// Names of the classes declared `abstract_test_case!` in the files, in file
108
+ /// order: the runner drops their own tests after loading.
109
+ fn abstract_classes(ruby: &Ruby, paths: RArray) -> Result<Vec<String>, Error> {
110
+ let found = discoveries(ruby, paths)?;
111
+ Ok(found.iter().flat_map(|discovery| discovery.abstract_classes().iter().cloned()).collect())
112
+ }
113
+
103
114
  fn plan(
104
115
  classes: RArray,
105
116
  durations: Vec<f64>,
@@ -118,6 +129,7 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
118
129
  module.define_module_function("version", function!(version, 0))?;
119
130
  module.define_module_function("discover", function!(discover, 1))?;
120
131
  module.define_module_function("discover_files", function!(discover_files, 1))?;
132
+ module.define_module_function("abstract_classes", function!(abstract_classes, 1))?;
121
133
  module.define_module_function("plan", function!(plan, 5))?;
122
134
  module.define_module_function("chart_report", function!(chart::chart_report, 3))?;
123
135
  limits::define(ruby, module)?;
@@ -20,5 +20,8 @@ module PaddedCell
20
20
  def source(source, file: '(source)') = refs(PaddedCellNative.discover(source), file)
21
21
 
22
22
  def refs(rows, file) = rows.map { TestRef.new(file, *it) }
23
+
24
+ # Names of the classes declared `abstract_test_case!` in files.
25
+ def abstract_classes(files) = PaddedCellNative.abstract_classes(files)
23
26
  end
24
27
  end
@@ -16,6 +16,12 @@ module PaddedCell
16
16
  module_function
17
17
 
18
18
  def call(files, seed:)
19
+ # An at_exit cannot be taken back: refuse rather than run twice.
20
+ if Minitest.installed_at_exit?
21
+ raise LoadFailure, 'minitest/autorun was required before padded_cell loaded the suite: its at_exit ' \
22
+ 'would run every test again, unisolated. Drop it from RUBYOPT, or require ' \
23
+ "'minitest' instead where it runs before padded_cell"
24
+ end
19
25
  Minitest.singleton_class.prepend(NoAutorun)
20
26
  Minitest.seed = seed
21
27
  # What `rake test` and `rails test` put on the load path.
@@ -34,12 +40,24 @@ module PaddedCell
34
40
 
35
41
  # [klass, method_name] for every loaded test, the way Minitest finds them.
36
42
  def tests
37
- Minitest::Runnable.runnables.flat_map do |klass|
43
+ runnables = Minitest::Runnable.runnables
44
+ abstract = abstract_classes(runnables)
45
+ runnables.flat_map do |klass|
46
+ next [] if abstract.include?(klass.name)
47
+
38
48
  klass.runnable_methods.map { [klass, it] }
39
49
  rescue NotImplementedError
40
50
  []
41
51
  end
42
52
  end
53
+
54
+ # Minitest's abstract_test_case! guards the class-level run, which cells
55
+ # never call: the declaration is read from the files the classes were
56
+ # defined in instead, test helpers and support files included.
57
+ def abstract_classes(runnables)
58
+ files = runnables.filter_map { (name = it.name) && Object.const_source_location(name)&.first }
59
+ Discovery.abstract_classes(files.uniq.select { File.file?(it) }).to_set
60
+ end
43
61
  end
44
62
 
45
63
  # Which loaded tests run: Minitest's --include/--exclude, plus file:line.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaddedCell
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padded_cell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '6.0'
18
+ version: '6.1'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '6.0'
25
+ version: '6.1'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rb_sys
28
28
  requirement: !ruby/object:Gem::Requirement