insanity 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 214015507baf0c53a4449036bd5f0f570746f615
4
- data.tar.gz: ae74f8c92eef6526d71c4fd24e6f03e8424e4dc7
3
+ metadata.gz: 553ef68a8d9f495bff8d47a93e8191137852abb2
4
+ data.tar.gz: c8688ea5d20abcb3701b888e50d2e8bde5e732cd
5
5
  SHA512:
6
- metadata.gz: 290d36e718a5f81c5f477bb7fc16449a1e40e08b1d56cc25088eea78a7dc1a74543d5a824c37ea57e68800e60cef0de5057b296c8ec3ae97a5dfbe7b7193b138
7
- data.tar.gz: 8cec5b7c2e0655e3a6b5f1d70e1cf5a3e2f10c3b6a647382c9b23cb3773d6c1aa337fff050d54a4da59352de78ae61d1e5e86e3d8d93c45c069ed9e3703080ad
6
+ metadata.gz: c1862a144aadd5ad01cddb297de76edfa2df1121d93b4402fdb4349f5966c614b11125fae0f1ba39d78c66a2d1d35260656733ca7c7f3e88ac7904207edb9ba0
7
+ data.tar.gz: 8c2f16dce52c99fa0efd5ec392e249f9782078fa777dd45dea7bd81f1892e2fbc73624cff23461986e55b72ca169d695aabb522eb58808ec041ece91cf2a8ed4
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.1.8
4
+ - 2.2.4
3
5
  - 2.3.0
4
6
  before_install: gem install bundler -v 1.11.2
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
- # Insanity
1
+ # Insanity [![Build Status](https://travis-ci.org/odlp/insanity.svg?branch=master)](https://travis-ci.org/odlp/insanity)
2
2
 
3
3
  Run a command repeatedly to check for differences. Handy for discovering flaky tests or verifying a change doesn't lead to instability.
4
4
 
5
- Output currently includes a summary of the exit statuses.
5
+ Insanity allows you to:
6
+
7
+ - See a summary of the exit statuses
8
+ - Save the output of each repetition
6
9
 
7
10
  ## Usage
8
11
 
@@ -23,6 +26,11 @@ Status 0 | 8 times
23
26
  Status 1 | 2 times
24
27
  ```
25
28
 
29
+ ### Command options
30
+
31
+ - `-i 99` / `--iterations 99`: Number of many times to run the command. Default: 100.
32
+ - `-o ./tmp` / `--output-dir ./tmp`: Save output in this directory. Each iteration is written to an individual file (combined stdout & stderr). Default: No output saved.
33
+
26
34
  ## Installation
27
35
 
28
36
  Install the gem directly:
@@ -31,7 +39,7 @@ Install the gem directly:
31
39
  gem install insanity
32
40
  ```
33
41
 
34
- Don't forget to run `rebenv rehash` if you use Rbenv.
42
+ Don't forget to run `rbenv rehash` if you use Rbenv.
35
43
 
36
44
  Alternatively add the following to your Gemfile:
37
45
 
@@ -12,6 +12,10 @@ parser = OptionParser.new do|opts|
12
12
  options[:iterations] = iterations
13
13
  end
14
14
 
15
+ opts.on('-o PATH', '--output-dir PATH', 'Path to save the output of each iteration') do |output_dir|
16
+ options[:output_dir] = output_dir
17
+ end
18
+
15
19
  opts.on('-h', '--help', 'Displays Help') do
16
20
  puts opts
17
21
  exit
@@ -22,5 +26,5 @@ parser.parse!
22
26
  command = ARGF.argv[0]
23
27
 
24
28
  Insanity::Runner
25
- .new(command: command, iterations: options[:iterations])
29
+ .new(command: command, options: options)
26
30
  .commence!
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["oliverp@gmail.com"]
11
11
 
12
12
  spec.summary = "Run a command repeatedly to check for differences."
13
- spec.description = "Handy for discovering flaky tests or verifying a change doesn't lead to instability."
13
+ spec.description = "Run a command repeatedly to check for differences. Handy for discovering flaky tests or verifying a change doesn't lead to instability."
14
14
  spec.homepage = "https://github.com/odlp/insanity"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -1,24 +1,21 @@
1
1
  require 'insanity/version'
2
- require 'insanity/printer'
2
+ require 'insanity/screen_printer'
3
+ require 'insanity/file_writer'
3
4
  require 'open3'
4
5
 
5
6
  module Insanity
6
7
  class Runner
7
8
 
8
- def initialize(command:, iterations:, printer: Printer.new)
9
+ def initialize(command:, options:, printer: ScreenPrinter.new, persistence_klass: FileWriter)
9
10
  @command = command
10
- @iterations = iterations
11
+ @iterations = options[:iterations]
11
12
  @printer = printer
13
+ @persistence = persistence_klass.new(output_dir: options[:output_dir])
12
14
  @results = []
13
15
  end
14
16
 
15
17
  def commence!
16
- iterations.times do |i|
17
- _, status = Open3.capture2e(command)
18
- add_result(status)
19
- printer.update_progress(status)
20
- end
21
-
18
+ iterations.times {|i| perform_iteration(i) }
22
19
  printer.print_summary(iterations, results)
23
20
  end
24
21
 
@@ -26,9 +23,16 @@ module Insanity
26
23
 
27
24
  private
28
25
 
29
- attr_reader :command, :iterations, :printer
26
+ attr_reader :command, :iterations, :printer, :persistence
30
27
  attr_accessor :results
31
28
 
29
+ def perform_iteration(i)
30
+ output, status = Open3.capture2e(command)
31
+ add_result(status)
32
+ persistence.save(iteration: i, status: status, output: output)
33
+ printer.update_progress(status)
34
+ end
35
+
32
36
  def add_result(status)
33
37
  results << Result.new(status)
34
38
  end
@@ -0,0 +1,34 @@
1
+ require 'fileutils'
2
+
3
+ module Insanity
4
+ class FileWriter
5
+
6
+ def initialize(output_dir:)
7
+ return if output_dir.nil?
8
+ @write_path = check_or_create_output_dir(output_dir)
9
+ end
10
+
11
+ def save(iteration:, status:, output:)
12
+ return if no_path?
13
+
14
+ file_name = File.join(write_path, "i#{iteration}-exit#{status.exitstatus}.txt")
15
+ File.write(file_name, output)
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :write_path
21
+
22
+ def no_path?
23
+ write_path.nil?
24
+ end
25
+
26
+ def check_or_create_output_dir(output_dir)
27
+ dir = File.expand_path(output_dir)
28
+ unless File.directory? dir
29
+ FileUtils.mkdir_p dir
30
+ end
31
+ dir
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  module Insanity
2
- class Printer
2
+ class ScreenPrinter
3
3
  def update_progress(status)
4
4
  if status.success?
5
5
  print green_dot
@@ -1,3 +1,3 @@
1
1
  module Insanity
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insanity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - odlp
@@ -86,8 +86,8 @@ dependencies:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: 2.3.3
89
- description: Handy for discovering flaky tests or verifying a change doesn't lead
90
- to instability.
89
+ description: Run a command repeatedly to check for differences. Handy for discovering
90
+ flaky tests or verifying a change doesn't lead to instability.
91
91
  email:
92
92
  - oliverp@gmail.com
93
93
  executables:
@@ -107,7 +107,8 @@ files:
107
107
  - exe/insanity
108
108
  - insanity.gemspec
109
109
  - lib/insanity.rb
110
- - lib/insanity/printer.rb
110
+ - lib/insanity/file_writer.rb
111
+ - lib/insanity/screen_printer.rb
111
112
  - lib/insanity/version.rb
112
113
  homepage: https://github.com/odlp/insanity
113
114
  licenses: []