Class: Verity::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/verity/configuration.rb

Overview

Public: Holds all user-configurable settings for a Verity test run. Access via ‘Verity.configuration` or inside a `Verity.configure` block.

Examples

Verity.configure do |c|
  c.test_globs    = ["test/**/*_test.rb"]
  c.worker_count  = :cpus
  c.reporter      = Verity::Reporters::DotsReporter.new($stdout)
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



45
46
47
# File 'lib/verity/configuration.rb', line 45

def initialize
  set_defaults!
end

Instance Attribute Details

#location_filtersObject

Public: String path for the SQLite manifest database. Use “:memory:” for an in-process database (single-worker only; cannot be used with parallel workers). Default: “verity/manifest.db” (relative to the process working directory, typically the project root).

Public: Array of glob Strings matched against the working directory to discover test files. Default: [“verity/*/_test.rb”].

Public: Integer worker count, or :cpus / “cpus” to auto-detect from Etc.nprocessors. Default: 1.

Public: Object implementing the Verity::Reporter interface that receives lifecycle callbacks. Default: ColoredDotsReporter writing to $stdout.

Public: Test dispatch order for manifest runs: :random (default; shuffled once in the coordinator) or :fingerprint (sorted). A non-nil #shuffle_seed always implies a shuffle, even if test_order is :fingerprint.

Public: Integer RNG seed for shuffled order. When nil and order is random, a seed is chosen, stored here, and printed to stderr (the number only) before workers start.

Public: Optional Array of [absolute_path, Integer line] pairs (from CLI file:line). When non-empty, only tests whose #line matches, or that have an enclosing #group opened on that file:line, are runnable.



42
43
44
# File 'lib/verity/configuration.rb', line 42

def location_filters
  @location_filters
end

#manifest_pathObject

Public: String path for the SQLite manifest database. Use “:memory:” for an in-process database (single-worker only; cannot be used with parallel workers). Default: “verity/manifest.db” (relative to the process working directory, typically the project root).

Public: Array of glob Strings matched against the working directory to discover test files. Default: [“verity/*/_test.rb”].

Public: Integer worker count, or :cpus / “cpus” to auto-detect from Etc.nprocessors. Default: 1.

Public: Object implementing the Verity::Reporter interface that receives lifecycle callbacks. Default: ColoredDotsReporter writing to $stdout.

Public: Test dispatch order for manifest runs: :random (default; shuffled once in the coordinator) or :fingerprint (sorted). A non-nil #shuffle_seed always implies a shuffle, even if test_order is :fingerprint.

Public: Integer RNG seed for shuffled order. When nil and order is random, a seed is chosen, stored here, and printed to stderr (the number only) before workers start.

Public: Optional Array of [absolute_path, Integer line] pairs (from CLI file:line). When non-empty, only tests whose #line matches, or that have an enclosing #group opened on that file:line, are runnable.



42
43
44
# File 'lib/verity/configuration.rb', line 42

def manifest_path
  @manifest_path
end

#reporterObject

Public: String path for the SQLite manifest database. Use “:memory:” for an in-process database (single-worker only; cannot be used with parallel workers). Default: “verity/manifest.db” (relative to the process working directory, typically the project root).

Public: Array of glob Strings matched against the working directory to discover test files. Default: [“verity/*/_test.rb”].

Public: Integer worker count, or :cpus / “cpus” to auto-detect from Etc.nprocessors. Default: 1.

Public: Object implementing the Verity::Reporter interface that receives lifecycle callbacks. Default: ColoredDotsReporter writing to $stdout.

Public: Test dispatch order for manifest runs: :random (default; shuffled once in the coordinator) or :fingerprint (sorted). A non-nil #shuffle_seed always implies a shuffle, even if test_order is :fingerprint.

Public: Integer RNG seed for shuffled order. When nil and order is random, a seed is chosen, stored here, and printed to stderr (the number only) before workers start.

Public: Optional Array of [absolute_path, Integer line] pairs (from CLI file:line). When non-empty, only tests whose #line matches, or that have an enclosing #group opened on that file:line, are runnable.



42
43
44
# File 'lib/verity/configuration.rb', line 42

def reporter
  @reporter
end

#shuffle_seedObject

Public: String path for the SQLite manifest database. Use “:memory:” for an in-process database (single-worker only; cannot be used with parallel workers). Default: “verity/manifest.db” (relative to the process working directory, typically the project root).

Public: Array of glob Strings matched against the working directory to discover test files. Default: [“verity/*/_test.rb”].

Public: Integer worker count, or :cpus / “cpus” to auto-detect from Etc.nprocessors. Default: 1.

Public: Object implementing the Verity::Reporter interface that receives lifecycle callbacks. Default: ColoredDotsReporter writing to $stdout.

Public: Test dispatch order for manifest runs: :random (default; shuffled once in the coordinator) or :fingerprint (sorted). A non-nil #shuffle_seed always implies a shuffle, even if test_order is :fingerprint.

Public: Integer RNG seed for shuffled order. When nil and order is random, a seed is chosen, stored here, and printed to stderr (the number only) before workers start.

Public: Optional Array of [absolute_path, Integer line] pairs (from CLI file:line). When non-empty, only tests whose #line matches, or that have an enclosing #group opened on that file:line, are runnable.



42
43
44
# File 'lib/verity/configuration.rb', line 42

def shuffle_seed
  @shuffle_seed
end

#test_globsObject

Public: String path for the SQLite manifest database. Use “:memory:” for an in-process database (single-worker only; cannot be used with parallel workers). Default: “verity/manifest.db” (relative to the process working directory, typically the project root).

Public: Array of glob Strings matched against the working directory to discover test files. Default: [“verity/*/_test.rb”].

Public: Integer worker count, or :cpus / “cpus” to auto-detect from Etc.nprocessors. Default: 1.

Public: Object implementing the Verity::Reporter interface that receives lifecycle callbacks. Default: ColoredDotsReporter writing to $stdout.

Public: Test dispatch order for manifest runs: :random (default; shuffled once in the coordinator) or :fingerprint (sorted). A non-nil #shuffle_seed always implies a shuffle, even if test_order is :fingerprint.

Public: Integer RNG seed for shuffled order. When nil and order is random, a seed is chosen, stored here, and printed to stderr (the number only) before workers start.

Public: Optional Array of [absolute_path, Integer line] pairs (from CLI file:line). When non-empty, only tests whose #line matches, or that have an enclosing #group opened on that file:line, are runnable.



42
43
44
# File 'lib/verity/configuration.rb', line 42

def test_globs
  @test_globs
end

#test_orderObject

Public: String path for the SQLite manifest database. Use “:memory:” for an in-process database (single-worker only; cannot be used with parallel workers). Default: “verity/manifest.db” (relative to the process working directory, typically the project root).

Public: Array of glob Strings matched against the working directory to discover test files. Default: [“verity/*/_test.rb”].

Public: Integer worker count, or :cpus / “cpus” to auto-detect from Etc.nprocessors. Default: 1.

Public: Object implementing the Verity::Reporter interface that receives lifecycle callbacks. Default: ColoredDotsReporter writing to $stdout.

Public: Test dispatch order for manifest runs: :random (default; shuffled once in the coordinator) or :fingerprint (sorted). A non-nil #shuffle_seed always implies a shuffle, even if test_order is :fingerprint.

Public: Integer RNG seed for shuffled order. When nil and order is random, a seed is chosen, stored here, and printed to stderr (the number only) before workers start.

Public: Optional Array of [absolute_path, Integer line] pairs (from CLI file:line). When non-empty, only tests whose #line matches, or that have an enclosing #group opened on that file:line, are runnable.



42
43
44
# File 'lib/verity/configuration.rb', line 42

def test_order
  @test_order
end

#worker_countObject

Public: String path for the SQLite manifest database. Use “:memory:” for an in-process database (single-worker only; cannot be used with parallel workers). Default: “verity/manifest.db” (relative to the process working directory, typically the project root).

Public: Array of glob Strings matched against the working directory to discover test files. Default: [“verity/*/_test.rb”].

Public: Integer worker count, or :cpus / “cpus” to auto-detect from Etc.nprocessors. Default: 1.

Public: Object implementing the Verity::Reporter interface that receives lifecycle callbacks. Default: ColoredDotsReporter writing to $stdout.

Public: Test dispatch order for manifest runs: :random (default; shuffled once in the coordinator) or :fingerprint (sorted). A non-nil #shuffle_seed always implies a shuffle, even if test_order is :fingerprint.

Public: Integer RNG seed for shuffled order. When nil and order is random, a seed is chosen, stored here, and printed to stderr (the number only) before workers start.

Public: Optional Array of [absolute_path, Integer line] pairs (from CLI file:line). When non-empty, only tests whose #line matches, or that have an enclosing #group opened on that file:line, are runnable.



42
43
44
# File 'lib/verity/configuration.rb', line 42

def worker_count
  @worker_count
end

Class Method Details

.cpus_worker_token?(value) ⇒ Boolean

Internal: Determine whether a value represents the :cpus worker token. Accepts :cpus, :cpu, “cpus”, or “cpu” (case-insensitive).

value - Symbol or String to check.

Returns true if the value is a cpus token.

Returns:

  • (Boolean)


102
103
104
105
106
107
108
109
110
111
112
# File 'lib/verity/configuration.rb', line 102

def cpus_worker_token?(value)
  case value
  when :cpus, :cpu
    true
  when String
    s = value.strip.downcase
    s == "cpus" || s == "cpu"
  else
    false
  end
end

Instance Method Details

#memory_manifest?Boolean

Public: Check whether the manifest is configured as in-memory.

Returns true when manifest_path is “:memory:”.

Returns:

  • (Boolean)


84
85
86
# File 'lib/verity/configuration.rb', line 84

def memory_manifest?
  manifest_path == ":memory:"
end

#resolved_worker_countObject

Public: Resolve worker_count to an Integer, expanding :cpus to the number of available processors.

Returns a positive Integer. Raises ArgumentError if the value cannot be resolved or is less than 1.

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/verity/configuration.rb', line 64

def resolved_worker_count
  n =
    if self.class.cpus_worker_token?(worker_count)
      [Etc.nprocessors, 1].max
    else
      begin
        Integer(worker_count)
      rescue TypeError, ArgumentError
        raise ArgumentError,
              "worker_count must be a positive Integer or :cpus / \"cpus\" (got #{worker_count.inspect})"
      end
    end
  raise ArgumentError, "worker_count must be >= 1 (got #{n})" if n < 1

  n
end

#set_defaults!Object



49
50
51
52
53
54
55
56
57
# File 'lib/verity/configuration.rb', line 49

def set_defaults!
  @manifest_path = "verity/manifest.db"
  @test_globs = ["verity/**/*_test.rb"]
  @worker_count = :cpus
  @reporter = Verity::Reporters::ColoredDotsReporter.new($stdout)
  @test_order = :random
  @shuffle_seed = nil
  @location_filters = []
end

#test_filesObject

Public: Expand test_globs into a sorted, deduplicated list of file paths.

Returns a sorted Array of String file paths.



91
92
93
# File 'lib/verity/configuration.rb', line 91

def test_files
  test_globs.flat_map { |pattern| Dir.glob(pattern) }.uniq.sort
end