3 # Copyright (c) 2013 Felipe Contreras
6 test_description='test ruby support'
10 if ! test_have_prereq RUBY
12 skip_all='skipping ruby tests'
16 test_expect_success 'basic support' '
17 git ruby > actual <<-EOF &&
20 echo "hello world" > expected &&
21 test_cmp expected actual
24 test_expect_success 'argument passing' '
25 cat > script <<-"EOF" &&
29 git ruby script foo bar > actual &&
30 cat > expected <<-EOF &&
34 test_cmp expected actual
37 test_expect_success 'test for_each_ref()' '
39 git ruby > actual <<-EOF &&
40 for_each_ref() do |name, sha1, flags|
41 puts "%s: %s" % [name, sha1_to_hex(sha1)]
44 git for-each-ref --format="%(refname): %(objectname)" > expected &&
45 test_cmp expected actual
48 test_expect_success 'test setup_git_directory()' '
52 git ruby > ../actual <<-EOF
53 prefix, nongit_ok = setup_git_directory()
57 echo "t/" > expected &&
58 test_cmp expected actual
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
66 git rev-parse -q --verify HEAD > expected &&
68 git rev-parse -q --verify --symbolic-full-name HEAD >> expected &&
69 test_cmp expected actual
72 test_expect_success 'test git_config()' '
73 git ruby > actual <<-EOF &&
74 git_config() do |key, value|
75 puts "%s=%s" % [key, value]
78 git config --list > expected &&
79 test_cmp expected actual
82 test_expect_success 'test get_sha1()' '
83 git ruby > actual <<-EOF &&
84 puts sha1_to_hex(get_sha1("HEAD"))
86 git rev-parse -q --verify HEAD > expected &&
87 test_cmp expected actual
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)
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
101 test_expect_success 'test Commit' '
102 git ruby > actual <<-EOF &&
103 commit = Git::Commit.get(get_sha1("HEAD"))
104 puts commit, commit.buffer
106 git rev-parse -q --verify HEAD > expected &&
107 git cat-file commit HEAD >> expected &&
108 test_cmp expected actual
111 test_expect_success 'test ParseOpt' '
112 cat > parse-script <<"EOF"
118 opts.usage = "git foo"
120 opts.on("b", "bool", help: "Boolean") do |v|
124 opts.on("s", "string", help: "String") do |v|
128 opts.on("n", "number", help: "Number") do |v|
135 p({ :bool => $bool, :str => $str, :num => $num })
138 git ruby parse-script > actual &&
139 cat > expected <<-EOF &&
141 {:bool=>false, :str=>"default", :num=>0}
143 test_cmp expected actual &&
145 git ruby parse-script --bool > actual &&
146 cat > expected <<-EOF &&
148 {:bool=>true, :str=>"default", :num=>0}
150 test_cmp expected actual &&
152 git ruby parse-script -b > actual &&
153 cat > expected <<-EOF &&
155 {:bool=>true, :str=>"default", :num=>0}
157 test_cmp expected actual &&
159 git ruby parse-script --string=foo > actual &&
160 cat > expected <<-EOF &&
162 {:bool=>false, :str=>"foo", :num=>0}
164 test_cmp expected actual &&
166 git ruby parse-script -sfoo > actual &&
167 cat > expected <<-EOF &&
169 {:bool=>false, :str=>"foo", :num=>0}
171 test_cmp expected actual &&
173 git ruby parse-script --number=10 > actual &&
174 cat > expected <<-EOF &&
176 {:bool=>false, :str=>"default", :num=>10}
178 test_cmp expected actual &&
180 git ruby parse-script --bool --string=bar --number=-20 > actual &&
181 cat > expected <<-EOF &&
183 {:bool=>true, :str=>"bar", :num=>-20}
185 test_cmp expected actual &&
187 git ruby parse-script --help > actual &&
188 cat > expected <<-EOF &&
194 test_cmp expected actual &&
196 git ruby parse-script --help > actual &&
197 cat > expected <<-EOF &&
203 test_cmp expected actual &&
205 test_must_fail git ruby parse-script --bad > actual &&
206 cat > expected <<-EOF &&
212 test_cmp expected actual &&
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}
219 test_cmp expected actual &&
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}
226 test_cmp expected actual &&
228 git ruby parse-script one --bool --no-bool > actual &&
229 cat > expected <<-EOF &&
231 {:bool=>false, :str=>"default", :num=>0}
234 test_cmp expected actual