gitweb: use new Git::Repo API, and add optional caching
[git/gitweb-caching.git] / t / t9503-gitweb-Mechanize.sh
blob169eed9ca521222b0d0ab8db6e471d457317458f
1 #!/bin/sh
3 # Copyright (c) 2008 Jakub Narebski
4 # Copyright (c) 2008 Lea Wiemann
7 # This test supports the --long-tests option.
9 # This test only runs on Perl 5.8 and later versions, since both
10 # Gitweb and Test::WWW::Mechanize::CGI require Perl 5.8.
12 test_description='gitweb tests (using WWW::Mechanize)
14 This test uses Test::WWW::Mechanize::CGI to test gitweb.'
16 # helper functions
18 safe_chmod () {
19 chmod "$1" "$2" &&
20 if [ "$(git config --get core.filemode)" = false ]
21 then
22 git update-index --chmod="$1" "$2"
26 . ./test-lib.sh
28 # check if test can be run
29 "$PERL_PATH" -e 'use 5.008' >/dev/null 2>&1 || {
30 test_expect_success \
31 'skipping gitweb tests, Perl 5.8 or newer required' :
32 test_done
33 exit
36 "$PERL_PATH" -MTest::WWW::Mechanize::CGI -e '' >/dev/null 2>&1 || {
37 test_expect_success \
38 'skipping gitweb tests, Test::WWW::Mechanize::CGI not found' :
39 test_done
40 exit
43 # set up test repository
44 test_expect_success 'set up test repository' '
46 echo "Not an empty file." > file &&
47 git add file &&
48 test_tick && git commit -a -m "Initial commit." &&
49 git branch b &&
51 echo "New file" > new_file &&
52 git add new_file &&
53 test_tick && git commit -a -m "File added." &&
55 safe_chmod +x new_file &&
56 test_tick && git commit -a -m "Mode changed." &&
58 git mv new_file renamed_file &&
59 test_tick && git commit -a -m "File renamed." &&
61 rm renamed_file &&
62 ln -s file renamed_file &&
63 test_tick && git commit -a -m "File to symlink." &&
64 git tag with-symlink &&
66 git rm renamed_file &&
67 rm -f renamed_file &&
68 test_tick && git commit -a -m "File removed." &&
70 cp file file2 &&
71 git add file2 &&
72 test_tick && git commit -a -m "File copied." &&
74 echo "New line" >> file2 &&
75 safe_chmod +x file2 &&
76 test_tick && git commit -a -m "Mode change and modification." &&
78 mkdir dir1 &&
79 echo "New file with a \"pickaxe test string\"" > dir1/file1 &&
80 git add dir1/file1 &&
81 test_tick && git commit -a -m "File added in subdirectory." &&
82 git tag -m "creating a tag object" tag-object
84 git checkout b &&
85 echo "Branch" >> b &&
86 git add b &&
87 test_tick && git commit -a -m "On branch" &&
88 git checkout master &&
89 test_tick && git merge b
92 # set up empty repository
93 # create this as a subdirectory of trash directory; not pretty, but simple
94 test_expect_success 'set up empty repository' '
96 mkdir empty.git &&
97 cd empty.git &&
98 git init --bare &&
99 cd ..
102 # set up gitweb configuration
103 safe_pwd="$("$PERL_PATH" -MPOSIX=getcwd -e 'print quotemeta(getcwd)')"
104 large_cache_root="$TEST_DIRECTORY/t9503/large_cache.tmp"
105 test_expect_success 'create file cache directory' \
106 'mkdir -p "$large_cache_root"'
107 cat >gitweb_config.perl <<EOF
108 # gitweb configuration for tests
110 our \$version = "current";
111 our \$GIT = "$GIT_EXEC_PATH/git";
112 our \$projectroot = "$safe_pwd";
113 our \$project_maxdepth = 8;
114 our \$home_link_str = "projects";
115 our \$site_name = "[localhost]";
116 our \$site_header = "";
117 our \$site_footer = "";
118 our \$home_text = "indextext.html";
119 our @stylesheets = ("file:///stylesheet");
120 our \$logo = "file:///logo";
121 our \$favicon = "file:///favicon";
122 our \$projects_list = "";
123 our \$export_ok = "";
124 our \$strict_export = "";
125 our %feature;
126 \$feature{'blame'}{'default'} = [1];
128 our \$large_cache_root = "$large_cache_root";
129 if (eval { require Cache::MemoryCache; 1 }) {
130 our \$cache = Cache::MemoryCache->new;
135 __END__
138 cat >.git/description <<EOF
139 t9503-gitweb-Mechanize test repository
142 GITWEB_CONFIG="$(pwd)/gitweb_config.perl"
143 export GITWEB_CONFIG
145 # run tests
147 test_external \
148 'test gitweb output' \
149 "$PERL_PATH" "$TEST_DIRECTORY/t9503/test.pl"
151 test_expect_success 'remove file cache directory' \
152 'rm -rf "$large_cache_root"'
154 test_done