Class: Judges::Test
Overview
Test.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright Ā© 2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(loog) ⇒ Test
constructor
A new instance of Test.
- #run(opts, args) ⇒ Object
Constructor Details
#initialize(loog) ⇒ Test
Returns a new instance of Test.
40 41 42 |
# File 'lib/judges/commands/test.rb', line 40 def initialize(loog) @loog = loog end |
Instance Method Details
#run(opts, args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/judges/commands/test.rb', line 44 def run(opts, args) raise 'Exactly one argument required' unless args.size == 1 dir = args[0] @loog.info("Testing judges in #{dir.to_rel}...") errors = [] judges = 0 tests = 0 visible = [] elapsed(@loog) do Judges::Judges.new(dir, opts['lib'], @loog).each_with_index do |p, i| visible << p.name next unless include?(opts, p.name) @loog.info("\nš Testing #{p.script} (##{i}) in #{p.dir.to_rel}...") p.tests.each do |f| tname = File.basename(f).gsub(/\.yml$/, '') visible << " #{p.name}/#{tname}" next unless include?(opts, p.name, tname) yaml = YAML.load_file(f, permitted_classes: [Time]) if yaml['skip'] @loog.info("Skippped #{f.to_rel}") next end unless Judges::Categories.new(opts['enable'], opts['disable']).ok?(yaml['category']) @loog.info("Skippped #{f.to_rel} because of its category") next end @loog.info("š ļø Testing #{f.to_rel}:") begin test_one(opts, p, tname, yaml) tests += 1 rescue StandardError => e @loog.warn(Backtrace.new(e)) errors << f end end judges += 1 end throw :'š No judges tested' if judges.zero? throw :"š All #{judges} judge(s) but no tests passed" if tests.zero? throw :"š All #{judges} judge(s) and #{tests} tests passed" if errors.empty? throw :"ā #{judges} judge(s) tested, #{errors.size} of them failed" end unless errors.empty? raise "#{errors.size} tests failed" unless opts['quiet'] @loog.debug('Not failing the build with tests failures, due to the --quiet option') end return unless judges.zero? || tests.zero? if opts['judge'].nil? raise 'There are seems to be no judges' unless opts['quiet'] @loog.debug('Not failing the build with no judges tested, due to the --quiet option') else raise 'There are seems to be no judges' if visible.empty? @loog.info("The following judges are available to use with the --judge option:\n #{visible.join("\n ")}") end end |