Path: blob/main/contrib/kyua/doc/manbuild_test.sh
107897 views
# Copyright 2014 The Kyua Authors.1# All rights reserved.2#3# Redistribution and use in source and binary forms, with or without4# modification, are permitted provided that the following conditions are5# met:6#7# * Redistributions of source code must retain the above copyright8# notice, this list of conditions and the following disclaimer.9# * Redistributions in binary form must reproduce the above copyright10# notice, this list of conditions and the following disclaimer in the11# documentation and/or other materials provided with the distribution.12# * Neither the name of Google Inc. nor the names of its contributors13# may be used to endorse or promote products derived from this software14# without specific prior written permission.15#16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.272829# Absolute path to the uninstalled script.30MANBUILD="__MANBUILD__"313233atf_test_case empty34empty_body() {35touch input36atf_check "${MANBUILD}" input output37atf_check cat output38}394041atf_test_case no_replacements42no_replacements_body() {43cat >input <<EOF44This is a manpage.4546With more than one line.47EOF48atf_check "${MANBUILD}" input output49atf_check -o file:input cat output50}515253atf_test_case one_replacement54one_replacement_body() {55cat >input <<EOF56This is a manpage.57Where __FOO__ gets replaced.58And nothing more.59EOF60atf_check "${MANBUILD}" -v FOO=this input output61cat >expout <<EOF62This is a manpage.63Where this gets replaced.64And nothing more.65EOF66atf_check -o file:expout cat output67}686970atf_test_case some_replacements71some_replacements_body() {72cat >input <<EOF73This is a manpage.74Where __FOO__ gets __BAR__.75And nothing more.76EOF77atf_check "${MANBUILD}" -v FOO=this -v BAR=replaced input output78cat >expout <<EOF79This is a manpage.80Where this gets replaced.81And nothing more.82EOF83atf_check -o file:expout cat output84}858687atf_test_case preserve_tricky_lines88preserve_tricky_lines_body() {89cat >input <<EOF90Begin91This line is intended.92This other \\93continues later.94\*(LtAnd this has strange characters\*(Gt95End96EOF97atf_check "${MANBUILD}" input output98cat >expout <<EOF99Begin100This line is intended.101This other \\102continues later.103\*(LtAnd this has strange characters\*(Gt104End105EOF106atf_check -o file:expout cat output107}108109110atf_test_case includes_ok111includes_ok_body() {112mkdir doc doc/subdir113cat >doc/input <<EOF114This is a manpage.115__include__ subdir/chunk116There is more...117__include__ chunk118And done!119EOF120cat >doc/subdir/chunk <<EOF121This is the first inclusion122and worked __OK__.123EOF124cat >doc/chunk <<EOF125This is the second inclusion.126EOF127atf_check "${MANBUILD}" -v OK=ok doc/input output128cat >expout <<EOF129This is a manpage.130This is the first inclusion131and worked ok.132There is more...133This is the second inclusion.134And done!135EOF136atf_check -o file:expout cat output137}138139140atf_test_case includes_parameterized141includes_parameterized_body() {142cat >input <<EOF143__include__ chunk value=first144__include__ chunk value=second145EOF146cat >chunk <<EOF147This is a chunk with value: __value__.148EOF149atf_check "${MANBUILD}" input output150cat >expout <<EOF151This is a chunk with value: first.152This is a chunk with value: second.153EOF154atf_check -o file:expout cat output155}156157158atf_test_case includes_fail159includes_fail_body() {160cat >input <<EOF161This is a manpage.162__include__ missing163EOF164atf_check -s exit:1 -o ignore \165-e match:"manbuild.sh: Failed to generate output.*left unreplaced" \166"${MANBUILD}" input output167[ ! -f output ] || atf_fail "Output file was generated but it should" \168"not have been"169}170171172atf_test_case generate_fail173generate_fail_body() {174touch input175atf_check -s exit:1 -o ignore \176-e match:"manbuild.sh: Failed to generate output" \177"${MANBUILD}" -v 'malformed&name=value' input output178[ ! -f output ] || atf_fail "Output file was generated but it should" \179"not have been"180}181182183atf_test_case validate_fail184validate_fail_body() {185cat >input <<EOF186This is a manpage.187Where __FOO__ gets replaced.188But where __BAR__ doesn't.189EOF190atf_check -s exit:1 -o ignore \191-e match:"manbuild.sh: Failed to generate output.*left unreplaced" \192"${MANBUILD}" -v FOO=this input output193[ ! -f output ] || atf_fail "Output file was generated but it should" \194"not have been"195}196197198atf_test_case bad_args199bad_args_body() {200atf_check -s exit:1 \201-e match:'manbuild.sh: Must provide input and output names' \202"${MANBUILD}"203204atf_check -s exit:1 \205-e match:'manbuild.sh: Must provide input and output names' \206"${MANBUILD}" foo207208atf_check -s exit:1 \209-e match:'manbuild.sh: Must provide input and output names' \210"${MANBUILD}" foo bar baz211}212213214atf_test_case bad_option215bad_option_body() {216atf_check -s exit:1 -e match:'manbuild.sh: Unknown option -Z' \217"${MANBUILD}" -Z218}219220221atf_init_test_cases() {222atf_add_test_case empty223atf_add_test_case no_replacements224atf_add_test_case one_replacement225atf_add_test_case some_replacements226atf_add_test_case preserve_tricky_lines227atf_add_test_case includes_ok228atf_add_test_case includes_parameterized229atf_add_test_case includes_fail230atf_add_test_case generate_fail231atf_add_test_case validate_fail232atf_add_test_case bad_args233atf_add_test_case bad_option234}235236237