github.com/rohankumardubey/cilium@v1.6.12/contrib/shell/test.sh (about)

     1  #!/bin/bash
     2  # Copyright 2017-2019 Authors of Cilium
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #     http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  readonly reset=$(tput sgr0)
    17  readonly red=$(tput bold; tput setaf 1)
    18  readonly green=$(tput bold; tput setaf 2)
    19  readonly yellow=$(tput bold; tput setaf 3)
    20  
    21  # Watch a file or directory for changes and trigger some action at that time.
    22  #
    23  # $1 = File to watch
    24  # $2+ = Command and arguments
    25  function watchdo
    26  {
    27      local FILE=$1
    28      shift
    29  
    30      if [ ! -z "$TESTPKGS" ]; then
    31          echo -e "${yellow}Using TESTPKGS=\"$TESTPKGS\" for run.${reset}"
    32      fi
    33      echo -e "${yellow}Running \"$@\" on changes to \"$FILE\" ...${reset}"
    34      while inotifywait -q -r -e move $FILE; do
    35          eval "$@";
    36          if [ $? == 0 ] ; then
    37              echo -e "${yellow}$@${reset}: ${green}✔${reset}"
    38          else
    39              echo -e "${yellow}$@${reset}: ${red}✘${reset}"
    40          fi
    41      done
    42  }
    43  
    44  function watchtest_
    45  {
    46  
    47      watchdo "." "make --quiet build unit-tests"
    48  }
    49  
    50  # Watch a file or directory for changes and trigger tests when it is modified.
    51  #
    52  # $1 = Filepath to watch under cilium directory
    53  function watchtest
    54  {
    55      if [ $# -gt 1 ]; then
    56          echo "usage: $0 <package>"
    57          exit 1
    58      elif ! which inotifywait >/dev/null; then
    59          echo "Cannot find 'inotifywait'. Please install inotify-tools."
    60          exit 1
    61      elif [ $# -eq 1 ]; then
    62          TESTPKGS="$1" watchtest_
    63      else
    64          watchtest_
    65      fi
    66  }