3 # Copyright (c) 2013 Felipe Contreras
6 test_description='test ruby support'
10 test_expect_success 'basic support' '
11 git ruby > actual <<-EOF &&
14 echo "hello world" > expected &&
15 test_cmp expected actual
18 test_expect_success 'argument passing' '
19 cat > script <<-"EOF" &&
23 git ruby script foo bar > actual &&
24 cat > expected <<-EOF &&
28 test_cmp expected actual
31 test_expect_success 'test for_each_ref()' '
33 git ruby > actual <<-EOF &&
34 for_each_ref() do |name, sha1, flags|
35 puts "%s: %s" % [name, sha1_to_hex(sha1)]
38 git for-each-ref --format="%(refname): %(objectname)" > expected &&
39 test_cmp expected actual
42 test_expect_success 'test setup_git_directory()' '
46 git ruby > ../actual <<-EOF
47 prefix, nongit_ok = setup_git_directory()
51 echo "t/" > expected &&
52 test_cmp expected actual
55 test_expect_success 'test dwim_ref()' '
56 git ruby > actual <<-EOF &&
57 sha1, num, ref = dwim_ref("HEAD")
58 puts sha1_to_hex(sha1), num, ref
60 git rev-parse -q --verify HEAD > expected &&
62 git rev-parse -q --verify --symbolic-full-name HEAD >> expected &&
63 test_cmp expected actual
66 test_expect_success 'test git_config()' '
67 git ruby > actual <<-EOF &&
68 git_config() do |key, value|
69 puts "%s=%s" % [key, value]
72 git config --list > expected &&
73 test_cmp expected actual
76 test_expect_success 'test get_sha1()' '
77 git ruby > actual <<-EOF &&
78 puts sha1_to_hex(get_sha1("HEAD"))
80 git rev-parse -q --verify HEAD > expected &&
81 test_cmp expected actual
84 test_expect_success 'test Object' '
85 git ruby > actual <<-EOF &&
86 object = Git::Object.get(get_sha1("HEAD"))
87 puts object, object.type == OBJ_COMMIT, sha1_to_hex(object.sha1)
89 git rev-parse -q --verify HEAD > expected &&
90 echo "true" >> expected &&
91 git rev-parse -q --verify HEAD >> expected &&
92 test_cmp expected actual
95 test_expect_success 'test Commit' '
96 git ruby > actual <<-EOF &&
97 commit = Git::Commit.get(get_sha1("HEAD"))
98 puts commit, commit.buffer
100 git rev-parse -q --verify HEAD > expected &&
101 git cat-file commit HEAD >> expected &&
102 test_cmp expected actual
105 test_expect_success 'test ParseOpt' '
106 cat > parse-script <<"EOF"
112 opts.usage = "git foo"
114 opts.on("b", "bool", help: "Boolean") do |v|
118 opts.on("s", "string", help: "String") do |v|
122 opts.on("n", "number", help: "Number") do |v|
129 p({ :bool => $bool, :str => $str, :num => $num })
132 git ruby parse-script > actual &&
133 cat > expected <<-EOF &&
135 {:bool=>false, :str=>"default", :num=>0}
137 test_cmp expected actual &&
139 git ruby parse-script --bool > actual &&
140 cat > expected <<-EOF &&
142 {:bool=>true, :str=>"default", :num=>0}
144 test_cmp expected actual &&
146 git ruby parse-script -b > actual &&
147 cat > expected <<-EOF &&
149 {:bool=>true, :str=>"default", :num=>0}
151 test_cmp expected actual &&
153 git ruby parse-script --string=foo > actual &&
154 cat > expected <<-EOF &&
156 {:bool=>false, :str=>"foo", :num=>0}
158 test_cmp expected actual &&
160 git ruby parse-script -sfoo > actual &&
161 cat > expected <<-EOF &&
163 {:bool=>false, :str=>"foo", :num=>0}
165 test_cmp expected actual &&
167 git ruby parse-script --number=10 > actual &&
168 cat > expected <<-EOF &&
170 {:bool=>false, :str=>"default", :num=>10}
172 test_cmp expected actual &&
174 git ruby parse-script --bool --string=bar --number=-20 > actual &&
175 cat > expected <<-EOF &&
177 {:bool=>true, :str=>"bar", :num=>-20}
179 test_cmp expected actual &&
181 git ruby parse-script --help > actual &&
182 cat > expected <<-EOF &&
188 test_cmp expected actual &&
190 git ruby parse-script --help > actual &&
191 cat > expected <<-EOF &&
197 test_cmp expected actual &&
199 test_must_fail git ruby parse-script --bad > actual &&
200 cat > expected <<-EOF &&
206 test_cmp expected actual &&
208 git ruby parse-script one --bool two --string=bar three --number=-20 mambo > actual &&
209 cat > expected <<-EOF &&
210 ["one", "two", "three", "mambo"]
211 {:bool=>true, :str=>"bar", :num=>-20}
213 test_cmp expected actual &&
215 git ruby parse-script one --bool two -- --three four > actual &&
216 cat > expected <<-EOF &&
217 ["one", "two", "--three", "four"]
218 {:bool=>true, :str=>"default", :num=>0}
220 test_cmp expected actual &&
222 git ruby parse-script one --bool --no-bool > actual &&
223 cat > expected <<-EOF &&
225 {:bool=>false, :str=>"default", :num=>0}
228 test_cmp expected actual &&