flakie 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/lefthook.yml +5 -3
- data/lib/flakie/cli/options.rb +3 -18
- data/lib/flakie/cli/parser.rb +8 -8
- data/lib/flakie/cli/runner.rb +7 -6
- data/lib/flakie/cli.rb +10 -4
- data/lib/flakie/engine.rb +3 -4
- data/lib/flakie/{formatters → reporters}/base.rb +2 -2
- data/lib/flakie/{formatters → reporters}/tic_tac_toe.rb +1 -1
- data/lib/flakie/{formatters.rb → reporters.rb} +1 -1
- data/lib/flakie/version.rb +1 -1
- data/lib/flakie.rb +1 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fb34ac8ca43a45eed4f1f0d44c6c2e7bb42165dcb88b62b7493bdd63baf9b9e
|
4
|
+
data.tar.gz: 6c847cdcbe2c5456446179ca25254333f9f24e78fd777a5d8ee8841786d9248a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52c5846a7221fe468ebd6edcddda83166f6d97b95174101057de62869b40450a67c022da65eeeb5d02c4947f74159c76bdaa65ef19c73adb31be3e33007557b3
|
7
|
+
data.tar.gz: a5d9e8418b723cfd717e5f5eaf5dd2012c70335ce371466bcfb8c473207784538575fe1517348219cc919f771936e809bc519ed9bfcb03dcad6bce66be2857ab
|
data/.rubocop.yml
CHANGED
data/lefthook.yml
CHANGED
@@ -10,8 +10,10 @@ pre-commit:
|
|
10
10
|
rspec:
|
11
11
|
run: bundle exec rspec
|
12
12
|
rubocop:
|
13
|
-
files: git
|
14
|
-
|
13
|
+
files: "git diff --name-only --staged"
|
14
|
+
glob: "{Gemfile,Rakefile,*.gemspec,*.rb}"
|
15
|
+
run: bundle exec rubocop --parallel {files}
|
15
16
|
stree:
|
16
|
-
files: git
|
17
|
+
files: "git diff --name-only --staged"
|
18
|
+
glob: "{Rakefile,*.gemspec,*.rb}"
|
17
19
|
run: bundle exec stree check {files}
|
data/lib/flakie/cli/options.rb
CHANGED
@@ -3,26 +3,11 @@
|
|
3
3
|
module Flakie
|
4
4
|
module CLI
|
5
5
|
Options =
|
6
|
-
Struct.new(:count, :
|
7
|
-
def self.default = new(count: 5,
|
6
|
+
Struct.new(:count, :format, :output, :help, :version) do
|
7
|
+
def self.default = new(count: 5, format: :tictactoe, output: $stdout, help: false, version: false)
|
8
8
|
def self.from(args) = default.tap { |options| Parser.parse!(args, into: options) }
|
9
9
|
|
10
|
-
def
|
11
|
-
if key == :env
|
12
|
-
add_env(value)
|
13
|
-
else
|
14
|
-
super
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def add_env(raw)
|
19
|
-
name, value = raw.split("=")
|
20
|
-
CLI.exit_with_error("Bad env variable format: #{raw}") if name.nil? || value.nil?
|
21
|
-
|
22
|
-
env[name] = value
|
23
|
-
end
|
24
|
-
|
25
|
-
def formatter = Formatters::ALL.fetch(format)
|
10
|
+
def reporter = Reporters::ALL.fetch(format)
|
26
11
|
|
27
12
|
def help? = help
|
28
13
|
def version? = version
|
data/lib/flakie/cli/parser.rb
CHANGED
@@ -4,22 +4,20 @@ module Flakie
|
|
4
4
|
module CLI
|
5
5
|
Parser =
|
6
6
|
OptionParser.new do |opts|
|
7
|
-
opts.banner = "USAGE: #{
|
7
|
+
opts.banner = "USAGE: #{NAME} [OPTIONS] COMMAND"
|
8
8
|
opts.separator ""
|
9
9
|
|
10
|
-
opts.version = "#{
|
10
|
+
opts.version = "#{NAME} #{VERSION}"
|
11
11
|
|
12
12
|
opts.separator "OPTIONS:"
|
13
13
|
opts.on("-n", "--count COUNT", Integer, "Number of tries (default: #{Options.default.count})")
|
14
14
|
|
15
15
|
opts.on("-f", "--format FORMATTER", "Output format. See FORMATTERS section below.") do |choice|
|
16
|
-
|
16
|
+
Reporters::ALL.include?(choice.to_sym) ? choice.to_sym : CLI.fail("Invalid format: #{choice}")
|
17
17
|
end
|
18
18
|
|
19
19
|
opts.on("-o", "--output FILE", "File to output result. Defaults to STDOUT.") { |path| File.open(path, "w") }
|
20
20
|
|
21
|
-
opts.on("-e", "--env KEY_VALUE", "Additional environment variables to set. Can be called multiple times.")
|
22
|
-
|
23
21
|
opts.on("-v", "--version", "Show the version")
|
24
22
|
opts.on("-h", "--help", "Show this help message")
|
25
23
|
opts.separator ""
|
@@ -29,9 +27,11 @@ module Flakie
|
|
29
27
|
opts.separator ""
|
30
28
|
|
31
29
|
opts.separator "EXAMPLES:"
|
32
|
-
opts.separator " #{
|
33
|
-
opts.separator " #{
|
34
|
-
opts.separator " #{
|
30
|
+
opts.separator " #{NAME} rails t test/foo_test.rb"
|
31
|
+
opts.separator " #{NAME} -n10 rails t test/foo_test.rb"
|
32
|
+
opts.separator " #{NAME} --count=10 rails t test/foo_test.rb"
|
33
|
+
opts.separator " #{NAME} --format=tictactoe rails t test/foo_test.rb"
|
34
|
+
opts.separator " #{NAME} -f tictactoe -o result.txt rails t test/foo_test.rb"
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
data/lib/flakie/cli/runner.rb
CHANGED
@@ -15,18 +15,19 @@ module Flakie
|
|
15
15
|
in version: true
|
16
16
|
Parser.version.display
|
17
17
|
else
|
18
|
-
Engine.new(
|
19
|
-
args.join(" "),
|
20
|
-
count: options.count,
|
21
|
-
env: options.env,
|
22
|
-
reporter: options.formatter.new(options.output),
|
23
|
-
).run
|
18
|
+
Engine.new(command, count: options.count, reporter: options.reporter.new(options.output)).run
|
24
19
|
end
|
25
20
|
end
|
26
21
|
|
27
22
|
private
|
28
23
|
|
29
24
|
attr_reader :options, :args
|
25
|
+
|
26
|
+
def command
|
27
|
+
CLI.fail("Command is a required argument") if args.empty?
|
28
|
+
|
29
|
+
args.join(" ")
|
30
|
+
end
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
data/lib/flakie/cli.rb
CHANGED
@@ -2,14 +2,20 @@
|
|
2
2
|
|
3
3
|
module Flakie
|
4
4
|
module CLI
|
5
|
-
|
5
|
+
extend self
|
6
6
|
|
7
|
-
def
|
7
|
+
def run(args)
|
8
8
|
Runner.new(args).call
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
warn(msg)
|
11
|
+
def fail(msg, show_help: true)
|
12
|
+
warn("error: #{msg}")
|
13
|
+
|
14
|
+
if show_help
|
15
|
+
warn("")
|
16
|
+
warn(Parser.help)
|
17
|
+
end
|
18
|
+
|
13
19
|
exit 1
|
14
20
|
end
|
15
21
|
end
|
data/lib/flakie/engine.rb
CHANGED
@@ -10,10 +10,9 @@ module Flakie
|
|
10
10
|
|
11
11
|
Report = Data.define(:runs) { def last_run = runs.last }
|
12
12
|
|
13
|
-
def initialize(command, count:,
|
13
|
+
def initialize(command, count:, reporter:)
|
14
14
|
@command = command
|
15
15
|
@count = count
|
16
|
-
@env = env
|
17
16
|
@reporter = reporter
|
18
17
|
@report = Report.new([])
|
19
18
|
end
|
@@ -23,7 +22,7 @@ module Flakie
|
|
23
22
|
|
24
23
|
count.times do |index|
|
25
24
|
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
26
|
-
system(
|
25
|
+
system(command, out: File::NULL, err: File::NULL)
|
27
26
|
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
28
27
|
duration = (end_time - start_time).round
|
29
28
|
report.runs.append Run.new(status: $?.success?, duration: duration, number: index + 1)
|
@@ -35,6 +34,6 @@ module Flakie
|
|
35
34
|
|
36
35
|
private
|
37
36
|
|
38
|
-
attr_reader :command, :count, :
|
37
|
+
attr_reader :command, :count, :reporter, :report
|
39
38
|
end
|
40
39
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Flakie
|
4
|
-
module
|
4
|
+
module Reporters
|
5
5
|
class Base
|
6
6
|
def initialize(output)
|
7
7
|
@output = output
|
@@ -16,7 +16,7 @@ module Flakie
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def report(_report)
|
19
|
-
raise NotImplementedError, "Base
|
19
|
+
raise NotImplementedError, "Base class must implement this method"
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
data/lib/flakie/version.rb
CHANGED
data/lib/flakie.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flakie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Khurram Raza
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -48,9 +48,9 @@ files:
|
|
48
48
|
- lib/flakie/cli/parser.rb
|
49
49
|
- lib/flakie/cli/runner.rb
|
50
50
|
- lib/flakie/engine.rb
|
51
|
-
- lib/flakie/
|
52
|
-
- lib/flakie/
|
53
|
-
- lib/flakie/
|
51
|
+
- lib/flakie/reporters.rb
|
52
|
+
- lib/flakie/reporters/base.rb
|
53
|
+
- lib/flakie/reporters/tic_tac_toe.rb
|
54
54
|
- lib/flakie/version.rb
|
55
55
|
homepage: https://github.com/ikhurramraza/flakie.git
|
56
56
|
licenses:
|