ruby: remove GIT_PAGER from environment
[git] / t / t10000-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 test_expect_success 'basic support' '
11         git ruby > actual <<-EOF &&
12         puts "hello world"
13         EOF
14         echo "hello world" > expected &&
15         test_cmp expected actual
16 '
17
18 test_expect_success 'argument passing' '
19         cat > script <<-"EOF" &&
20         p($0)
21         p(ARGV)
22         EOF
23         git ruby script foo bar > actual &&
24         cat > expected <<-EOF &&
25         "script"
26         ["foo", "bar"]
27         EOF
28         test_cmp expected actual
29 '
30
31 test_expect_success 'test for_each_ref()' '
32         test_commit foo &&
33         git ruby > actual <<-EOF &&
34         for_each_ref() do |name, sha1, flags|
35                 puts "%s: %s" % [name, sha1_to_hex(sha1)]
36         end
37         EOF
38         git for-each-ref --format="%(refname): %(objectname)" > expected &&
39         test_cmp expected actual
40 '
41
42 test_expect_success 'test setup_git_directory()' '
43         mkdir t &&
44         (
45         cd t &&
46         git ruby > ../actual <<-EOF
47         prefix, nongit_ok = setup_git_directory()
48         puts prefix
49         EOF
50         ) &&
51         echo "t/" > expected &&
52         test_cmp expected actual
53 '
54
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
59         EOF
60         git rev-parse -q --verify HEAD > expected &&
61         echo 1 >> expected &&
62         git rev-parse -q --verify --symbolic-full-name HEAD >> expected &&
63         test_cmp expected actual
64 '
65
66 test_expect_success 'test git_config()' '
67         git ruby > actual <<-EOF &&
68         git_config() do |key, value|
69           puts "%s=%s" % [key, value]
70         end
71         EOF
72         git config --list > expected &&
73         test_cmp expected actual
74 '
75
76 test_expect_success 'test get_sha1()' '
77         git ruby > actual <<-EOF &&
78         puts sha1_to_hex(get_sha1("HEAD"))
79         EOF
80         git rev-parse -q --verify HEAD > expected &&
81         test_cmp expected actual
82 '
83
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)
88         EOF
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
93 '
94
95 test_expect_success 'test Commit' '
96         git ruby > actual <<-EOF &&
97         commit = Git::Commit.get(get_sha1("HEAD"))
98         puts commit, commit.buffer
99         EOF
100         git rev-parse -q --verify HEAD > expected &&
101         git cat-file commit HEAD >> expected &&
102         test_cmp expected actual
103 '
104
105 test_done