#!/bin/sh # Checks that the configuration documents stay consistent with each other and # with cgit. The manual and the reference config name the same keys, and cgit # accepts every key the manual documents and no other. The reference config # changes nothing as it ships and puts scan-path after every global setting, # and two settings the manual wants prior to scan-path are shown to miss a # scan above them. The manual's contents name its sections in order, and both # settings sections keep their entries sorted. test_description='Check the configuration documents' CGIT_TEST_NO_CREATE_REPOS=YesPlease . ./setup.sh ROOT="$TEST_OUTPUT_DIRECTORY/.." test_expect_success 'extract the key lists' ' sed -n "/^Global settings$/,/^Repository-specific cgitrc file$/p" "$ROOT/MANUAL.txt" | sed -n "s/^\([a-z][a-zA-Z0-9.<>-]*\)::$/\1/p" | sort >manual-keys && sed -n -e "s/^#\{0,1\}\(mimetype\)\..*=.*/\1./p" \ -e "s/^#\{0,1\}\(repo\.module-link\)\..*=.*/\1./p" \ -e "s/^#\{0,1\}\([a-z][a-zA-Z0-9.<>-]*\)=.*/\1/p" "$ROOT/custom/cgitrc" | sort -u >example-keys && test -s manual-keys && test -s example-keys ' test_expect_success 'the reference config sets every documented key' ' comm -23 manual-keys example-keys >missing && test_must_be_empty missing ' test_expect_success 'every key the reference config sets is documented' ' comm -13 manual-keys example-keys >undocumented && test_must_be_empty undocumented ' # Each documented key is given an empty value, the global ones ahead of the # repository and the repo.* ones after it, along with one key of each kind # that cgit does not know, which shows the warning would be seen. test_expect_success 'cgit accepts every key the manual documents' ' { grep -v "^repo\." manual-keys | sed -e "s/^mimetype\.$/mimetype.txt/" -e "s/$/=/" && echo "no-such-key=" && echo "repo.url=docs" && grep "^repo\." manual-keys | grep -v "^repo\.url$" | sed -e "s/^repo\.module-link\.$/repo.module-link.sub/" -e "s/$/=/" && echo "repo.no-such-key=" } >keysrc && cgit_rc keysrc "url=" >keys.out 2>keys.err && grep "Unknown" keys.err >unknown && test_write_lines "[cgit] Unknown config key: no-such-key" \ "[cgit] Unknown repo config key: no-such-key" >expect && test_cmp expect unknown ' # The names are read off the comparisons apply_config and cgit_repo_config # make, the latter written without the repo. prefix. test_expect_success 'the manual documents every key cgit accepts' ' sed -n "/^static void apply_config(/,/^}/p" "$ROOT/source/cgit.c" | sed -n "s/.*strcmp(name, \"\([^\"]*\)\").*/\1/p" >accepted && sed -n "/^void cgit_repo_config(/,/^}/p" "$ROOT/source/cgit.c" | sed -n "s/.*strcmp(name, \"\([^\"]*\)\").*/repo.\1/p" >>accepted && echo mimetype.\ >>accepted && echo repo.module-link.\ >>accepted && test_line_count -gt 100 accepted && sort -u -o accepted accepted && comm -23 accepted manual-keys >undocumented && test_must_be_empty undocumented ' # The sample says that copied as-is it leaves cgit as if nothing were set, so # a repository listed after it renders the same as one listed alone, and # nothing in it is logged. test_expect_success 'the reference config changes nothing as it ships' ' mkrepo repos/sample 1 >/dev/null && { echo "repo.url=sample" && echo "repo.path=$PWD/repos/sample/.git" } >alonerc && cat "$ROOT/custom/cgitrc" alonerc >samplerc && for url in "" sample/ sample/log/ do cgit_ok alonerc "url=$url" >alone.out && cgit_ok samplerc "url=$url" >sample.out && strip_headers expect && strip_headers actual && test_grep "data-page=" actual && test_cmp expect actual || return 1 done ' # A scanned repository inherits the global settings above scan-path, so the # sample keeps none below it. test_expect_success 'the reference config scans after every global setting' ' sed -n "/^#\{0,1\}scan-path=/,\$p" "$ROOT/custom/cgitrc" | sed -n "s/^#\{0,1\}\([a-z][a-zA-Z0-9.<>-]*\)=.*/\1/p" | grep -v "^repo\." >after-scan-path && echo scan-path >expect && test_cmp expect after-scan-path ' # The scan runs as its line is read, which is why the manual has these two # defined prior to it. Below it, strict-export comes too late to filter and # cache-size too late to keep the list, though the page is still cached. test_expect_success 'strict-export and cache-size reach the scan only above it' ' mkrepo scanned/exported 1 >/dev/null && mkrepo scanned/plain 1 >/dev/null && touch scanned/exported/.git/export-ok && mkdir above below && { echo "virtual-root=/" && echo "cache-root=$PWD/above" && echo "strict-export=export-ok" && echo "cache-size=64" && echo "scan-path=$PWD/scanned" } >aboverc && { echo "virtual-root=/" && echo "cache-root=$PWD/below" && echo "scan-path=$PWD/scanned" && echo "strict-export=export-ok" && echo "cache-size=64" } >belowrc && cgit_ok aboverc "url=" >tmp && test_grep ">exported" tmp && test_grep ! ">plain" tmp && ls above/rc-* && cgit_ok belowrc "url=" >tmp && test_grep ">plain" tmp && ls below >slots && test_line_count = 1 slots && test_grep ! "^rc-" slots ' test_expect_success 'the manual lists its global settings in order' ' sed -n "/^Global settings$/,/^Repository settings$/p" "$ROOT/MANUAL.txt" | sed -n "s/^\([a-z][a-zA-Z0-9.<>-]*\)::$/\1/p" >global-order && sort -c global-order ' test_expect_success 'the manual lists its repository settings in order' ' sed -n "/^Repository settings$/,/^Repository-specific cgitrc file$/p" "$ROOT/MANUAL.txt" | sed -n "s/^\(repo\.[a-zA-Z0-9.<>-]*\)::$/\1/p" >repo-order && sort -c repo-order ' # A section heading is the line above a row of dashes, and the contents list # names every section but its own. test_expect_success 'the contents of the manual name its sections in order' ' sed -n "/^Contents$/,/^[^-]/s/^- //p" "$ROOT/MANUAL.txt" >contents && test -s contents && sed -n "\$!N;/\n--*\$/P;D" "$ROOT/MANUAL.txt" | grep -v "^Contents$" >sections && test_cmp sections contents ' test_done