3 # SPDX-License-Identifier: BSD-3-Clause
5 # Copyright 2013 Google Inc.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 # * Neither the name of Google Inc. nor the names of its contributors
18 # may be used to endorse or promote products derived from this software
19 # without specific prior written permission.
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 # This sample test program implements various test cases for the cp(1)
37 # utility in order to demonstrate the usage of the ATF shell API (see
42 # Auxiliary function to compare two files for equality.
45 if ! cmp -s "${1}" "${2}"; then
46 echo "${1} and ${2} differ, but they should be equal"
48 atf_fail "Original and copy do not match"
53 # This is the simplest form of a test case definition: a test case
56 # In most cases, this is the definition you will want to use. However,
57 # make absolutely sure that the test case name is descriptive enough.
58 # Multi-word test case names are encouraged. Keep in mind that these
59 # are exposed to the reader in the test reports, and the goal is for
60 # the combination of the test program plus the name of the test case to
61 # give a pretty clear idea of what specific condition the test is
66 cp $(atf_get_srcdir)/file1 .
68 # The atf_check function is a very powerful function of atf-sh.
69 # It allows you to define checkers for the exit status, the
70 # stdout and the stderr of any command you execute. If the
71 # result of the command does not match the expectations defined
72 # in the checkers, the test fails and verbosely reports data
75 # See atf-check(1) for details.
76 atf_check -s exit:0 -o empty -e empty cp file1 file2
78 verify_copy file1 file2
80 # Of special note here is that we are NOT deleting the temporary
81 # files we created in this test. Kyua takes care of this
82 # cleanup automatically and tests can (and should) rely on this
87 # This is a more complex form of a test case definition: a test case
88 # with a header and a body. You should always favor the simpler
89 # definition above unless you have to override specific metadata
92 # See atf-test-case(4) and kyua-atf-interface(1) for details on all
93 # available properties.
97 # In this specific case, we define a textual description for
98 # the test case, which is later exported to the reports for
99 # documentation purposes.
101 # However, note again that you should favor highly descriptive
102 # test case names to textual descriptions.
103 atf_set "descr" "Tests that the -f flag causes cp to forcibly" \
104 "override the destination file"
107 cp $(atf_get_srcdir)/file1 .
110 atf_check cp -f file1 file2
111 verify_copy file1 file2
115 # Lastly, we tell ATF which test cases exist in this program. This
116 # function should not do anything other than this registration.
118 atf_init_test_cases() {
119 atf_add_test_case simple
120 atf_add_test_case force