# Helper functions for testing Redmine core integrity when plugins are in use.
# Author: Martin Cizek, Orchitech

# https://www.redmine.org/issues/35199
PLUGIN_BREAKING_TESTS=(
  test/{unit,integration}/lib/redmine/hook_test.rb
)
TEST_HIDE_SUFFIX=.exclude

_rename_plugin_breaking_tests()
{
  local src_suffix=$1
  local dest_suffix=$2
  local t

  for t in "${PLUGIN_BREAKING_TESTS[@]}"; do
    if [[ -f "${t}${src_suffix}" ]]; then
      mv "${t}${src_suffix}" "${t}${dest_suffix}"
    elif ! [[ -f "${t}${dest_suffix}" ]]; then
      echo "Plugin-breaking test '$t' not found." >&2
      echo "Please inspect PLUGIN_BREAKING_TESTS." >&2
      exit 2
    fi
  done
}

hide_plugin_breaking_tests()
{
  _rename_plugin_breaking_tests '' "$TEST_HIDE_SUFFIX"
}

reveal_plugin_breaking_tests()
{
  _rename_plugin_breaking_tests "$TEST_HIDE_SUFFIX" ''
}
