1#!/usr/bin/env bash
2#
3# installation-scripts.sh
4#
5# -- This script tests the bash scripts that install OpenCoarrays and its prerequisites.
6#
7# OpenCoarrays is distributed under the OSI-approved BSD 3-clause License:
8# Copyright (c) 2015-2016, Sourcery, Inc.
9# Copyright (c) 2015-2016, Sourcery Institute
10# All rights reserved.
11#
12# Redistribution and use in source and binary forms, with or without modification,
13# are permitted provided that the following conditions are met:
14#
15# 1. Redistributions of source code must retain the above copyright notice, this
16#    list of conditions and the following disclaimer.
17# 2. Redistributions in binary form must reproduce the above copyright notice, this
18#    list of conditions and the following disclaimer in the documentation and/or
19#    other materials provided with the distribution.
20# 3. Neither the names of the copyright holders nor the names of their contributors
21#    may be used to endorse or promote products derived from this software without
22#    specific prior written permission.
23#
24# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27# IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33# POSSIBILITY OF SUCH DAMAGE.
34#
35# Portions of this script derive from BASH3 Boilerplate and are distributed under
36# the following license:
37#
38# The MIT License (MIT)
39#
40# Copyright (c) 2014 Kevin van Zonneveld
41#
42# Permission is hereby granted, free of charge, to any person obtaining a copy
43# of this software and associated documentation files (the "Software"), to deal
44# in the Software without restriction, including without limitation the rights
45# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
46# copies of the Software, and to permit persons to whom the Software is
47# furnished to do so, subject to the following conditions:
48#
49# The above copyright notice and this permission notice shall be included in all
50# copies or substantial portions of the Software.
51#
52# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
54# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
55# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
56# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
57# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
58# SOFTWARE.
59#
60#
61#  - https://github.com/kvz/bash3boilerplate
62#  - http://kvz.io/blog/2013/02/26/introducing-bash3boilerplate/
63#
64# Version: 2.0.0
65#
66# Authors:
67#
68#  - Kevin van Zonneveld (http://kvz.io)
69#  - Izaak Beekman (https://izaakbeekman.com/)
70#  - Alexander Rathai (Alexander.Rathai@gmail.com)
71#  - Dr. Damian Rouson (http://www.sourceryinstitute.org/) (documentation)
72#
73# Licensed under MIT
74# Copyright (c) 2013 Kevin van Zonneveld (http://kvz.io)
75
76# The invocation of bootstrap.sh below performs the following tasks:
77# (1) Import several bash3boilerplate helper functions & default settings.
78# (2) Set several variables describing the current file and its usage page.
79# (3) Parse the usage information (default usage file name: current file's name with -usage appended).
80# (4) Parse the command line using the usage information.
81
82set -o errtrace
83
84if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
85  # shellcheck disable=SC2154
86  if [[ "${__usage+x}" ]]; then
87    __b3bp_tmp_source_idx=1
88  fi
89fi
90
91# Set magic variables for current file, directory, os, etc.
92__dir="$(cd "$(dirname "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")" && pwd)"
93__file="${__dir}/$(basename "${BASH_SOURCE[${__b3bp_tmp_source_idx:-0}]}")"
94
95# requires `set -o errtrace`
96__b3bp_err_report() {
97  local error_code
98  error_code=${?}
99  error "Error in ${__file} in function ${1} on line ${2}"
100  exit ${error_code}
101}
102# Uncomment the following line for always providing an error backtrace
103trap '__b3bp_err_report "${FUNCNAME:-.}" ${LINENO}' ERR
104
105### Start of boilerplate -- do not edit this block #######################
106export OPENCOARRAYS_SRC_DIR="${OPENCOARRAYS_SRC_DIR:-${PWD%/}/../../..}"
107if [[ ! -f "${OPENCOARRAYS_SRC_DIR}/src/libcaf.h" ]]; then
108  echo "Please run this script inside the OpenCoarrays source sudirectory src/tests/instsallation"
109  echo "or set OPENCOARRAYS_SRC_DIR to the OpenCoarrays source directory path."
110  exit 1
111fi
112export B3B_USE_CASE="${B3B_USE_CASE:-${OPENCOARRAYS_SRC_DIR}/prerequisites/use-case}"
113if [[ ! -f "${B3B_USE_CASE:-}/bootstrap.sh" ]]; then
114  echo "Please set B3B_USE_CASE to the bash3boilerplate use-case directory path."
115  exit 2
116else
117  # shellcheck source=../../../prerequisites/use-case/bootstrap.sh
118  source "${B3B_USE_CASE}/bootstrap.sh" "$@"
119fi
120### End of boilerplate -- start user edits below #########################
121
122# Set expected value of present flags that take no arguments
123export __flag_present=1
124
125# Set up a function to call when receiving an EXIT signal to do some cleanup. Remove if
126# not needed. Other signals can be trapped too, like SIGINT and SIGTERM.
127function cleanup_before_exit() {
128  info "Cleaning up. Done"
129}
130trap cleanup_before_exit EXIT # The signal is specified here. Could be SIGINT, SIGTERM etc.
131
132pushd "${OPENCOARRAYS_SRC_DIR}"/src/tests/installation
133
134# shellcheck source=../../../prerequisites/stack.sh
135source "${OPENCOARRAYS_SRC_DIR}"/prerequisites/stack.sh
136source test-stack.sh
137test_stack
138
139popd
140