at_coder_friends 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -2
  3. data/.rubocop.yml +1 -0
  4. data/.rubocop_todo.yml +4 -1
  5. data/Gemfile.lock +16 -14
  6. data/Rakefile +2 -0
  7. data/at_coder_friends.gemspec +1 -0
  8. data/lib/at_coder_friends.rb +13 -5
  9. data/lib/at_coder_friends/cli.rb +1 -2
  10. data/lib/at_coder_friends/config_loader.rb +2 -2
  11. data/lib/at_coder_friends/context.rb +3 -3
  12. data/lib/at_coder_friends/cxx_generator.rb +7 -13
  13. data/lib/at_coder_friends/emitter.rb +0 -4
  14. data/lib/at_coder_friends/parser/constraints_parser.rb +26 -0
  15. data/lib/at_coder_friends/parser/format_parser.rb +154 -0
  16. data/lib/at_coder_friends/parser/main.rb +16 -0
  17. data/lib/at_coder_friends/parser/page_parser.rb +119 -0
  18. data/lib/at_coder_friends/path_util.rb +10 -0
  19. data/lib/at_coder_friends/problem.rb +11 -14
  20. data/lib/at_coder_friends/scraping/agent.rb +77 -0
  21. data/lib/at_coder_friends/scraping/authentication.rb +71 -0
  22. data/lib/at_coder_friends/scraping/custom_test.rb +53 -0
  23. data/lib/at_coder_friends/scraping/session.rb +26 -0
  24. data/lib/at_coder_friends/scraping/submission.rb +31 -0
  25. data/lib/at_coder_friends/scraping/tasks.rb +39 -0
  26. data/lib/at_coder_friends/test_runner/base.rb +123 -0
  27. data/lib/at_coder_friends/test_runner/judge.rb +44 -0
  28. data/lib/at_coder_friends/test_runner/sample.rb +35 -0
  29. data/lib/at_coder_friends/verifier.rb +4 -2
  30. data/lib/at_coder_friends/version.rb +1 -1
  31. data/tasks/regression.rake +163 -0
  32. metadata +30 -7
  33. data/lib/at_coder_friends/format_parser.rb +0 -151
  34. data/lib/at_coder_friends/judge_test_runner.rb +0 -34
  35. data/lib/at_coder_friends/sample_test_runner.rb +0 -31
  36. data/lib/at_coder_friends/scraping_agent.rb +0 -265
  37. data/lib/at_coder_friends/test_runner.rb +0 -104
@@ -1,104 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rbconfig'
4
-
5
- module AtCoderFriends
6
- # run tests for the specified program.
7
- class TestRunner
8
- include PathUtil
9
-
10
- attr_reader :ctx
11
-
12
- def initialize(ctx)
13
- @ctx = ctx
14
- @path, @dir, @prg, @base, @ext, @q = split_prg_path(ctx.path)
15
- end
16
-
17
- def config
18
- ctx.config
19
- end
20
-
21
- # rubocop:disable Metrics/MethodLength
22
- def run_test(id, infile, outfile, expfile)
23
- return false unless File.exist?(infile) && File.exist?(expfile)
24
-
25
- puts "==== #{id} (#{test_loc}) ===="
26
-
27
- success = send(test_mtd, infile, outfile)
28
- input, result, expected =
29
- [infile, outfile, expfile].map { |file| File.read(file) }
30
-
31
- puts '-- input --'
32
- print input
33
- puts '-- expected --'
34
- print expected
35
- puts '-- result --'
36
- print result
37
- if !success
38
- puts '!!!!! RE !!!!!'
39
- elsif result != expected
40
- puts '!!!!! WA !!!!!'
41
- else
42
- puts '<< OK >>'
43
- end
44
- true
45
- end
46
- # rubocop:enable Metrics/MethodLength
47
-
48
- def test_loc
49
- test_cmd ? 'local' : 'remote'
50
- end
51
-
52
- def test_mtd
53
- test_cmd ? :local_test : :remote_test
54
- end
55
-
56
- def local_test(infile, outfile)
57
- system("#{test_cmd} < #{infile} > #{outfile}")
58
- end
59
-
60
- def remote_test(infile, outfile)
61
- res = ctx.scraping_agent.code_test(infile)
62
- unless res && res['Result']
63
- File.write(outfile, 'Remote test failed.')
64
- return false
65
- end
66
- puts "Exit code: #{res.dig('Result', 'ExitCode')}"
67
- puts "Time: #{res.dig('Result', 'TimeConsumption')}ms"
68
- puts "Memory: #{res.dig('Result', 'MemoryConsumption')}KB"
69
- if res.dig('Result', 'ExitCode') != 0
70
- File.write(outfile, res['Stderr'])
71
- return false
72
- end
73
- File.write(outfile, res['Stdout'])
74
- true
75
- end
76
-
77
- def test_cmd
78
- @test_cmd ||= begin
79
- cmds = config.dig('ext_settings', @ext, 'test_cmd')
80
- cmd = cmds && (cmds[which_os.to_s] || cmds['default'])
81
- return nil unless cmd
82
-
83
- cmd.gsub('{dir}', @dir).gsub('{base}', @base)
84
- end
85
- end
86
-
87
- def which_os
88
- @which_os ||= begin
89
- case RbConfig::CONFIG['host_os']
90
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
91
- :windows
92
- when /darwin|mac os/
93
- :macosx
94
- when /linux/
95
- :linux
96
- when /solaris|bsd/
97
- :unix
98
- else
99
- :unknown
100
- end
101
- end
102
- end
103
- end
104
- end