git-contest 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +21 -3
  3. data/README.md +5 -0
  4. data/Rakefile +8 -0
  5. data/appveyor.yml +21 -0
  6. data/bin/git-contest +4 -33
  7. data/bin/git-contest-config +4 -241
  8. data/bin/git-contest-finish +4 -151
  9. data/bin/git-contest-init +4 -65
  10. data/bin/git-contest-list +4 -64
  11. data/bin/git-contest-rebase +4 -64
  12. data/bin/git-contest-start +4 -57
  13. data/bin/git-contest-submit +4 -183
  14. data/git-contest.gemspec +2 -1
  15. data/lib/contest/driver/base.rb +7 -4
  16. data/lib/git/contest/command_line.rb +10 -0
  17. data/lib/git/contest/command_line/command.rb +117 -0
  18. data/lib/git/contest/command_line/main_command.rb +56 -0
  19. data/lib/git/contest/command_line/sub_commands.rb +35 -0
  20. data/lib/git/contest/command_line/sub_commands/config_command.rb +258 -0
  21. data/lib/git/contest/command_line/sub_commands/finish_command.rb +161 -0
  22. data/lib/git/contest/command_line/sub_commands/init_command.rb +79 -0
  23. data/lib/git/contest/command_line/sub_commands/list_command.rb +89 -0
  24. data/lib/git/contest/command_line/sub_commands/rebase_command.rb +87 -0
  25. data/lib/git/contest/command_line/sub_commands/start_command.rb +77 -0
  26. data/lib/git/contest/command_line/sub_commands/submit_command.rb +220 -0
  27. data/lib/git/contest/common.rb +6 -6
  28. data/lib/git/contest/git.rb +160 -156
  29. data/lib/git/contest/version.rb +1 -1
  30. data/spec/command/t004_git_contest_submit_spec.rb +254 -0
  31. data/spec/command/t005_git_contest_branching_spec.rb +90 -0
  32. data/spec/command/t007_git_contest_start_spec.rb +95 -0
  33. data/spec/command/t008_git_contest_finish_spec.rb +171 -0
  34. data/spec/command/t009_git_contest_init_spec.rb +85 -0
  35. data/spec/command/t012_git_contest_list_spec.rb +123 -0
  36. data/spec/command/t013_git_contest_config_spec.rb +186 -0
  37. data/spec/{lib/contest/driver → contest_driver}/t001_aizu_online_judge_spec.rb +1 -1
  38. data/spec/{lib/contest/driver → contest_driver}/t002_codeforces_spec.rb +1 -1
  39. data/spec/{lib/contest/driver → contest_driver}/t003_uva_online_judge_spec.rb +1 -1
  40. data/spec/{lib/contest/driver → contest_driver}/t010_kattis_spec.rb +1 -1
  41. data/spec/{lib/contest/driver → contest_driver}/t011_utils_spec.rb +0 -0
  42. data/spec/spec_helper.rb +18 -12
  43. data/spec/t006_config_spec.rb +37 -31
  44. metadata +57 -33
  45. data/spec/bin/t004_git_contest_submit_spec.rb +0 -223
  46. data/spec/bin/t005_git_contest_branching_spec.rb +0 -70
  47. data/spec/bin/t007_git_contest_start_spec.rb +0 -88
  48. data/spec/bin/t008_git_contest_finish_spec.rb +0 -162
  49. data/spec/bin/t009_git_contest_init_spec.rb +0 -55
  50. data/spec/bin/t012_git_contest_list_spec.rb +0 -99
  51. data/spec/bin/t013_git_contest_config_spec.rb +0 -149
  52. data/spec/spec_list.txt +0 -1
@@ -7,6 +7,6 @@
7
7
 
8
8
  module Git
9
9
  module Contest
10
- VERSION = "0.2.4"
10
+ VERSION = "0.2.5"
11
11
  end
12
12
  end
@@ -0,0 +1,254 @@
1
+ require "spec_helper"
2
+
3
+ module CommandLine
4
+
5
+ describe "T004: git-contest-submit command" do
6
+
7
+ before do
8
+ ENV['GIT_CONTEST_CONFIG'] = "#{@temp_dir}/config.yml"
9
+ File.write "#{@temp_dir}/config.yml", [
10
+ 'sites:',
11
+ ' test_dummy:',
12
+ ' driver: dummy',
13
+ ' user: dummy',
14
+ ' password: dummy',
15
+ ' test_11111:',
16
+ ' driver: codeforces',
17
+ ' user: dummy',
18
+ ' password: dummy',
19
+ ' test_22222:',
20
+ ' driver: aizu_online_judge',
21
+ ' user: dummy',
22
+ ' password: dummy',
23
+ ' test_33333:',
24
+ ' driver: uva_online_judge',
25
+ ' user: dummy',
26
+ ' password: dummy'
27
+ ].join($/)
28
+ end
29
+
30
+ def call_submit(args)
31
+ cli = SubCommands::SubmitCommand.new(args)
32
+ cli.init
33
+ cli
34
+ end
35
+
36
+ def call_main(args)
37
+ cli = MainCommand.new(args)
38
+ cli.init
39
+ cli
40
+ end
41
+
42
+ def call_init(args)
43
+ cli = SubCommands::InitCommand.new(args)
44
+ cli.init
45
+ cli
46
+ end
47
+
48
+ context "A001: --version" do
49
+
50
+ context "git-contest-submit --version" do
51
+ it { expect { call_submit(["--version"])}.to output(/[0-9]+\.[0-9]+\.[0-9]+/).to_stdout.and raise_error SystemExit }
52
+ end
53
+
54
+ context "git-contest submit --version" do
55
+ it { expect { call_main(["submit", "--version"]).run }.to output(/[0-9]+\.[0-9]+\.[0-9]+/).to_stdout.and raise_error SystemExit }
56
+ end
57
+
58
+ end
59
+
60
+ context "A002: --help" do
61
+
62
+ before do
63
+ Dir.mkdir 'working'
64
+ Dir.chdir 'working'
65
+ File.open 'main.cpp', 'w' do |file|
66
+ file.write 'ac-code'
67
+ end
68
+ end
69
+
70
+ context "B001: dummy driver available only test-mode" do
71
+ context "git-contest-submit --help" do
72
+ subject { lambda { call_submit(['--help']).run } }
73
+ it { should output(/test_dummy/).to_stdout.and raise_error SystemExit }
74
+ it { should output(/test_11111/).to_stdout.and raise_error SystemExit }
75
+ it { should output(/test_22222/).to_stdout.and raise_error SystemExit }
76
+ it { should output(/test_33333/).to_stdout.and raise_error SystemExit }
77
+ end
78
+ end
79
+ end
80
+
81
+ context "A003: after init git repo" do
82
+
83
+ before do
84
+ Dir.mkdir 'working'
85
+ Dir.chdir 'working'
86
+ File.open 'main.cpp', 'w' do |file|
87
+ file.write 'ac-code'
88
+ end
89
+ end
90
+
91
+ before do
92
+ call_init(['--defaults']).run
93
+ end
94
+
95
+ context "git-contest-submit test_dummy -c 100 -p A" do
96
+
97
+ context "output" do
98
+ subject { lambda { call_submit(['test_dummy', '-c', '100', '-p', 'A']).run } }
99
+ it { should output(/99999/).to_stdout }
100
+ it { should output(/Accepted/).to_stdout }
101
+ it { should output(/@commit/).to_stdout }
102
+ end
103
+
104
+ context "submit" do
105
+ before { expect { call_submit(['test_dummy', '-c', '100', '-p', 'A']).run }.to output(/@commit/).to_stdout }
106
+ it do
107
+ ret_git = `git log --oneline`
108
+ expect(ret_git).to match /Dummy 100A: Accepted/
109
+ end
110
+ end
111
+ end
112
+ end
113
+
114
+ context "A004: with commit message" do
115
+
116
+ before do
117
+ Dir.mkdir 'working'
118
+ Dir.chdir 'working'
119
+ File.open 'main.cpp', 'w' do |file|
120
+ file.write 'ac-code'
121
+ end
122
+ end
123
+
124
+ before { expect { call_init(["--defaults"]).run }.to output("").to_stdout }
125
+
126
+ context "git contest submit test_dummy -c 100 -p A -m '...'" do
127
+ before { expect { call_submit(['test_dummy', '-c', '100', '-p', 'A', '-m', 'this is commit message']).run }.to output(/@commit/).to_stdout }
128
+ it do
129
+ ret = Git.do "log --oneline"
130
+ expect(ret).to include "this is commit message"
131
+ end
132
+ end
133
+
134
+ end
135
+
136
+ context 'A005: normal submit' do
137
+
138
+ before do
139
+ Dir.mkdir 'working'
140
+ Dir.chdir 'working'
141
+ File.open 'main.cpp', 'w' do |file|
142
+ file.write 'ac-code'
143
+ end
144
+ end
145
+
146
+ context "git-contest-submit test_dummy" do
147
+ subject { lambda { call_submit(["test_dummy"]).run } }
148
+ it { should output(/Error/).to_stderr.and raise_error SystemExit }
149
+ end
150
+
151
+ context "git-contest-submit test_dummy -c 100" do
152
+ subject { lambda { call_submit(["test_dummy", "-c", "100"]).run } }
153
+ it { should output(/Error/).to_stderr.and raise_error SystemExit }
154
+ end
155
+
156
+ context "git-contest-submit test_dummy -c 100 -p A" do
157
+ subject { lambda { call_submit(['test_dummy', '-c', '100', '-p', 'A']).run } }
158
+ it { should output(/99999/).to_stdout }
159
+ it { should output(/Accepted/).to_stdout }
160
+ end
161
+ end
162
+
163
+ context 'A006: --source' do
164
+ before do
165
+ Dir.mkdir 'working'
166
+ Dir.chdir 'working'
167
+ end
168
+
169
+ context "B001: submit single file" do
170
+ before do
171
+ File.open 'ac.cpp', 'w' do |file|
172
+ file.write 'ac-code'
173
+ end
174
+ File.open 'wa.cpp', 'w' do |file|
175
+ file.write 'wa-code'
176
+ end
177
+ end
178
+
179
+ context "git contest submit test_dummy -c 100 -p A --source ac.cpp" do
180
+ subject { lambda { call_submit(["test_dummy", "-c", "100", "-p", "A", "--source", "ac.cpp"]).run } }
181
+ it { should output(/99999/).to_stdout }
182
+ it { should output(/Accepted/).to_stdout }
183
+ end
184
+
185
+ context "git contest submit test_dummy -c 100 -p A -s ac.cpp" do
186
+ subject { lambda { call_submit(["test_dummy", "-c", "100", "-p", "A", "-s", "ac.cpp"]).run } }
187
+ it { should output(/99999/).to_stdout }
188
+ it { should output(/Accepted/).to_stdout }
189
+ end
190
+
191
+ context "git contest submit test_dummy -c 100 -p A --source wa.cpp" do
192
+ subject { lambda { call_submit(["test_dummy", "-c", "100", "-p", "A", "--source", "wa.cpp"]).run } }
193
+ it { should output(/99999/).to_stdout }
194
+ it { should output(/Wrong Answer/).to_stdout }
195
+ end
196
+
197
+ context "git contest submit test_dummy -c 100 -p A -s wa.cpp" do
198
+ subject { lambda { call_submit(["test_dummy", "-c", "100", "-p", "A", "-s", "wa.cpp"]).run } }
199
+ it { should output(/99999/).to_stdout }
200
+ it { should output(/Wrong Answer/).to_stdout }
201
+ end
202
+ end
203
+
204
+ context "B002: submit multiple files" do
205
+ before do
206
+ File.open '1.cpp', 'w' do |file|
207
+ file.write 'wa-code'
208
+ end
209
+ File.open '2.cpp', 'w' do |file|
210
+ file.write 'ac-code'
211
+ end
212
+ end
213
+
214
+ context "git contest submit test_dummy -c 100 -p A --source 1.cpp,2.cpp" do
215
+ subject { lambda { call_submit(["test_dummy", "-c", "100", "-p", "A", "--source", "1.cpp,2.cpp"]).run } }
216
+ it { should output(/99999/).to_stdout }
217
+ it { should output(/Wrong Answer/).to_stdout }
218
+ end
219
+
220
+ context "git contest submit test_dummy -c 100 -p A --source 2.cpp,1.cpp" do
221
+ subject { lambda { call_submit(["test_dummy", "-c", "100", "-p", "A", "--source", "2.cpp,1.cpp"]).run } }
222
+ it { should output(/99999/).to_stdout }
223
+ it { should output(/Accepted/).to_stdout }
224
+ end
225
+
226
+ context "git contest submit test_dummy -c 100 -p A -s 1.cpp,2.cpp" do
227
+ subject { lambda { call_submit(["test_dummy", "-c", "100", "-p", "A", "-s", "1.cpp,2.cpp"]).run } }
228
+ it { should output(/99999/).to_stdout }
229
+ it { should output(/Wrong Answer/).to_stdout }
230
+ end
231
+
232
+ context "git contest submit test_dummy -c 100 -p A -s 2.cpp,1.cpp" do
233
+ subject { lambda { call_submit(["test_dummy", "-c", "100", "-p", "A", "-s", "2.cpp,1.cpp"]).run } }
234
+ it { should output(/99999/).to_stdout }
235
+ it { should output(/Accepted/).to_stdout }
236
+ end
237
+
238
+ context "git contest submit test_dummy -c 100 -p A -s 1.*,2.*" do
239
+ subject { lambda { call_submit(["test_dummy", "-c", "100", "-p", "A", "-s", "1.*,2.*"]).run } }
240
+ it { should output(/99999/).to_stdout }
241
+ it { should output(/Wrong Answer/).to_stdout }
242
+ end
243
+
244
+ context "git contest submit test_dummy -c 100 -p A -s 2.*,1.*" do
245
+ subject { lambda { call_submit(["test_dummy", "-c", "100", "-p", "A", "-s", "2.*,1.*"]).run } }
246
+ it { should output(/99999/).to_stdout }
247
+ it { should output(/Accepted/).to_stdout }
248
+ end
249
+ end
250
+ end
251
+ end
252
+
253
+ end # CommandLine
254
+
@@ -0,0 +1,90 @@
1
+ require "spec_helper"
2
+
3
+ describe "T005: branching" do
4
+
5
+ def call_main(args)
6
+ cli = CommandLine::MainCommand.new(args)
7
+ cli.init
8
+ cli
9
+ end
10
+
11
+ context "create config file" do
12
+
13
+ before do
14
+ ENV['GIT_CONTEST_CONFIG'] = "#{@temp_dir}/home/config.yml"
15
+ File.open ENV['GIT_CONTEST_CONFIG'], "w" do |file|
16
+ file.write <<EOF
17
+ sites:
18
+ test_dummy:
19
+ driver: dummy
20
+ user: dummy
21
+ password: dummy
22
+ EOF
23
+ end
24
+ end
25
+
26
+ context "$ git contest init" do
27
+
28
+ before { expect {call_main(["init", "--defaults"]).run}.to output("").to_stdout }
29
+ it { expect(Git.current_branch).to eq "master" }
30
+
31
+ context "$ git contest start contest1" do
32
+
33
+ before { expect {call_main(["start", "contest1"]).run}.to output(/contest1/).to_stdout }
34
+ it { expect(Git.current_branch).to eq "contest/contest1" }
35
+
36
+ context "edit main.c as wrong" do
37
+
38
+ before do
39
+ File.open 'main.c', 'w' do |file|
40
+ file.write 'wa-code'
41
+ end
42
+ end
43
+
44
+ context "$ git contest submit" do
45
+
46
+ before { expect {call_main(["submit", "test_dummy", "-c", "1000", "-p", "A"]).run}.to output(/Wrong Answer/).to_stdout }
47
+
48
+ context "fix main.c" do
49
+
50
+ before do
51
+ File.open 'main.c', 'w' do |file|
52
+ file.write 'ac-code'
53
+ end
54
+ end
55
+
56
+ context "$ git contest submit (resubmit)" do
57
+
58
+ before { expect {call_main(["submit", "test_dummy", "-c", "1000", "-p", "A"]).run}.to output(/Accepted/).to_stdout }
59
+
60
+ context "$ git contest finish" do
61
+
62
+ before { expect {call_main(["finish", "--no-edit"]).run}.to output(/contest1/).to_stdout }
63
+ it { expect(Git.current_branch).to eq "master" }
64
+
65
+ context "$ git log" do
66
+
67
+ subject { Git.do "log --oneline" }
68
+ it { should include "Dummy 1000A: Wrong Answer" }
69
+ it { should include "Dummy 1000A: Accepted" }
70
+
71
+ end # git log
72
+
73
+ end # git contest finish
74
+
75
+ end # git contest submit (resubmit)
76
+
77
+ end # fix main.c
78
+
79
+ end # git contest sbumit
80
+
81
+ end # edit main.c
82
+
83
+ end # git contest start contest1
84
+
85
+ end # git contest init
86
+
87
+ end # create config file
88
+
89
+ end # brancing
90
+
@@ -0,0 +1,95 @@
1
+ require "spec_helper"
2
+
3
+ describe "T007: git-contest-start" do
4
+
5
+ def call_main(args)
6
+ cli = CommandLine::MainCommand.new(args)
7
+ cli.init
8
+ cli
9
+ end
10
+
11
+ context "A001: specify based branch" do
12
+ before do
13
+ expect { call_main(["init", "--defaults"]).run }.to output(/.*/).to_stdout
14
+ end
15
+
16
+ it "001" do
17
+ Git.do "checkout -b base1"
18
+ Git.do "commit --allow-empty -m \"this is commit\""
19
+ Git.do "checkout master"
20
+ expect { call_main(["start", "test1"]).run }.to output(/.*/).to_stdout
21
+ ret1 = Git.do "log --oneline"
22
+ expect(ret1).not_to include "this is commit"
23
+ expect { call_main(["start", "test2", "base1"]).run }.to output(/.*/).to_stdout
24
+ ret2 = Git.do "log --oneline"
25
+ expect(ret2).to include "this is commit"
26
+ end
27
+
28
+ it "002" do
29
+ Git.do "checkout -b base1"
30
+ Git.do "commit --allow-empty -m \"this is commit\""
31
+ Git.do "checkout master"
32
+ expect { call_main(["start", "test1", "base1"]).run }.to output(/.*/).to_stdout
33
+ ret1 = Git.do "log --oneline"
34
+ expect(ret1).to include "this is commit"
35
+ expect { call_main(["start", "test2"]).run }.to output(/.*/).to_stdout
36
+ ret2 = Git.do "log --oneline"
37
+ expect(ret2).not_to include "this is commit"
38
+ end
39
+
40
+ it "003" do
41
+ Git.do "checkout -b base1"
42
+ Git.do "commit --allow-empty -m \"this is commit\""
43
+ expect { call_main(["start", "test1", "base1"]).run }.to output(/.*/).to_stdout
44
+ ret1 = Git.do "log --oneline"
45
+ expect(ret1).to include "this is commit"
46
+ expect { call_main(["start", "test2"]).run }.to output(/.*/).to_stdout
47
+ ret2 = Git.do "log --oneline"
48
+ expect(ret2).not_to include "this is commit"
49
+ end
50
+
51
+ it "004" do
52
+ Git.do "checkout -b base1"
53
+ Git.do "commit --allow-empty -m \"this is commit\""
54
+ expect { call_main(["start", "test1"]).run }.to output(/.*/).to_stdout
55
+ ret1 = Git.do "log --oneline"
56
+ expect(ret1).not_to include "this is commit"
57
+ expect { call_main(["start", "test2", "base1"]).run }.to output(/.*/).to_stdout
58
+ ret2 = Git.do "log --oneline"
59
+ expect(ret2).to include "this is commit"
60
+ end
61
+ end
62
+
63
+ context "A002: --fetch" do
64
+ it "001" do
65
+ Dir.mkdir "test1"
66
+ Dir.chdir "test1"
67
+ expect { call_main(["init", "--defaults"]).run }.to output(/.*/).to_stdout
68
+ expect { call_main(["start", "branch1"]).run }.to output(/.*/).to_stdout
69
+ Dir.chdir ".."
70
+ Git.do "clone -b master test1 test2"
71
+ Dir.chdir "test1"
72
+ 3.times {|x| Git.do "commit --allow-empty -m \"this is commit\"" }
73
+ ret1 = Git.do "log --oneline"
74
+ expect(ret1).to include "this is commit"
75
+
76
+ Dir.chdir ".."
77
+ Dir.chdir "test2"
78
+ # init
79
+ expect { call_main(["init", "--defaults"]).run }.to output(/.*/).to_stdout
80
+ # fetch
81
+ ret2 = Git.do "log --oneline origin/master"
82
+ expect(ret2).not_to include "this is commit"
83
+
84
+ # TODO: support: start branch1 --fetch
85
+ expect { call_main(["start", "--fetch", "branch1"]).run }.to output(/.*/).to_stdout
86
+
87
+ ret3 = Git.do "log --oneline"
88
+ expect(ret3).to_not include "this is commit"
89
+
90
+ Git.do "pull origin master"
91
+ expect { call_main(["start", "--fetch", "branch2"]).run }.to output(/Summary of actions/).to_stdout
92
+ end
93
+ end
94
+ end
95
+