summaryrefslogtreecommitdiff
path: root/tests/futility/common.sh
blob: ed187d7b36dbbf5e47210c2749054072826b4da3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Color output encodings.
COL_RED='\E[31;1m'
COL_GREEN='\E[32;1m'
COL_YELLOW='\E[33;1m'
COL_BLUE='\E[34;1m'
COL_STOP='\E[0;m'

# args: [message]
green() {
  echo -e "${COL_GREEN}$*${COL_STOP}"
}

# args: [message]
yellow() {
  echo -e "${COL_YELLOW}WARNING: $*${COL_STOP}"
}

# args: [message]
red() {
  echo -e "${COL_RED}$*${COL_STOP}"
}

# args: [nested level] [message]
error() {
  local lev=${1:-}
  case "${1:-}" in
    [0-9]*)
      lev=$1
      shift
      ;;
    *) lev=0
      ;;
  esac
  local x=$(caller $lev)
  local cline="${x%% *}"
  local cfile="${x#* }"
  cfile="${cfile##*/}"
  local args="$*"
  local spacer="${args:+: }"
  red "at ${cfile}, line ${cline}${spacer}${args}" 1>&2
  exit 1
}