ftest 0.1.1 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b936435d56deda1792974d6e8a9b7e6e3268925
4
- data.tar.gz: a3d68f8cfc0e04898d8383c93fe27c781c6a9deb
3
+ metadata.gz: c74881d078896ac38442c877ecca6dbdad5d739f
4
+ data.tar.gz: 2e7146641d9f0bfefd920e0edb2fb5e2656747a5
5
5
  SHA512:
6
- metadata.gz: 023ffd02a8feee884bb483284d68f149febb8c4da6612878b6deb6c5a83f824ce500b906ae031f90073d137b3727e228f2c4896561ee5dbb9acf965b4c13c59c
7
- data.tar.gz: 94fb9e42376f7c2fecca5bc7efc87de17f0e7acdf03ff8a5b0130997e7f4385cc6f097b7e951a1ef58ae74b35033948bd59a2b8814faa6998cc1b0b96db7540b
6
+ metadata.gz: 33b69d60643c7622583be04bbbf308b8b49b97e0d7ddfb28dacc535b380d3af6862e0745e000f96e628efd0aac1668974afc184cc19bfd9de4b2bbfcdc8eaa1d
7
+ data.tar.gz: 7099432413a94b4b85f12ded3ce90a5fc0dd3f4834928d729d38399b6342ecb0c9c9f57900b4ab05778beae8c11d2bf5b614406be7930c9e41bfa7e4c866f760
@@ -2,6 +2,7 @@ require "logger"
2
2
 
3
3
  module FTest
4
4
  autoload :Assert, "ftest/assert"
5
+ autoload :BacktraceFilter, "ftest/backtrace_filter"
5
6
  autoload :ColoredLogger, "ftest/colored_logger"
6
7
  autoload :Config, "ftest/config"
7
8
  autoload :CLI, "ftest/cli"
@@ -15,10 +16,18 @@ module FTest
15
16
  #
16
17
  # logger.info "hi"
17
18
  # assert true
19
+ #
20
+ # You can also require "ftest/script" to automatically include FTest
18
21
  def logger
19
22
  Config.logger
20
23
  end
21
24
 
25
+ # Describe can help break up a larger test script into chunks. Blocks are run
26
+ # immediately; this is a pure cosmetic enhancement.
27
+ def describe msg
28
+ yield
29
+ end
30
+
22
31
  def self.included target
23
32
  Assert::Syntax.infect target
24
33
  end
@@ -6,32 +6,10 @@ require_relative "assert/syntax"
6
6
 
7
7
  module FTest
8
8
  module Assert
9
- extend self
10
-
11
- def inspect object, truncate = 100
9
+ def self.inspect object, truncate = 100
12
10
  raw = object.inspect
13
11
  return raw if raw.size <= truncate
14
12
  "#{raw[0..truncate - 2]} …\""
15
13
  end
16
-
17
- def filter_trace trace
18
- return trace unless Config.trim_backtrace
19
-
20
- entry_point = trace.last
21
- ftest_root = File.expand_path "../..", __FILE__
22
-
23
- first_pass = trace.drop_while do |location|
24
- full_path = File.expand_path location.path
25
- full_path.start_with? ftest_root
26
- end
27
-
28
- second_pass = first_pass.take_while do |location|
29
- full_path = File.expand_path location.path
30
- not full_path.start_with? ftest_root
31
- end
32
-
33
- second_pass << entry_point unless second_pass.last == entry_point
34
- second_pass
35
- end
36
14
  end
37
15
  end
@@ -78,7 +78,7 @@ module FTest
78
78
  end
79
79
 
80
80
  def trace
81
- Assert.filter_trace @trace
81
+ BacktraceFilter.(@trace)
82
82
  end
83
83
 
84
84
  class Refutation < Assertion
@@ -0,0 +1,25 @@
1
+ module FTest
2
+ module BacktraceFilter
3
+ extend self
4
+
5
+ def call trace
6
+ return trace unless Config.trim_backtraces
7
+
8
+ entry_point = trace.last
9
+ ftest_root = File.expand_path "../..", __FILE__
10
+
11
+ first_pass = trace.drop_while do |location|
12
+ full_path = File.expand_path location.to_s
13
+ full_path.start_with? ftest_root
14
+ end
15
+
16
+ second_pass = first_pass.take_while do |location|
17
+ full_path = File.expand_path location.to_s
18
+ not full_path.start_with? ftest_root
19
+ end
20
+
21
+ second_pass << entry_point unless second_pass.last == entry_point
22
+ second_pass
23
+ end
24
+ end
25
+ end
@@ -25,8 +25,8 @@ module FTest
25
25
  Config.child_count = options.child_count
26
26
  Config.fail_fast = options.fail_fast?
27
27
  Config.logger = build_logger
28
- Config.reverse_stack_traces = options.reverse_stack_traces?
29
- Config.trim_backtrace = !options.full_backtrace?
28
+ Config.reverse_backtraces = options.reverse_backtraces?
29
+ Config.trim_backtraces = options.trim_backtraces?
30
30
  end
31
31
 
32
32
  def build_logger
@@ -54,7 +54,6 @@ module FTest
54
54
  def initialize
55
55
  @paths = []
56
56
  @log_level = Logger::WARN
57
- @child_count = 2
58
57
  end
59
58
 
60
59
  def add_path path
@@ -85,20 +84,21 @@ module FTest
85
84
  @full_backtrace = !@full_backtrace
86
85
  end
87
86
 
88
- def full_backtrace?
89
- @full_backtrace
87
+ def trim_backtraces?
88
+ return nil if @full_backtrace.nil?
89
+ not @full_backtrace
90
90
  end
91
91
 
92
92
  def quiet
93
93
  @log_level += 1
94
94
  end
95
95
 
96
- def reverse_stack_traces
97
- @reverse_stack_traces = !@reverse_stack_traces
96
+ def reverse_backtraces
97
+ @reverse_backtraces = !@reverse_backtraces
98
98
  end
99
99
 
100
- def reverse_stack_traces?
101
- @reverse_stack_traces
100
+ def reverse_backtraces?
101
+ @reverse_backtraces
102
102
  end
103
103
 
104
104
  def verbose
@@ -156,7 +156,7 @@ If no PATH is specified, ./tests is assumed
156
156
  @options.quiet
157
157
  end
158
158
  opts.on "-r", "--reverse-traces", "Reverse the order of stack traces" do
159
- @options.reverse_stack_traces
159
+ @options.reverse_backtraces
160
160
  end
161
161
  opts.on "-v", "--verbose", "Increases log verbosity" do
162
162
  @options.verbose
@@ -25,7 +25,8 @@ module FTest
25
25
  end
26
26
 
27
27
  %i(unknown fatal error warn info debug).each do |log_level|
28
- define_method log_level do |msg|
28
+ define_method log_level do |msg = nil, &block|
29
+ msg ||= block[]
29
30
  colored_msg = format log_level, msg
30
31
  @logger.public_send log_level, colored_msg
31
32
  end
@@ -5,15 +5,19 @@ module FTest
5
5
  attr_writer :child_count
6
6
  attr_writer :fail_fast
7
7
  attr_writer :logger
8
- attr_writer :reverse_stack_traces
9
- attr_writer :trim_backtrace
8
+ attr_writer :reverse_backtraces
9
+ attr_writer :trim_backtraces
10
10
 
11
11
  def child_count
12
- @child_count or 1
12
+ Option::Number.evaluate @child_count do
13
+ ENV.fetch "FTEST_CHILD_COUNT", 1
14
+ end
13
15
  end
14
16
 
15
17
  def fail_fast
16
- @fail_fast or false
18
+ Option::Boolean.evaluate @fail_fast do
19
+ ENV["FTEST_FAIL_FAST"]
20
+ end
17
21
  end
18
22
 
19
23
  def logger
@@ -24,12 +28,48 @@ module FTest
24
28
  @default_logger ||= Logger.new $stdout
25
29
  end
26
30
 
27
- def reverse_stack_traces
28
- @reverse_stack_traces or false
31
+ def reverse_backtraces
32
+ Option::Boolean.evaluate @reverse_backtraces do
33
+ ENV["FTEST_REVERSE_BACKTRACES"]
34
+ end
29
35
  end
30
36
 
31
- def trim_backtrace
32
- @trim_backtrace or false
37
+ def trim_backtraces
38
+ Option::Boolean.evaluate @trim_backtraces do
39
+ ENV.fetch "FTEST_TRIM_BACKTRACES", true
40
+ end
41
+ end
42
+
43
+ class Option
44
+ def self.evaluate value, &block
45
+ instance = new value
46
+ instance.fetch &block
47
+ end
48
+
49
+ def initialize value
50
+ @value = value
51
+ end
52
+
53
+ def fetch
54
+ @value = yield unless set?
55
+ value
56
+ end
57
+
58
+ def set?
59
+ not @value.nil?
60
+ end
61
+
62
+ class Number < Option
63
+ def value
64
+ @value.to_i
65
+ end
66
+ end
67
+
68
+ class Boolean < Option
69
+ def value
70
+ not [nil, false, "", "0", "n", "no", "false"].include? @value
71
+ end
72
+ end
33
73
  end
34
74
  end
35
75
  end
@@ -117,11 +117,12 @@ module FTest
117
117
  def print_stacktrace error
118
118
  locations = error.backtrace
119
119
  final_location = locations.shift
120
+ locations = FTest::BacktraceFilter.(locations)
120
121
 
121
122
  lines = locations.map do |loc| "\tfrom #{loc}" end
122
123
  lines.unshift "#{final_location}: #{error.message}"
123
124
 
124
- lines.reverse! if Config.reverse_stack_traces
125
+ lines.reverse! if Config.reverse_backtraces
125
126
  Config.logger.error "Exception:\n#{lines * "\n"}"
126
127
  end
127
128
 
@@ -0,0 +1,2 @@
1
+ require "ftest"
2
+ include FTest
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ftest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Ladd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-28 00:00:00.000000000 Z
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Fork based runner for tests written as simple ruby scripts
14
14
  email: nathanladd+github@gmail.com
@@ -26,10 +26,12 @@ files:
26
26
  - lib/ftest/assert/checks/registry.rb
27
27
  - lib/ftest/assert/errors.rb
28
28
  - lib/ftest/assert/syntax.rb
29
+ - lib/ftest/backtrace_filter.rb
29
30
  - lib/ftest/cli.rb
30
31
  - lib/ftest/colored_logger.rb
31
32
  - lib/ftest/config.rb
32
33
  - lib/ftest/runner.rb
34
+ - lib/ftest/script.rb
33
35
  - lib/ftest/util.rb
34
36
  homepage: https://github.com/ntl/ftest
35
37
  licenses: