#! @ATF_SH@ # Copyright 2012 Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of Google Inc. nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # Creates a fake program that records its invocations for later processing. # # The fake program, when invoked, will append its arguments to a commands.log # file in the test case's work directory. # # \param binary The path to the program to create. # \param get_stdin Whether to capture stdin or not. create_mock_binary() { local binary="${1}"; shift local get_stdin="${1}"; shift cat >"${binary}" <>"\${logfile}" for arg in "\${@}"; do echo "Arg: \${arg}" >>"\${logfile}" done [ "${get_stdin}" = no ] || sed -e 's,^,stdin: ,' >>"\${logfile}" echo >>"\${logfile}" EOF chmod +x "${binary}" } setup_mocks() { mkdir bin create_mock_binary bin/mail yes create_mock_binary bin/sysbuild no PATH="$(pwd)/bin:${PATH}" SYSBUILD_BINDIR="$(pwd)/bin"; export SYSBUILD_BINDIR } atf_test_case no_args no_args_body() { setup_mocks atf_check sysbuild4cron cat >expout <expout <>bin/sysbuild done echo "exit 1" >>bin/sysbuild atf_check sysbuild4cron a name="$(cd sysbuild/log && echo sysbuild4cron.*.log)" cat >expout <>expout done echo >>expout atf_check -o file:expout cat commands.log } atf_test_case custom_flags custom_flags_body() { setup_mocks echo "exit 1" >>bin/sysbuild atf_check sysbuild4cron -l path/to/logs -r somebody@example.net name="$(cd path/to/logs && echo sysbuild4cron.*.log)" cat >expout <>bin/sysbuild echo "echo bar 1>&2" >>bin/sysbuild echo "exit 1" >>bin/sysbuild atf_check sysbuild4cron atf_check -o match:"stdin: foo" -o match:"stdin: bar" cat commands.log } atf_test_case unknown_flag unknown_flag_body() { cat >experr <