Skip to content

Commit

Permalink
Improve CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Oct 4, 2022
1 parent 1ea0867 commit f06958d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
7 changes: 6 additions & 1 deletion exe/easytest
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
$LOAD_PATH << File.expand_path("../lib", __dir__)
$LOAD_PATH << File.join(Dir.pwd, "test")

Dir.glob("test/**/*_test.rb") { |file| load file }
require "easytest"

test_files = Dir.glob("test/**/*_test.rb").filter do |file|
ARGV.empty? || ARGV.any? { |pattern| file.include?(pattern) }
end
test_files.each { |file| load file }
17 changes: 12 additions & 5 deletions lib/easytest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def self.run
end
end

puts "#{Rainbow('Summary:').bright} #{Rainbow("#{failed_count} failed").red.bright}, " \
"#{Rainbow("#{passed_count} passed").green.bright}, " \
"#{passed_count + failed_count} total"
[passed_count, failed_count]
end

def self.cases
Expand All @@ -52,9 +50,18 @@ def self.add_case(new_case)
start_time = Time.now

at_exit do
Easytest.run
passed_count, failed_count = Easytest.run
total_count = passed_count + failed_count

time = Time.now - start_time

puts "#{Rainbow('Time:').bright} #{time.round(5)} seconds"
if total_count == 0
puts Rainbow("A test suite should have at least one test case!").red.bright
puts ""
puts "Please put `test/**/*_test.rb` files or specify valid patterns to the `easytest` command."
else
puts "#{Rainbow('Summary:').bright} #{Rainbow("#{failed_count} failed").red.bright}, " \
"#{Rainbow("#{passed_count} passed").green.bright}, #{total_count} total"
puts "#{Rainbow('Time:').bright} #{time.round(5)} seconds"
end
end

0 comments on commit f06958d

Please sign in to comment.