assert 2.3.2 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/assert CHANGED
@@ -3,5 +3,10 @@
3
3
  # Copyright (c) 2011-Present Kelly Redding and Collin Redding
4
4
  #
5
5
 
6
+ require 'assert'
6
7
  require 'assert/cli'
7
- Assert::CLI.run *ARGV
8
+
9
+ Assert.config.debug ENV['ASSERT_DEBUG'] == 'true' || Assert::CLI.debug?(ARGV)
10
+
11
+ Assert::CLI.bench('CLI init and parse'){ @cli = Assert::CLI.new(*ARGV) }
12
+ @cli.run
@@ -15,19 +15,6 @@ module Assert
15
15
  def self.config; Config; end
16
16
  def self.configure; yield Config if block_given?; end
17
17
 
18
- def self.init(test_files, opts)
19
- # load any test helper file
20
- if p = opts[:test_dir_path]
21
- helper_file = File.join(p, Config.test_helper)
22
- require helper_file if File.exists?(helper_file)
23
- end
24
-
25
- # load the test files
26
- Assert.view.fire(:before_load, test_files)
27
- test_files.each{ |p| require p }
28
- Assert.view.fire(:after_load)
29
- end
30
-
31
18
  class Config
32
19
  include Singleton
33
20
  # map any class methods to the singleton
@@ -55,17 +42,7 @@ module Assert
55
42
  @runner = Assert::Runner.new
56
43
  @test_dir = "test"
57
44
  @test_helper = "helper.rb"
58
-
59
- # use git, by default, to determine which files have changes
60
- @changed_files = proc do |test_paths|
61
- cmds = [
62
- "git diff --no-ext-diff --name-only", # changed files
63
- "git ls-files --others --exclude-standard" # added files
64
- ]
65
- cmd = cmds.map{ |c| "#{c} -- #{test_paths.join(' ')}" }.join(' && ')
66
- puts " `#{cmd}`" if Assert.config.debug
67
- `#{cmd}`.split("\n")
68
- end
45
+ @changed_files = Assert::AssertRunner::DEFAULT_CHANGED_FILES_PROC
69
46
 
70
47
  # default option values
71
48
  @runner_seed = begin; srand; srand % 0xFFFF; end.to_i
@@ -1,3 +1,5 @@
1
+ require 'assert/cli'
2
+
1
3
  module Assert
2
4
 
3
5
  class AssertRunner
@@ -5,18 +7,49 @@ module Assert
5
7
  USER_SETTINGS_FILE = ".assert/init.rb"
6
8
  LOCAL_SETTINGS_FILE = ".assert.rb"
7
9
 
8
- def initialize(test_paths, test_options)
9
- require 'assert' # inits config singleton with the default settings
10
+ DEFAULT_CHANGED_FILES_PROC = Proc.new do |test_paths|
11
+ # use git to determine which files have changes
12
+ files = []
13
+ cmd = [
14
+ "git diff --no-ext-diff --name-only", # changed files
15
+ "git ls-files --others --exclude-standard" # added files
16
+ ].map{ |c| "#{c} -- #{test_paths.join(' ')}" }.join(' && ')
10
17
 
11
- apply_user_settings
12
- apply_local_settings
13
- apply_option_settings(test_options)
14
- apply_env_settings
18
+ Assert::CLI.bench('Load only changed files') do
19
+ files = `#{cmd}`.split("\n")
20
+ end
21
+ puts Assert::CLI.debug_msg(" `#{cmd}`") if Assert.config.debug
22
+ files
23
+ end
24
+
25
+ def initialize(test_paths, test_options)
26
+ Assert::CLI.bench('Apply settings') do
27
+ apply_user_settings
28
+ apply_local_settings
29
+ apply_option_settings(test_options)
30
+ apply_env_settings
31
+ end
15
32
 
16
33
  files = test_files(test_paths.empty? ? [*Assert.config.test_dir] : test_paths)
17
- Assert.init(files, {
18
- :test_dir_path => path_of(Assert.config.test_dir, files.first)
19
- })
34
+ init(files, path_of(Assert.config.test_dir, files.first))
35
+ end
36
+
37
+ def init(test_files, test_dir)
38
+ # load any test helper file
39
+ if test_dir && (h = File.join(test_dir, Config.test_helper)) && File.exists?(h)
40
+ Assert::CLI.bench('Require test helper'){ require h }
41
+ end
42
+
43
+ # load the test files
44
+ Assert.view.fire(:before_load, test_files)
45
+ Assert::CLI.bench("Require #{test_files.count} test files") do
46
+ test_files.each{ |p| require p }
47
+ end
48
+ if Assert.config.debug
49
+ puts Assert::CLI.debug_msg("Test files:")
50
+ test_files.each{ |f| puts Assert::CLI.debug_msg(" #{f}") }
51
+ end
52
+ Assert.view.fire(:after_load)
20
53
  end
21
54
 
22
55
  def run
@@ -56,7 +89,6 @@ module Assert
56
89
  end
57
90
 
58
91
  def changed_test_files(test_paths)
59
- puts "Loading only changed files:" if Assert.config.debug
60
92
  globbed_test_files(Assert.config.changed_files.call(test_paths))
61
93
  end
62
94
 
@@ -1,3 +1,4 @@
1
+ require 'benchmark'
1
2
  require 'set'
2
3
  require 'assert/assert_runner'
3
4
  require 'assert/version'
@@ -6,11 +7,24 @@ module Assert
6
7
 
7
8
  class CLI
8
9
 
9
- def self.run(*args)
10
- self.new.run(*args)
10
+ def self.debug?(args)
11
+ args.include?('-d') || args.include?('--debug')
11
12
  end
12
13
 
13
- def initialize
14
+ def self.debug_msg(msg, time_in_ms = nil)
15
+ "[DEBUG] #{msg}#{" (#{time_in_ms} ms)" if time_in_ms}"
16
+ end
17
+
18
+ def self.bench(msg, &block)
19
+ if !Assert.config.debug
20
+ block.call; return
21
+ end
22
+ RoundedMillisecondTime.new(Benchmark.measure(&block).real).tap do |time_in_ms|
23
+ puts debug_msg(msg, time_in_ms)
24
+ end
25
+ end
26
+
27
+ def initialize(*args)
14
28
  @cli = CLIRB.new do
15
29
  option 'runner_seed', 'Use a given seed to run tests', {
16
30
  :abbrev => 's', :value => Fixnum
@@ -27,15 +41,11 @@ module Assert
27
41
  # show loaded test files, cli err backtraces, etc
28
42
  option 'debug', 'run in debug mode'
29
43
  end
44
+ @cli.parse!(args)
30
45
  end
31
46
 
32
- def run(*args)
33
- # default debug_mode to the env var
34
- debug_mode = ENV['ASSERT_DEBUG'] == 'true'
47
+ def run
35
48
  begin
36
- # parse manually in the case that parsing fails before the debug arg
37
- debug_mode ||= args.include?('-d') || args.include?('--debug')
38
- @cli.parse!(args)
39
49
  Assert::AssertRunner.new(@cli.args, @cli.opts).run
40
50
  rescue CLIRB::HelpExit
41
51
  puts help
@@ -43,7 +53,7 @@ module Assert
43
53
  puts Assert::VERSION
44
54
  rescue CLIRB::Error => exception
45
55
  puts "#{exception.message}\n\n"
46
- puts debug_mode ? exception.backtrace.join("\n") : help
56
+ puts Assert.config.debug ? exception.backtrace.join("\n") : help
47
57
  exit(1)
48
58
  rescue Exception => exception
49
59
  puts "#{exception.class}: #{exception.message}"
@@ -61,6 +71,14 @@ module Assert
61
71
 
62
72
  end
63
73
 
74
+ module RoundedMillisecondTime
75
+ ROUND_PRECISION = 3
76
+ ROUND_MODIFIER = 10 ** ROUND_PRECISION
77
+ def self.new(time_in_seconds)
78
+ (time_in_seconds * 1000 * ROUND_MODIFIER).to_i / ROUND_MODIFIER.to_f
79
+ end
80
+ end
81
+
64
82
  class CLIRB # Version 1.0.0, https://github.com/redding/cli.rb
65
83
  Error = Class.new(RuntimeError);
66
84
  HelpExit = Class.new(RuntimeError); VersionExit = Class.new(RuntimeError)
@@ -1,3 +1,3 @@
1
1
  module Assert
2
- VERSION = "2.3.2"
2
+ VERSION = "2.3.3"
3
3
  end
@@ -19,10 +19,6 @@ module Assert::View
19
19
  option 'ignore_styles', :magenta
20
20
 
21
21
  def before_load(test_files)
22
- if Assert.config.debug
23
- puts "Loading test files:"
24
- test_files.each{ |f| puts " #{f}" }
25
- end
26
22
  end
27
23
 
28
24
  def after_load
@@ -9,7 +9,7 @@ module Assert
9
9
  desc "the Assert module"
10
10
  subject { Assert }
11
11
 
12
- should have_imeths :view, :suite, :runner, :config, :configure, :init
12
+ should have_imeths :view, :suite, :runner, :config, :configure
13
13
 
14
14
  should "know its config singleton" do
15
15
  assert_same Config, subject.config
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assert
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 3
9
- - 2
10
- version: 2.3.2
9
+ - 3
10
+ version: 2.3.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-10-29 00:00:00 Z
19
+ date: 2013-11-11 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: ansi