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