Class: Judges::Test

Inherits:
Object show all
Defined in:
lib/judges/commands/test.rb

Overview

Test.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright Ā© 2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(loog) ⇒ Test

Returns a new instance of Test.



38
39
40
# File 'lib/judges/commands/test.rb', line 38

def initialize(loog)
  @loog = loog
end

Instance Method Details

#run(opts, args) ⇒ Object



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
74
# File 'lib/judges/commands/test.rb', line 42

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 = []
  done = 0
  global = {}
  Judges::Packs.new(dir, opts['lib'], @loog).each_with_index do |p, i|
    local = {}
    next unless include?(opts, p.name)
    @loog.info("\nšŸ‘‰ Testing #{p.script} (##{i}) in #{p.dir.to_rel}...")
    p.tests.each do |f|
      yaml = YAML.load_file(f, permitted_classes: [Time])
      @loog.info("Testing #{f.to_rel}:")
      begin
        test_one(p, global, local, yaml)
      rescue StandardError => e
        @loog.warn(Backtrace.new(e))
        errors << f
      end
    end
    done += 1
  end
  if done.zero?
    raise 'No judges tested :(' unless opts['quiet']
    @loog.warn("\nšŸ‘ No judges tested")
  elsif errors.empty?
    @loog.info("\nšŸ‘ All #{done} judge(s) tested successfully")
  else
    @loog.info("\nāŒ #{done} judge(s) tested, #{errors.size} of them failed")
    raise "#{errors.size} tests failed" unless opts['quiet']
  end
end