Class: Judges::Test
Overview
The test command.
This class is instantiated by the bin/judges command line interface. You are not supposed to instantiate it yourself.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024-2026 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(loog) ⇒ Test
constructor
Initialize.
-
#run(opts, args) ⇒ Object
Run the test command (called by the
bin/judgesscript).
Constructor Details
#initialize(loog) ⇒ Test
Initialize.
30 31 32 |
# File 'lib/judges/commands/test.rb', line 30 def initialize(loog) @loog = loog end |
Instance Method Details
#run(opts, args) ⇒ Object
Run the test command (called by the bin/judges script). rubocop:disable Metrics/MethodLength
39 40 41 42 43 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 |
# File 'lib/judges/commands/test.rb', line 39 def run(opts, args) raise(ArgumentError, 'Exactly one argument required') unless args.size == 1 dir = args[0] @loog.info("Testing judges in #{dir.to_rel}...") errors = [] tested = 0 tests = 0 visible = [] times = {} judges = Judges::Judges.new(dir, opts['lib'], @loog) elapsed(@loog, level: Logger::INFO) do judges.each_with_index do |judge, i| visible << judge.name next unless include?(opts, judge.name) @loog.info("👉 Testing #{judge.script} (##{i}) in #{judge.dir.to_rel}...") buf = Loog::Buffer.new judge = judge.with_loog(buf) tests += run_judge_tests(judge, buf, opts, judges, visible, times, errors) tested += 1 end print_test_summary(times, errors, tested, tests) end unless errors.empty? raise(StandardError, "#{errors.size} tests failed") unless opts['quiet'] @loog.debug('Not failing the build with test failures, due to the --quiet option') end return unless tested.zero? || tests.zero? if opts['judge'].nil? raise(StandardError, 'There seem to be no judges') unless opts['quiet'] @loog.debug('Not failing the build with no judges tested, due to the --quiet option') else raise(StandardError, 'There seem 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 |