#!/bin/bash # This code should almost never use plain time functions like time.Now(), # time.Since(), etc, because we should use mockable clock functions instead, # for the time-related tests to work. # # I already wasted some time trying to debug tests which were failing just # because I accidentally used plain time functions, so I wrote this script to # to ensure that. # # On those rare occassions when we do want plain time functions, we also should # place the guard comment: YES_I_WANT_PLAIN_TIME. This script will not complain # about those. guard="YES_I_WANT_PLAIN_TIME" path="$1" if [[ "$path" == "" ]]; then echo "Usage: $0 " exit 1 fi grep -r 'time\.\(Now\|After\|Since\|Sleep\|Tick\|Timer\)' "${path}" \ | grep -v "${guard}" if [[ "$?" == "0" ]]; then echo "" echo "^^^" echo "Error: found occurrences of plain time functions not guarded with ${guard}" exit 1 fi echo "OK: no occurrences of plain time functions found." exit 0