#!/bin/bash

# BEGIN_COPYRIGHT
#
# Copyright 2009-2019 CRS4.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# END_COPYRIGHT

this="${BASH_SOURCE-$0}"
this_dir=$(cd -P -- "$(dirname -- "${this}")" && pwd -P)
. "${this_dir}/config.sh"

trap exit ERR

examples=(
    hdfs
    input_format
    pydoop_script
    pydoop_submit
    self_contained
    sequence_file
)
some_failed=0

for e in ${examples[@]}; do
    pushd ${e}
    echo -ne "\n\n *** RUNNING ${e} EXAMPLE(S) ***\n\n"
    ./run
    exit_code=$?
    if [ ${exit_code} -ne 0 ]; then
      echo -ne "\n\n #### Error!!  Example ${e} finished with code ${exit_code} ###\n\n" >&2
      some_failed=1
    fi
    popd
done

if [ ${some_failed} -ne 0 ]; then
  echo "##############################################" >&2
  echo "Some examples failed to run correctly.  Please" >&2
  echo "verify your installation"                       >&2
  echo "##############################################" >&2
fi
