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
@@ -1,223 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "T004: git-contest-submit command" do
4
- before do
5
- ENV['GIT_CONTEST_CONFIG'] = "#{@temp_dir}/config.yml"
6
- File.open "#{@temp_dir}/config.yml", 'w' do |file|
7
- file.write <<EOF
8
- sites:
9
- test_dummy:
10
- driver: dummy
11
- user: dummy
12
- password: dummy
13
- test_11111:
14
- driver: codeforces
15
- user: dummy
16
- password: dummy
17
- test_22222:
18
- driver: aizu_online_judge
19
- user: dummy
20
- password: dummy
21
- test_33333:
22
- driver: uva_online_judge
23
- user: dummy
24
- password: dummy
25
- EOF
26
- end
27
- end
28
-
29
- context "A001: --version" do
30
- it "git-contest-submit --version" do
31
- ret = `#{bin_path("git-contest-submit")} --version`
32
- expect(ret).to match /git-contest [0-9]+\.[0-9]+\.[0-9]+/
33
- end
34
-
35
- it "git-contest submit --version" do
36
- ret = `#{bin_path("git-contest submit")} --version`
37
- expect(ret).to match /git-contest [0-9]+\.[0-9]+\.[0-9]+/
38
- end
39
-
40
- it "git contest submit --version" do
41
- ret = `git contest submit --version`
42
- expect(ret).to match /git-contest [0-9]+\.[0-9]+\.[0-9]+/
43
- end
44
- end
45
-
46
- context "A002: --help" do
47
- before do
48
- Dir.mkdir 'working'
49
- Dir.chdir 'working'
50
- File.open 'main.cpp', 'w' do |file|
51
- file.write 'ac-code'
52
- end
53
- end
54
-
55
- context "B001: dummy driver available only test-mode" do
56
- it "git-contest-submit --help" do
57
- ret = `#{bin_path('git-contest-submit')} --help`
58
- expect(ret).to include 'test_dummy'
59
- expect(ret).to include 'test_11111'
60
- expect(ret).to include 'test_22222'
61
- expect(ret).to include 'test_33333'
62
- end
63
- end
64
- end
65
-
66
- context "A003: after init git repo" do
67
- before do
68
- Dir.mkdir 'working'
69
- Dir.chdir 'working'
70
- File.open 'main.cpp', 'w' do |file|
71
- file.write 'ac-code'
72
- end
73
- end
74
-
75
- before do
76
- `#{bin_path("git-contest")} init --defaults`
77
- end
78
-
79
- it "git-contest-submit test_dummy -c 100 -p A" do
80
- ret_submit = `#{bin_path("git-contest-submit")} test_dummy -c 100 -p A 2>&1`
81
- expect(ret_submit).to include '99999'
82
- expect(ret_submit).to include 'Accepted'
83
- ret_git = `git log --oneline --decorate --graph`
84
- expect(ret_git).to include "Dummy 100A: Accepted"
85
- end
86
- end
87
-
88
- context "A004: with commit message" do
89
- before do
90
- Dir.mkdir 'working'
91
- Dir.chdir 'working'
92
- File.open 'main.cpp', 'w' do |file|
93
- file.write 'ac-code'
94
- end
95
- end
96
-
97
- before do
98
- bin_exec "init --defaults"
99
- end
100
-
101
- it "git contest submit test_dummy -c 100 -p A -m '...'" do
102
- bin_exec "submit test_dummy -c 100 -p A -m 'this is commit message'"
103
- ret = git_do "log --oneline"
104
- expect(ret).to include "this is commit message"
105
- end
106
- end
107
-
108
- context 'A005: normal submit' do
109
- before do
110
- Dir.mkdir 'working'
111
- Dir.chdir 'working'
112
- File.open 'main.cpp', 'w' do |file|
113
- file.write 'ac-code'
114
- end
115
- end
116
-
117
- it "git-contest-submit test_dummy" do
118
- ret = `#{bin_path('git-contest-submit')} test_dummy 2>&1`
119
- expect(ret).to include 'Error'
120
- end
121
-
122
- it "git-contest-submit test_dummy -c 100" do
123
- ret = `#{bin_path('git-contest-submit')} test_dummy -c 100 2>&1`
124
- expect(ret).to include 'Error'
125
- end
126
-
127
- it "git-contest-submit test_dummy -c 100 -p A" do
128
- ret = `#{bin_path('git-contest-submit')} test_dummy -c 100 -p A 2>&1`
129
- expect(ret).to include '99999'
130
- expect(ret).to include 'Accepted'
131
- end
132
- end
133
-
134
- context 'A006: --source' do
135
- before do
136
- Dir.mkdir 'working'
137
- Dir.chdir 'working'
138
- end
139
-
140
- context "B001: submit single file" do
141
- before do
142
- File.open 'ac.cpp', 'w' do |file|
143
- file.write 'ac-code'
144
- end
145
- File.open 'wa.cpp', 'w' do |file|
146
- file.write 'wa-code'
147
- end
148
- end
149
-
150
- it "git contest submit test_dummy -c 100 -p A --source ac.cpp" do
151
- ret = bin_exec "submit test_dummy -c 100 -p A --source ac.cpp"
152
- expect(ret).to include '99999'
153
- expect(ret).to include 'Accepted'
154
- end
155
-
156
- it "git contest submit test_dummy -c 100 -p A -s ac.cpp" do
157
- ret = bin_exec "submit test_dummy -c 100 -p A -s ac.cpp"
158
- expect(ret).to include '99999'
159
- expect(ret).to include 'Accepted'
160
- end
161
-
162
- it "git contest submit test_dummy -c 100 -p A --source wa.cpp" do
163
- ret = bin_exec "submit test_dummy -c 100 -p A --source wa.cpp"
164
- expect(ret).to include '99999'
165
- expect(ret).to include 'Wrong Answer'
166
- end
167
-
168
- it "git contest submit test_dummy -c 100 -p A -s wa.cpp" do
169
- ret = bin_exec "submit test_dummy -c 100 -p A -s wa.cpp"
170
- expect(ret).to include '99999'
171
- expect(ret).to include 'Wrong Answer'
172
- end
173
- end
174
-
175
- context "B002: submit multiple files" do
176
- before do
177
- File.open '1.cpp', 'w' do |file|
178
- file.write 'wa-code'
179
- end
180
- File.open '2.cpp', 'w' do |file|
181
- file.write 'ac-code'
182
- end
183
- end
184
-
185
- it "git contest submit test_dummy -c 100 -p A --source 1.cpp,2.cpp" do
186
- ret = bin_exec "submit test_dummy -c 100 -p A --source 1.cpp,2.cpp"
187
- expect(ret).to include '99999'
188
- expect(ret).to include 'Wrong Answer'
189
- end
190
-
191
- it "git contest submit test_dummy -c 100 -p A --source 2.cpp,1.cpp" do
192
- ret = bin_exec "submit test_dummy -c 100 -p A --source 2.cpp,1.cpp"
193
- expect(ret).to include '99999'
194
- expect(ret).to include 'Accepted'
195
- end
196
-
197
- it "git contest submit test_dummy -c 100 -p A -s 1.cpp,2.cpp" do
198
- ret = bin_exec "submit test_dummy -c 100 -p A -s 1.cpp,2.cpp"
199
- expect(ret).to include '99999'
200
- expect(ret).to include 'Wrong Answer'
201
- end
202
-
203
- it "git contest submit test_dummy -c 100 -p A -s 2.cpp,1.cpp" do
204
- ret = bin_exec "submit test_dummy -c 100 -p A -s 2.cpp,1.cpp"
205
- expect(ret).to include '99999'
206
- expect(ret).to include 'Accepted'
207
- end
208
-
209
- it "git contest submit test_dummy -c 100 -p A -s 1.*,2.*" do
210
- ret = bin_exec "submit test_dummy -c 100 -p A -s 1.*,2.*"
211
- expect(ret).to include '99999'
212
- expect(ret).to include 'Wrong Answer'
213
- end
214
-
215
- it "git contest submit test_dummy -c 100 -p A -s 2.*,1.*" do
216
- ret = bin_exec "submit test_dummy -c 100 -p A -s 2.*,1.*"
217
- expect(ret).to include '99999'
218
- expect(ret).to include 'Accepted'
219
- end
220
- end
221
- end
222
- end
223
-
@@ -1,70 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "T005: branching" do
4
- context "A001" do
5
- before do
6
- ENV['GIT_CONTEST_CONFIG'] = "#{@temp_dir}/home/config.yml"
7
- File.open ENV['GIT_CONTEST_CONFIG'], "w" do |file|
8
- file.write <<EOF
9
- sites:
10
- test_dummy:
11
- driver: dummy
12
- user: dummy
13
- password: dummy
14
- EOF
15
- end
16
- end
17
-
18
- context 'B001' do
19
- it '001: init -> start -> submit -> submit -> finish' do
20
- Dir.mkdir 'test1'
21
- Dir.chdir 'test1'
22
-
23
- # Init
24
- bin_exec "init --defaults"
25
- expect(git_current_branch).to eq 'master'
26
- ret = git_do "log --oneline"
27
- expect(ret).to include 'Initial commit'
28
-
29
- # Start
30
- bin_exec "start contest1"
31
- expect(git_current_branch).to eq 'contest/contest1'
32
-
33
- # Edit.1
34
- File.open 'main.c', 'w' do |file|
35
- file.write 'wa-code'
36
- end
37
-
38
- # Submit.1
39
- bin_exec "submit test_dummy -c 1000 -p A"
40
- ret = git_do "log --oneline"
41
- expect(ret).to include 'Dummy 1000A: Wrong Answer'
42
-
43
- ret = git_do "ls-files"
44
- expect(ret).to include 'main.c'
45
-
46
- # Edit.2 fixed
47
- File.open 'main.c', 'w' do |file|
48
- file.write 'ac-code'
49
- end
50
-
51
- # Submit.2
52
- bin_exec "submit test_dummy -c 1000 -p A"
53
- ret = git_do "log --oneline"
54
- expect(ret).to include 'Dummy 1000A: Accepted'
55
-
56
- ret = git_do "ls-files"
57
- expect(ret).to include 'main.c'
58
-
59
- # Finish
60
- bin_exec "finish --no-edit"
61
- expect(git_current_branch).to eq 'master'
62
-
63
- ret = git_do "log --oneline"
64
- expect(ret).to include 'Dummy 1000A: Wrong Answer'
65
- expect(ret).to include 'Dummy 1000A: Accepted'
66
- end
67
- end
68
- end
69
- end
70
-
@@ -1,88 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "T007: git-contest-start" do
4
- context "A001: specify based branch" do
5
- before do
6
- bin_exec "init --defaults"
7
- end
8
-
9
- it "001" do
10
- git_do "checkout -b base1"
11
- git_do "commit --allow-empty -m 'this is commit'"
12
- git_do "checkout master"
13
- bin_exec "start test1"
14
- ret1 = git_do "log --oneline"
15
- expect(ret1).not_to include "this is commit"
16
- bin_exec "start test2 base1"
17
- ret2 = git_do "log --oneline"
18
- expect(ret2).to include "this is commit"
19
- end
20
-
21
- it "002" do
22
- git_do "checkout -b base1"
23
- git_do "commit --allow-empty -m 'this is commit'"
24
- git_do "checkout master"
25
- bin_exec "start test1 base1"
26
- ret1 = git_do "log --oneline"
27
- expect(ret1).to include "this is commit"
28
- bin_exec "start test2"
29
- ret2 = git_do "log --oneline"
30
- expect(ret2).not_to include "this is commit"
31
- end
32
-
33
- it "003" do
34
- git_do "checkout -b base1"
35
- git_do "commit --allow-empty -m 'this is commit'"
36
- bin_exec "start test1 base1"
37
- ret1 = git_do "log --oneline"
38
- expect(ret1).to include "this is commit"
39
- bin_exec "start test2"
40
- ret2 = git_do "log --oneline"
41
- expect(ret2).not_to include "this is commit"
42
- end
43
-
44
- it "004" do
45
- git_do "checkout -b base1"
46
- git_do "commit --allow-empty -m 'this is commit'"
47
- bin_exec "start test1"
48
- ret1 = git_do "log --oneline"
49
- expect(ret1).not_to include "this is commit"
50
- bin_exec "start test2 base1"
51
- ret2 = git_do "log --oneline"
52
- expect(ret2).to include "this is commit"
53
- end
54
- end
55
-
56
- context "A002: --fetch" do
57
- it "001" do
58
- Dir.mkdir "test1"
59
- Dir.chdir "test1"
60
- bin_exec "init --defaults"
61
- Dir.chdir ".."
62
- git_do "clone test1 test2"
63
- Dir.chdir "test1"
64
- 10.times {|x| git_do "commit --allow-empty -m 'this is commit'" }
65
- ret1 = git_do "log --oneline master"
66
- expect(ret1).to include "this is commit"
67
-
68
- Dir.chdir ".."
69
- Dir.chdir "test2"
70
- # init
71
- bin_exec "init --defaults"
72
- # fetch
73
- ret2 = git_do "log --oneline origin/master"
74
- expect(ret2).not_to include "this is commit"
75
-
76
- ret_start1 = bin_exec "start branch1 --fetch"
77
- expect(ret_start1).not_to include "Summary of actions:"
78
-
79
- ret3 = git_do "log --oneline origin/master"
80
- expect(ret3).to include "this is commit"
81
-
82
- git_do "pull origin master"
83
- ret_start2 = bin_exec "start branch2 --fetch"
84
- expect(ret_start2).to include "Summary of actions:"
85
- end
86
- end
87
- end
88
-
@@ -1,162 +0,0 @@
1
- require "spec_helper"
2
-
3
- # Do not forget --no-edit option
4
-
5
- describe "T008: git-contest-finish" do
6
- context "A001: --keep" do
7
- it "001: init -> start -> empty-commits -> finish" do
8
- bin_exec "init --defaults"
9
- bin_exec "start branch1"
10
- git_do "commit --allow-empty -m 'this is commit'"
11
- bin_exec "finish --no-edit"
12
- ret1 = git_do "branch"
13
- ret_log1 = git_do "log --oneline master"
14
- expect(ret1).not_to include "branch1"
15
- expect(ret_log1).to include "this is commit"
16
- end
17
-
18
- it "002: init -> start -> empty-commits -> finish --keep" do
19
- bin_exec "init --defaults"
20
- bin_exec "start branch1"
21
- git_do "commit --allow-empty -m 'this is commit'"
22
- bin_exec "finish --no-edit --keep"
23
- ret1 = git_do "branch"
24
- ret_log1 = git_do "log --oneline master"
25
- expect(ret1).to include "branch1"
26
- expect(ret_log1).to include "this is commit"
27
- end
28
-
29
- it "003: init -> start -> empty-commits -> finish -k" do
30
- bin_exec "init --defaults"
31
- bin_exec "start branch1"
32
- git_do "commit --allow-empty -m 'this is commit'"
33
- bin_exec "finish --no-edit -k"
34
- ret1 = git_do "branch"
35
- ret_log1 = git_do "log --oneline master"
36
- expect(ret1).to include "branch1"
37
- expect(ret_log1).to include "this is commit"
38
- end
39
-
40
- end
41
-
42
- context "A002: --rebase" do
43
- it "001: init -> start -> empty-commits -> finish --rebase" do
44
- # create branches: branch1(normal) -> branch2(rebase) -> branch3(normal)
45
- bin_exec "init --defaults"
46
- bin_exec "start branch1"
47
- 10.times {|x|
48
- name = "test-1.#{x}"
49
- FileUtils.touch name
50
- git_do "add #{name}"
51
- git_do "commit -m 'Add #{name}'"
52
- }
53
- bin_exec "start branch2"
54
- 10.times {|x|
55
- name = "test-2.#{x}"
56
- FileUtils.touch name
57
- git_do "add #{name}"
58
- git_do "commit -m 'Add #{name}'"
59
- }
60
- bin_exec "start branch3"
61
- 10.times {|x|
62
- name = "test-3.#{x}"
63
- FileUtils.touch name
64
- git_do "add #{name}"
65
- git_do "commit -m 'Add #{name}'"
66
- }
67
- # finish branches
68
- ret_branch_1 = git_do "branch"
69
- bin_exec "finish branch1 --no-edit"
70
- bin_exec "finish branch2 --no-edit --rebase"
71
- bin_exec "finish branch3 --no-edit"
72
- ret_branch_2 = git_do "branch"
73
- ret_log = git_do "log --oneline"
74
- expect(ret_branch_1).to include "branch1"
75
- expect(ret_branch_1).to include "branch2"
76
- expect(ret_branch_1).to include "branch3"
77
- expect(ret_branch_2).not_to include "branch1"
78
- expect(ret_branch_2).not_to include "branch2"
79
- expect(ret_branch_2).not_to include "branch3"
80
- (!!ret_log.match(/test-2.*test-3.*test-1/m)).should === true
81
- end
82
-
83
- end
84
-
85
- context "A003: --force-delete" do
86
- # TODO: recheck
87
- it "001: init -> start -> trigger merge error -> finish --force-delete" do
88
- # make conflict
89
- bin_exec "init --defaults"
90
- FileUtils.touch "test.txt"
91
- git_do "add test.txt"
92
- git_do "commit -m 'Add test.txt'"
93
- bin_exec "start branch1"
94
- bin_exec "start branch2"
95
- git_do "checkout contest/branch1"
96
- File.open "test.txt", "w" do |file|
97
- file.write "test1"
98
- end
99
- # git_do "add test.txt"
100
- # git_do "commit -m 'Edit test.txt @ branch1'"
101
- git_do "checkout contest/branch2"
102
- File.open "test.txt", "w" do |file|
103
- file.write "test2"
104
- end
105
- git_do "add test.txt"
106
- git_do "commit -m 'Edit test.txt @ branch2'"
107
- # finish
108
- bin_exec "finish branch1 --no-edit"
109
- bin_exec "finish branch2 --force-delete --no-edit"
110
- ret_branch = git_do "branch"
111
- expect(ret_branch).not_to include "contest/branch1"
112
- expect(ret_branch).not_to include "contest/branch2"
113
- end
114
- end
115
-
116
- context "A004: --squash" do
117
- it "001: init -> start -> empty-commits -> finish --squash" do
118
- bin_exec "init --defaults"
119
- bin_exec "start branch1"
120
- 10.times {|x|
121
- filename = "test#{x}.txt"
122
- FileUtils.touch filename
123
- git_do "add #{filename}"
124
- git_do "commit -m 'this is commit #{x}'"
125
- }
126
- bin_exec "finish --no-edit --squash branch1"
127
- ret_log1 = git_do "log --oneline"
128
- ret_branch1 = git_do "branch"
129
- expect(ret_branch1).not_to include "branch1"
130
- expect(ret_log1).to include "this is commit"
131
- expect(ret_log1).to include "Squashed commit"
132
- end
133
- end
134
-
135
- context "A005: --fetch" do
136
- before do
137
- Dir.mkdir "src"
138
- Dir.chdir "src"
139
- bin_exec "init --defaults"
140
- bin_exec "start branch1"
141
- 10.times {|x| git_do "commit --allow-empty -m 'this is commit #{x}'" }
142
- Dir.chdir ".."
143
- git_do "clone src dest"
144
- Dir.chdir "dest"
145
- end
146
-
147
- it "001: init -> start -> clone -> checkout@dest -> empty-commits@dest -> finish@dest" do
148
- git_do "checkout -b master origin/master"
149
- bin_exec "init --defaults"
150
- bin_exec "start --fetch branch1"
151
- bin_exec "finish --fetch branch1 --no-edit"
152
- ret_branch2 = git_do "branch"
153
- Dir.chdir ".."
154
- Dir.chdir "src"
155
- ret_branch1 = git_do "branch"
156
- git_do "checkout master"
157
- expect(ret_branch1).to include 'branch1'
158
- expect(ret_branch2).not_to include 'branch1'
159
- end
160
- end
161
- end
162
-