test: remove httpd tests that ask for user
[git] / t / t9710-ruby.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2013 Felipe Contreras
4 #
5
6 test_description='test ruby support'
7
8 . ./test-lib.sh
9
10 if ! test_have_prereq RUBY
11 then
12         skip_all='skipping ruby tests'
13         test_done
14 fi
15
16 test_expect_success 'basic support' '
17         git ruby > actual <<-EOF &&
18         puts "hello world"
19         EOF
20         echo "hello world" > expected &&
21         test_cmp expected actual
22 '
23
24 test_expect_success 'argument passing' '
25         cat > script <<-"EOF" &&
26         p($0)
27         p(ARGV)
28         EOF
29         git ruby script foo bar > actual &&
30         cat > expected <<-EOF &&
31         "script"
32         ["foo", "bar"]
33         EOF
34         test_cmp expected actual
35 '
36
37 test_expect_success 'test for_each_ref()' '
38         test_commit foo &&
39         git ruby > actual <<-EOF &&
40         for_each_ref() do |name, sha1, flags|
41                 puts "%s: %s" % [name, sha1_to_hex(sha1)]
42         end
43         EOF
44         git for-each-ref --format="%(refname): %(objectname)" > expected &&
45         test_cmp expected actual
46 '
47
48 test_expect_success 'test setup_git_directory()' '
49         mkdir t &&
50         (
51         cd t &&
52         git ruby > ../actual <<-EOF
53         prefix, nongit_ok = setup_git_directory()
54         puts prefix
55         EOF
56         ) &&
57         echo "t/" > expected &&
58         test_cmp expected actual
59 '
60
61 test_expect_success 'test dwim_ref()' '
62         git ruby > actual <<-EOF &&
63         sha1, num, ref = dwim_ref("HEAD")
64         puts sha1_to_hex(sha1), num, ref
65         EOF
66         git rev-parse -q --verify HEAD > expected &&
67         echo 1 >> expected &&
68         git rev-parse -q --verify --symbolic-full-name HEAD >> expected &&
69         test_cmp expected actual
70 '
71
72 test_expect_success 'test git_config()' '
73         git ruby > actual <<-EOF &&
74         git_config() do |key, value|
75           puts "%s=%s" % [key, value]
76         end
77         EOF
78         git config --list > expected &&
79         test_cmp expected actual
80 '
81
82 test_expect_success 'test get_sha1()' '
83         git ruby > actual <<-EOF &&
84         puts sha1_to_hex(get_sha1("HEAD"))
85         EOF
86         git rev-parse -q --verify HEAD > expected &&
87         test_cmp expected actual
88 '
89
90 test_expect_success 'test Object' '
91         git ruby > actual <<-EOF &&
92         object = Git::Object.get(get_sha1("HEAD"))
93         puts object, object.type == OBJ_COMMIT, sha1_to_hex(object.sha1)
94         EOF
95         git rev-parse -q --verify HEAD > expected &&
96         echo "true" >> expected &&
97         git rev-parse -q --verify HEAD >> expected &&
98         test_cmp expected actual
99 '
100
101 test_expect_success 'test Commit' '
102         git ruby > actual <<-EOF &&
103         commit = Git::Commit.get(get_sha1("HEAD"))
104         puts commit, commit.buffer
105         EOF
106         git rev-parse -q --verify HEAD > expected &&
107         git cat-file commit HEAD >> expected &&
108         test_cmp expected actual
109 '
110
111 test_expect_success 'test ParseOpt' '
112         cat > parse-script <<"EOF"
113         $str = "default"
114         $num = 0
115         $bool = false
116
117         opts = ParseOpt.new
118         opts.usage = "git foo"
119
120         opts.on("b", "bool", help: "Boolean") do |v|
121           $bool = v
122         end
123
124         opts.on("s", "string", help: "String") do |v|
125           $str = v
126         end
127
128         opts.on("n", "number", help: "Number") do |v|
129           $num = v.to_i
130         end
131
132         opts.parse
133
134         p(ARGV)
135         p({ :bool => $bool, :str => $str, :num => $num })
136         EOF
137
138         git ruby parse-script > actual &&
139         cat > expected <<-EOF &&
140         []
141         {:bool=>false, :str=>"default", :num=>0}
142         EOF
143         test_cmp expected actual &&
144
145         git ruby parse-script --bool > actual &&
146         cat > expected <<-EOF &&
147         []
148         {:bool=>true, :str=>"default", :num=>0}
149         EOF
150         test_cmp expected actual &&
151
152         git ruby parse-script -b > actual &&
153         cat > expected <<-EOF &&
154         []
155         {:bool=>true, :str=>"default", :num=>0}
156         EOF
157         test_cmp expected actual &&
158
159         git ruby parse-script --string=foo > actual &&
160         cat > expected <<-EOF &&
161         []
162         {:bool=>false, :str=>"foo", :num=>0}
163         EOF
164         test_cmp expected actual &&
165
166         git ruby parse-script -sfoo > actual &&
167         cat > expected <<-EOF &&
168         []
169         {:bool=>false, :str=>"foo", :num=>0}
170         EOF
171         test_cmp expected actual &&
172
173         git ruby parse-script --number=10 > actual &&
174         cat > expected <<-EOF &&
175         []
176         {:bool=>false, :str=>"default", :num=>10}
177         EOF
178         test_cmp expected actual &&
179
180         git ruby parse-script --bool --string=bar --number=-20 > actual &&
181         cat > expected <<-EOF &&
182         []
183         {:bool=>true, :str=>"bar", :num=>-20}
184         EOF
185         test_cmp expected actual &&
186
187         git ruby parse-script --help > actual &&
188         cat > expected <<-EOF &&
189         usage: git foo
190             -b, --bool            Boolean
191             -s, --string          String
192             -n, --number          Number
193         EOF
194         test_cmp expected actual &&
195
196         git ruby parse-script --help > actual &&
197         cat > expected <<-EOF &&
198         usage: git foo
199             -b, --bool            Boolean
200             -s, --string          String
201             -n, --number          Number
202         EOF
203         test_cmp expected actual &&
204
205         test_must_fail git ruby parse-script --bad > actual &&
206         cat > expected <<-EOF &&
207         usage: git foo
208             -b, --bool            Boolean
209             -s, --string          String
210             -n, --number          Number
211         EOF
212         test_cmp expected actual &&
213
214         git ruby parse-script one --bool two --string=bar three --number=-20 mambo > actual &&
215         cat > expected <<-EOF &&
216         ["one", "two", "three", "mambo"]
217         {:bool=>true, :str=>"bar", :num=>-20}
218         EOF
219         test_cmp expected actual &&
220
221         git ruby parse-script one --bool two -- --three four > actual &&
222         cat > expected <<-EOF &&
223         ["one", "two", "--three", "four"]
224         {:bool=>true, :str=>"default", :num=>0}
225         EOF
226         test_cmp expected actual &&
227
228         git ruby parse-script one --bool --no-bool > actual &&
229         cat > expected <<-EOF &&
230         ["one"]
231         {:bool=>false, :str=>"default", :num=>0}
232         EOF
233         cat actual
234         test_cmp expected actual
235 '
236
237 test_done