insanity 0.1.0 → 0.2.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 +4 -4
- data/.travis.yml +2 -0
- data/README.md +11 -3
- data/exe/insanity +5 -1
- data/insanity.gemspec +1 -1
- data/lib/insanity.rb +14 -10
- data/lib/insanity/file_writer.rb +34 -0
- data/lib/insanity/{printer.rb → screen_printer.rb} +1 -1
- data/lib/insanity/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 553ef68a8d9f495bff8d47a93e8191137852abb2
|
4
|
+
data.tar.gz: c8688ea5d20abcb3701b888e50d2e8bde5e732cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1862a144aadd5ad01cddb297de76edfa2df1121d93b4402fdb4349f5966c614b11125fae0f1ba39d78c66a2d1d35260656733ca7c7f3e88ac7904207edb9ba0
|
7
|
+
data.tar.gz: 8c2f16dce52c99fa0efd5ec392e249f9782078fa777dd45dea7bd81f1892e2fbc73624cff23461986e55b72ca169d695aabb522eb58808ec041ece91cf2a8ed4
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
# Insanity
|
1
|
+
# Insanity [](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
|
-
|
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 `
|
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
|
|
data/exe/insanity
CHANGED
@@ -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,
|
29
|
+
.new(command: command, options: options)
|
26
30
|
.commence!
|
data/insanity.gemspec
CHANGED
@@ -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)/}) }
|
data/lib/insanity.rb
CHANGED
@@ -1,24 +1,21 @@
|
|
1
1
|
require 'insanity/version'
|
2
|
-
require 'insanity/
|
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:,
|
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
|
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
|
data/lib/insanity/version.rb
CHANGED
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.
|
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:
|
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/
|
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: []
|