#!/bin/bash

function init_env
{
  unset -v src_script_path external_script_path EASY_KERNEL_WORKFLOW
  external_script_path="tests/external"
  src_script_path="./src"
  export src_script_path external_script_path EASY_KERNEL_WORKFLOW
}

# Receives a string with one or more lines and print each of
# then prefixed by "> "
function prefix_multiline
{
  echo "$@" | sed -E "s/^/> /g"
}

# Receives a path and creates a fake kernel root in it. The goal is to make this
# path recognizable by src/kwlib.sh:is_kernel_root().
function mk_fake_kernel_root
{
  local -r path="$1"
  mkdir -p "$path"
  touch "$path/COPYING"
  touch "$path/CREDITS"
  touch "$path/Kbuild"
  touch "$path/Makefile"
  touch "$path/README"
  touch "$path/MAINTAINERS"
  mkdir -p "$path/Documentation"
  mkdir -p "$path/arch"
  mkdir -p "$path/include"
  mkdir -p "$path/drivers"
  mkdir -p "$path/fs"
  mkdir -p "$path/init"
  mkdir -p "$path/ipc"
  mkdir -p "$path/kernel"
  mkdir -p "$path/lib"
  mkdir -p "$path/scripts"
}

function invoke_shunit
{
  command -v shunit2 > /dev/null
  if [[ "$?" -eq 0 ]]; then
    . shunit2
  elif [[ -f ./tests/shunit2 ]]; then
    . ./tests/shunit2
  else
    echo -e "Can't find shunit2.\nDo you have it installed (or downloaded it to ./tests/shunit2)?"
    return 1
  fi
}
