t / t9500-gitweb-standalone-no-errors.shon commit War on whitespace (a6080a0)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Jakub Narebski
   4#
   5
   6test_description='gitweb as standalone script (basic tests).
   7
   8This test runs gitweb (git web interface) as CGI script from
   9commandline, and checks that it would not write any errors
  10or warnings to log.'
  11
  12gitweb_init () {
  13        cat >gitweb_config.perl <<EOF
  14#!/usr/bin/perl
  15
  16# gitweb configuration for tests
  17
  18our \$version = "current";
  19our \$GIT = "git";
  20our \$projectroot = "$(pwd)";
  21our \$home_link_str = "projects";
  22our \$site_name = "[localhost]";
  23our \$site_header = "";
  24our \$site_footer = "";
  25our \$home_text = "indextext.html";
  26our @stylesheets = ("file:///$(pwd)/../../gitweb/gitweb.css");
  27our \$logo = "file:///$(pwd)/../../gitweb/git-logo.png";
  28our \$favicon = "file:///$(pwd)/../../gitweb/git-favicon.png";
  29our \$projects_list = "";
  30our \$export_ok = "";
  31our \$strict_export = "";
  32
  33CGI::Carp::set_programname("gitweb/gitweb.cgi");
  34EOF
  35
  36        cat >.git/description <<EOF
  37$0 test repository
  38EOF
  39}
  40
  41gitweb_run () {
  42        export GATEWAY_INTERFACE="CGI/1.1"
  43        export HTTP_ACCEPT="*/*"
  44        export REQUEST_METHOD="GET"
  45        export QUERY_STRING=""$1""
  46        export PATH_INFO=""$2""
  47
  48        export GITWEB_CONFIG=$(pwd)/gitweb_config.perl
  49
  50        # some of git commands write to STDERR on error, but this is not
  51        # written to web server logs, so we are not interested in that:
  52        # we are interested only in properly formatted errors/warnings
  53        rm -f gitweb.log &&
  54        perl -- $(pwd)/../../gitweb/gitweb.perl \
  55                >/dev/null 2>gitweb.log &&
  56        if grep -q -s "^[[]" gitweb.log >/dev/null; then false; else true; fi
  57
  58        # gitweb.log is left for debugging
  59}
  60
  61. ./test-lib.sh
  62
  63gitweb_init
  64
  65# ----------------------------------------------------------------------
  66# no commits (empty, just initialized repository)
  67
  68test_expect_success \
  69        'no commits: projects_list (implicit)' \
  70        'gitweb_run'
  71test_debug 'cat gitweb.log'
  72
  73test_expect_success \
  74        'no commits: projects_index' \
  75        'gitweb_run "a=project_index"'
  76test_debug 'cat gitweb.log'
  77
  78test_expect_success \
  79        'no commits: .git summary (implicit)' \
  80        'gitweb_run "p=.git"'
  81test_debug 'cat gitweb.log'
  82
  83test_expect_success \
  84        'no commits: .git commit (implicit HEAD)' \
  85        'gitweb_run "p=.git;a=commit"'
  86test_debug 'cat gitweb.log'
  87
  88test_expect_success \
  89        'no commits: .git commitdiff (implicit HEAD)' \
  90        'gitweb_run "p=.git;a=commitdiff"'
  91test_debug 'cat gitweb.log'
  92
  93test_expect_success \
  94        'no commits: .git tree (implicit HEAD)' \
  95        'gitweb_run "p=.git;a=tree"'
  96test_debug 'cat gitweb.log'
  97
  98test_expect_success \
  99        'no commits: .git heads' \
 100        'gitweb_run "p=.git;a=heads"'
 101test_debug 'cat gitweb.log'
 102
 103test_expect_success \
 104        'no commits: .git tags' \
 105        'gitweb_run "p=.git;a=tags"'
 106test_debug 'cat gitweb.log'
 107
 108
 109# ----------------------------------------------------------------------
 110# initial commit
 111
 112test_expect_success \
 113        'Make initial commit' \
 114        'echo "Not an empty file." > file &&
 115         git add file &&
 116         git commit -a -m "Initial commit." &&
 117         git branch b'
 118
 119test_expect_success \
 120        'projects_list (implicit)' \
 121        'gitweb_run'
 122test_debug 'cat gitweb.log'
 123
 124test_expect_success \
 125        'projects_index' \
 126        'gitweb_run "a=project_index"'
 127test_debug 'cat gitweb.log'
 128
 129test_expect_success \
 130        '.git summary (implicit)' \
 131        'gitweb_run "p=.git"'
 132test_debug 'cat gitweb.log'
 133
 134test_expect_success \
 135        '.git commit (implicit HEAD)' \
 136        'gitweb_run "p=.git;a=commit"'
 137test_debug 'cat gitweb.log'
 138
 139test_expect_success \
 140        '.git commitdiff (implicit HEAD, root commit)' \
 141        'gitweb_run "p=.git;a=commitdiff"'
 142test_debug 'cat gitweb.log'
 143
 144test_expect_success \
 145        '.git commitdiff_plain (implicit HEAD, root commit)' \
 146        'gitweb_run "p=.git;a=commitdiff_plain"'
 147test_debug 'cat gitweb.log'
 148
 149test_expect_success \
 150        '.git commit (HEAD)' \
 151        'gitweb_run "p=.git;a=commit;h=HEAD"'
 152test_debug 'cat gitweb.log'
 153
 154test_expect_success \
 155        '.git tree (implicit HEAD)' \
 156        'gitweb_run "p=.git;a=tree"'
 157test_debug 'cat gitweb.log'
 158
 159test_expect_success \
 160        '.git blob (file)' \
 161        'gitweb_run "p=.git;a=blob;f=file"'
 162test_debug 'cat gitweb.log'
 163
 164test_expect_success \
 165        '.git blob_plain (file)' \
 166        'gitweb_run "p=.git;a=blob_plain;f=file"'
 167test_debug 'cat gitweb.log'
 168
 169# ----------------------------------------------------------------------
 170# nonexistent objects
 171
 172test_expect_success \
 173        '.git commit (non-existent)' \
 174        'gitweb_run "p=.git;a=commit;h=non-existent"'
 175test_debug 'cat gitweb.log'
 176
 177test_expect_success \
 178        '.git commitdiff (non-existent)' \
 179        'gitweb_run "p=.git;a=commitdiff;h=non-existent"'
 180test_debug 'cat gitweb.log'
 181
 182test_expect_success \
 183        '.git commitdiff (non-existent vs HEAD)' \
 184        'gitweb_run "p=.git;a=commitdiff;hp=non-existent;h=HEAD"'
 185test_debug 'cat gitweb.log'
 186
 187test_expect_success \
 188        '.git tree (0000000000000000000000000000000000000000)' \
 189        'gitweb_run "p=.git;a=tree;h=0000000000000000000000000000000000000000"'
 190test_debug 'cat gitweb.log'
 191
 192test_expect_success \
 193        '.git tag (0000000000000000000000000000000000000000)' \
 194        'gitweb_run "p=.git;a=tag;h=0000000000000000000000000000000000000000"'
 195test_debug 'cat gitweb.log'
 196
 197test_expect_success \
 198        '.git blob (non-existent)' \
 199        'gitweb_run "p=.git;a=blob;f=non-existent"'
 200test_debug 'cat gitweb.log'
 201
 202test_expect_success \
 203        '.git blob_plain (non-existent)' \
 204        'gitweb_run "p=.git;a=blob_plain;f=non-existent"'
 205test_debug 'cat gitweb.log'
 206
 207
 208# ----------------------------------------------------------------------
 209# commitdiff testing (implicit, one implicit tree-ish)
 210
 211test_expect_success \
 212        'commitdiff(0): root' \
 213        'gitweb_run "p=.git;a=commitdiff"'
 214test_debug 'cat gitweb.log'
 215
 216test_expect_success \
 217        'commitdiff(0): file added' \
 218        'echo "New file" > new_file &&
 219         git add new_file &&
 220         git commit -a -m "File added." &&
 221         gitweb_run "p=.git;a=commitdiff"'
 222test_debug 'cat gitweb.log'
 223
 224test_expect_success \
 225        'commitdiff(0): mode change' \
 226        'chmod a+x new_file &&
 227         git commit -a -m "Mode changed." &&
 228         gitweb_run "p=.git;a=commitdiff"'
 229test_debug 'cat gitweb.log'
 230
 231test_expect_success \
 232        'commitdiff(0): file renamed' \
 233        'git mv new_file renamed_file &&
 234         git commit -a -m "File renamed." &&
 235         gitweb_run "p=.git;a=commitdiff"'
 236test_debug 'cat gitweb.log'
 237
 238test_expect_success \
 239        'commitdiff(0): file to symlink' \
 240        'rm renamed_file &&
 241         ln -s file renamed_file &&
 242         git commit -a -m "File to symlink." &&
 243         gitweb_run "p=.git;a=commitdiff"'
 244test_debug 'cat gitweb.log'
 245
 246test_expect_success \
 247        'commitdiff(0): file deleted' \
 248        'git rm renamed_file &&
 249         rm -f renamed_file &&
 250         git commit -a -m "File removed." &&
 251         gitweb_run "p=.git;a=commitdiff"'
 252test_debug 'cat gitweb.log'
 253
 254test_expect_success \
 255        'commitdiff(0): file copied / new file' \
 256        'cp file file2 &&
 257         git add file2 &&
 258         git commit -a -m "File copied." &&
 259         gitweb_run "p=.git;a=commitdiff"'
 260test_debug 'cat gitweb.log'
 261
 262test_expect_success \
 263        'commitdiff(0): mode change and modified' \
 264        'echo "New line" >> file2 &&
 265         chmod a+x file2 &&
 266         git commit -a -m "Mode change and modification." &&
 267         gitweb_run "p=.git;a=commitdiff"'
 268test_debug 'cat gitweb.log'
 269
 270test_expect_success \
 271        'commitdiff(0): renamed and modified' \
 272        'cat >file2<<EOF &&
 273Dominus regit me,
 274et nihil mihi deerit.
 275In loco pascuae ibi me collocavit,
 276super aquam refectionis educavit me;
 277animam meam convertit,
 278deduxit me super semitas jusitiae,
 279propter nomen suum.
 280EOF
 281         git commit -a -m "File added." &&
 282         git mv file2 file3 &&
 283         echo "Propter nomen suum." >> file3 &&
 284         git commit -a -m "File rename and modification." &&
 285         gitweb_run "p=.git;a=commitdiff"'
 286test_debug 'cat gitweb.log'
 287
 288test_expect_success \
 289        'commitdiff(0): renamed, mode change and modified' \
 290        'git mv file3 file2 &&
 291         echo "Propter nomen suum." >> file2 &&
 292         chmod a+x file2 &&
 293         git commit -a -m "File rename, mode change and modification." &&
 294         gitweb_run "p=.git;a=commitdiff"'
 295test_debug 'cat gitweb.log'
 296
 297# ----------------------------------------------------------------------
 298# commitdiff testing (taken from t4114-apply-typechange.sh)
 299
 300test_expect_success 'setup typechange commits' '
 301        echo "hello world" > foo &&
 302        echo "hi planet" > bar &&
 303        git update-index --add foo bar &&
 304        git commit -m initial &&
 305        git branch initial &&
 306        rm -f foo &&
 307        ln -s bar foo &&
 308        git update-index foo &&
 309        git commit -m "foo symlinked to bar" &&
 310        git branch foo-symlinked-to-bar &&
 311        rm -f foo &&
 312        echo "how far is the sun?" > foo &&
 313        git update-index foo &&
 314        git commit -m "foo back to file" &&
 315        git branch foo-back-to-file &&
 316        rm -f foo &&
 317        git update-index --remove foo &&
 318        mkdir foo &&
 319        echo "if only I knew" > foo/baz &&
 320        git update-index --add foo/baz &&
 321        git commit -m "foo becomes a directory" &&
 322        git branch "foo-becomes-a-directory" &&
 323        echo "hello world" > foo/baz &&
 324        git update-index foo/baz &&
 325        git commit -m "foo/baz is the original foo" &&
 326        git branch foo-baz-renamed-from-foo
 327        '
 328
 329test_expect_success \
 330        'commitdiff(2): file renamed from foo to foo/baz' \
 331        'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-baz-renamed-from-foo"'
 332test_debug 'cat gitweb.log'
 333
 334test_expect_success \
 335        'commitdiff(2): file renamed from foo/baz to foo' \
 336        'gitweb_run "p=.git;a=commitdiff;hp=foo-baz-renamed-from-foo;h=initial"'
 337test_debug 'cat gitweb.log'
 338
 339test_expect_success \
 340        'commitdiff(2): directory becomes file' \
 341        'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=initial"'
 342test_debug 'cat gitweb.log'
 343
 344test_expect_success \
 345        'commitdiff(2): file becomes directory' \
 346        'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-becomes-a-directory"'
 347test_debug 'cat gitweb.log'
 348
 349test_expect_success \
 350        'commitdiff(2): file becomes symlink' \
 351        'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-symlinked-to-bar"'
 352test_debug 'cat gitweb.log'
 353
 354test_expect_success \
 355        'commitdiff(2): symlink becomes file' \
 356        'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-back-to-file"'
 357test_debug 'cat gitweb.log'
 358
 359test_expect_success \
 360        'commitdiff(2): symlink becomes directory' \
 361        'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-becomes-a-directory"'
 362test_debug 'cat gitweb.log'
 363
 364test_expect_success \
 365        'commitdiff(2): directory becomes symlink' \
 366        'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=foo-symlinked-to-bar"'
 367test_debug 'cat gitweb.log'
 368
 369# ----------------------------------------------------------------------
 370# commit, commitdiff: merge, large
 371test_expect_success \
 372        'Create a merge' \
 373        'git checkout b &&
 374         echo "Branch" >> b &&
 375         git add b &&
 376         git commit -a -m "On branch" &&
 377         git checkout master &&
 378         git pull . b'
 379
 380test_expect_success \
 381        'commit(0): merge commit' \
 382        'gitweb_run "p=.git;a=commit"'
 383test_debug 'cat gitweb.log'
 384
 385test_expect_success \
 386        'commitdiff(0): merge commit' \
 387        'gitweb_run "p=.git;a=commitdiff"'
 388test_debug 'cat gitweb.log'
 389
 390test_expect_success \
 391        'Prepare large commit' \
 392        'git checkout b &&
 393         echo "To be changed" > 01-change &&
 394         echo "To be renamed" > 02-pure-rename-from &&
 395         echo "To be deleted" > 03-delete &&
 396         echo "To be renamed and changed" > 04-rename-from &&
 397         echo "To have mode changed" > 05-mode-change &&
 398         echo "File to symlink" > 06-file-or-symlink &&
 399         echo "To be changed and have mode changed" > 07-change-mode-change     &&
 400         git add 0* &&
 401         git commit -a -m "Prepare large commit" &&
 402         echo "Changed" > 01-change &&
 403         git mv 02-pure-rename-from 02-pure-rename-to &&
 404         git rm 03-delete && rm -f 03-delete &&
 405         echo "A new file" > 03-new &&
 406         git add 03-new &&
 407         git mv 04-rename-from 04-rename-to &&
 408         echo "Changed" >> 04-rename-to &&
 409         chmod a+x 05-mode-change &&
 410         rm -f 06-file-or-symlink && ln -s 01-change 06-file-or-symlink &&
 411         echo "Changed and have mode changed" > 07-change-mode-change   &&
 412         chmod a+x 07-change-mode-change &&
 413         git commit -a -m "Large commit" &&
 414         git checkout master'
 415
 416test_expect_success \
 417        'commit(1): large commit' \
 418        'gitweb_run "p=.git;a=commit;h=b"'
 419test_debug 'cat gitweb.log'
 420
 421test_expect_success \
 422        'commitdiff(1): large commit' \
 423        'gitweb_run "p=.git;a=commitdiff;h=b"'
 424test_debug 'cat gitweb.log'
 425
 426# ----------------------------------------------------------------------
 427# tags testing
 428
 429test_expect_success \
 430        'tags: list of different types of tags' \
 431        'git checkout master &&
 432         git tag -a -m "Tag commit object" tag-commit HEAD &&
 433         git tag -a -m "" tag-commit-nomessage HEAD &&
 434         git tag -a -m "Tag tag object" tag-tag tag-commit &&
 435         git tag -a -m "Tag tree object" tag-tree HEAD^{tree} &&
 436         git tag -a -m "Tag blob object" tag-blob HEAD:file &&
 437         git tag lightweight/tag-commit HEAD &&
 438         git tag lightweight/tag-tag tag-commit &&
 439         git tag lightweight/tag-tree HEAD^{tree} &&
 440         git tag lightweight/tag-blob HEAD:file &&
 441         gitweb_run "p=.git;a=tags"'
 442test_debug 'cat gitweb.log'
 443
 444test_expect_success \
 445        'tag: Tag to commit object' \
 446        'gitweb_run "p=.git;a=tag;h=tag-commit"'
 447test_debug 'cat gitweb.log'
 448
 449test_expect_success \
 450        'tag: on lightweight tag (invalid)' \
 451        'gitweb_run "p=.git;a=tag;h=lightweight/tag-commit"'
 452test_debug 'cat gitweb.log'
 453
 454# ----------------------------------------------------------------------
 455# logs
 456
 457test_expect_success \
 458        'logs: log (implicit HEAD)' \
 459        'gitweb_run "p=.git;a=log"'
 460test_debug 'cat gitweb.log'
 461
 462test_expect_success \
 463        'logs: shortlog (implicit HEAD)' \
 464        'gitweb_run "p=.git;a=shortlog"'
 465test_debug 'cat gitweb.log'
 466
 467test_expect_success \
 468        'logs: history (implicit HEAD, file)' \
 469        'gitweb_run "p=.git;a=history;f=file"'
 470test_debug 'cat gitweb.log'
 471
 472# ----------------------------------------------------------------------
 473# feed generation
 474
 475test_expect_success \
 476        'feeds: OPML' \
 477        'gitweb_run "a=opml"'
 478test_debug 'cat gitweb.log'
 479
 480test_expect_success \
 481        'feed: RSS' \
 482        'gitweb_run "p=.git;a=rss"'
 483test_debug 'cat gitweb.log'
 484
 485test_expect_success \
 486        'feed: Atom' \
 487        'gitweb_run "p=.git;a=atom"'
 488test_debug 'cat gitweb.log'
 489
 490# ----------------------------------------------------------------------
 491# encoding/decoding
 492
 493test_expect_success \
 494        'encode(commit): utf8' \
 495        '. ../t3901-utf8.txt &&
 496         echo "UTF-8" >> file &&
 497         git add file &&
 498         git commit -F ../t3900/1-UTF-8.txt &&
 499         gitweb_run "p=.git;a=commit"'
 500test_debug 'cat gitweb.log'
 501
 502test_expect_success \
 503        'encode(commit): iso-8859-1' \
 504        '. ../t3901-8859-1.txt &&
 505         echo "ISO-8859-1" >> file &&
 506         git add file &&
 507         git config i18n.commitencoding ISO-8859-1 &&
 508         git commit -F ../t3900/ISO-8859-1.txt &&
 509         git config --unset i18n.commitencoding &&
 510         gitweb_run "p=.git;a=commit"'
 511test_debug 'cat gitweb.log'
 512
 513test_expect_success \
 514        'encode(log): utf-8 and iso-8859-1' \
 515        'gitweb_run "p=.git;a=log"'
 516test_debug 'cat gitweb.log'
 517
 518test_done