#! __ATF_SH__1# Copyright 2012 Google Inc.2# All rights reserved.3#4# Redistribution and use in source and binary forms, with or without5# modification, are permitted provided that the following conditions are6# met:7#8# * Redistributions of source code must retain the above copyright9# notice, this list of conditions and the following disclaimer.10# * Redistributions in binary form must reproduce the above copyright11# notice, this list of conditions and the following disclaimer in the12# documentation and/or other materials provided with the distribution.13# * Neither the name of Google Inc. nor the names of its contributors14# may be used to endorse or promote products derived from this software15# without specific prior written permission.16#17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2829Cxx="__CXX__"30ExamplesDir="__EXAMPLESDIR__"31LibDir="__LIBDIR__"323334make_example() {35cp "${ExamplesDir}/Makefile" "${ExamplesDir}/${1}.cpp" .36make CXX="${Cxx}" "${1}"3738# Ensure that the binary we just built can find liblutok. This is39# needed because the lutok.pc file (which the Makefile used above40# queries) does not provide rpaths to the installed library and41# therefore the binary may not be able to locate it. Hardcoding the42# rpath flags into lutok.pc is non-trivial because we simply don't43# have any knowledge about what the correct flag to set an rpath is.44#45# Additionally, setting rpaths is not always the right thing to do.46# For example, pkgsrc will automatically change lutok.pc to add the47# missing rpath, in which case this is unnecessary. But in the case48# of Fedora, adding rpaths goes against the packaging guidelines.49if [ -n "${LD_LIBRARY_PATH}" ]; then50export LD_LIBRARY_PATH="${LibDir}:${LD_LIBRARY_PATH}"51else52export LD_LIBRARY_PATH="${LibDir}"53fi54}555657example_test_case() {58local name="${1}"; shift5960atf_test_case "${name}"61eval "${name}_head() { \62atf_set 'require.files' '${ExamplesDir}/${name}.cpp'; \63atf_set 'require.progs' 'make pkg-config'; \64}"65eval "${name}_body() { \66make_example '${name}'; \67${name}_validate; \68}"69}707172example_test_case bindings73bindings_validate() {74atf_check -s exit:0 -o inline:'120\n' ./bindings 575atf_check -s exit:1 -e match:'Argument.*must be an integer' ./bindings foo76atf_check -s exit:1 -e match:'Argument.*must be positive' ./bindings -577}787980example_test_case hello81hello_validate() {82atf_check -s exit:0 -o inline:'Hello, world!\n' ./hello83}848586example_test_case interpreter87interpreter_validate() {88cat >script.lua <<EOF89test_variable = 1234590print("From the interpreter: " .. (test_variable - 345))91EOF9293atf_check -s exit:0 -o match:"From the interpreter: 12000" \94-x "./interpreter <script.lua"95}969798example_test_case raii99raii_validate() {100cat >expout <<EOF101String in field foo: hello102String in field bar: 123103String in field baz: bye104EOF105atf_check -s exit:0 -o file:expout ./raii106}107108109atf_init_test_cases() {110atf_add_test_case bindings111atf_add_test_case hello112atf_add_test_case interpreter113atf_add_test_case raii114}115116117