#!/usr/bin/env bash

# Test everything that is automatable.

top="$(pwd)"

# make test
for t in \
    c \
    c_from_cpp \
    c/extern \
    c/static/function \
    c/static/variable \
    cpp \
    cpp_from_c \
    cpp/extern_const \
    cpp/inline_variable \
    gcc \
    gcc/weak \
    glibc \
    linker/incremental_link \
    linker/variable_address \
    posix \
    shared_library/basic \
    shared_library/lib_lib_dependency \
    shared_library/symbol_version \
  ; do
  if ! make -C "$t" -j`nproc` test; then
    echo "TEST FAILED: $t"
    exit 1
  fi
done

# make only
for t in \
    c/interactive \
    cpp/interactive \
    glibc/interactive \
    posix/curses \
    posix/interactive \
    posix/socket \
  ; do
  if ! make -C "$t" -j`nproc`; then
    echo "TEST FAILED: $t"
    exit 1
  fi
done

# ./test only
for t in \
    scons \
  ; do
  cd "${top}/${t}"
  if ! ./test; then
    echo "TEST FAILED: $t"
    exit 1
  fi
done
echo "ALL TESTS PASSED"
exit 0
