flakie 1.0.0 → 2.0.1
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/.ruby-version +1 -1
- 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 -12
- data/lib/flakie/report.rb +9 -0
- 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/run.rb +9 -0
- data/lib/flakie/version.rb +1 -1
- data/lib/flakie.rb +1 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9547b581d0d35fd344f0b289bb0c4acd43198fb967d861dd4f934447e5529323
|
4
|
+
data.tar.gz: e21954bf1272f817b56761ca247f17057463c53011916d3c10a4d1701fefe1e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab3633180ea705c586dcfc3f30a54807c08a4090b97c26771703fe12c7bc6127e721b3fea921e445d1812d1a8cf090dd2fc10a95bcfe01d529aa177aafec539c
|
7
|
+
data.tar.gz: 4d1968ae5fe66c92ebac24f4967a963065010aec5f69e0898478c1c78e4ef7f5ac50fe8bc716dc4b44323b6485f62c5a931d8a9b5f1a4acdb0f5f31e67b5ec3b
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-3.
|
1
|
+
ruby-3.3.0
|
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
@@ -2,18 +2,9 @@
|
|
2
2
|
|
3
3
|
module Flakie
|
4
4
|
class Engine
|
5
|
-
|
6
|
-
Data.define(:status, :duration, :number) do
|
7
|
-
def success? = status == true
|
8
|
-
def failure? = status == true
|
9
|
-
end
|
10
|
-
|
11
|
-
Report = Data.define(:runs) { def last_run = runs.last }
|
12
|
-
|
13
|
-
def initialize(command, count:, env:, reporter:)
|
5
|
+
def initialize(command, count:, reporter:)
|
14
6
|
@command = command
|
15
7
|
@count = count
|
16
|
-
@env = env
|
17
8
|
@reporter = reporter
|
18
9
|
@report = Report.new([])
|
19
10
|
end
|
@@ -23,7 +14,7 @@ module Flakie
|
|
23
14
|
|
24
15
|
count.times do |index|
|
25
16
|
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
26
|
-
system(
|
17
|
+
system(command, out: File::NULL, err: File::NULL)
|
27
18
|
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
28
19
|
duration = (end_time - start_time).round
|
29
20
|
report.runs.append Run.new(status: $?.success?, duration: duration, number: index + 1)
|
@@ -35,6 +26,6 @@ module Flakie
|
|
35
26
|
|
36
27
|
private
|
37
28
|
|
38
|
-
attr_reader :command, :count, :
|
29
|
+
attr_reader :command, :count, :reporter, :report
|
39
30
|
end
|
40
31
|
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/run.rb
ADDED
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Khurram Raza
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -48,9 +48,11 @@ 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/report.rb
|
52
|
+
- lib/flakie/reporters.rb
|
53
|
+
- lib/flakie/reporters/base.rb
|
54
|
+
- lib/flakie/reporters/tic_tac_toe.rb
|
55
|
+
- lib/flakie/run.rb
|
54
56
|
- lib/flakie/version.rb
|
55
57
|
homepage: https://github.com/ikhurramraza/flakie.git
|
56
58
|
licenses:
|
@@ -74,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
76
|
- !ruby/object:Gem::Version
|
75
77
|
version: '0'
|
76
78
|
requirements: []
|
77
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.5.3
|
78
80
|
signing_key:
|
79
81
|
specification_version: 4
|
80
82
|
summary: Test flakyness of commands
|