test-utils.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/bash
  2. # Copyright 2021, gRPC Authors All rights reserved.
  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. # This script contains part of SwiftNIO's test_functions.sh script. The license
  16. # for the original work is reproduced below. See NOTICES.txt for more.
  17. ##===----------------------------------------------------------------------===##
  18. ##
  19. ## This source file is part of the SwiftNIO open source project
  20. ##
  21. ## Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
  22. ## Licensed under Apache License v2.0
  23. ##
  24. ## See LICENSE.txt for license information
  25. ## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
  26. ##
  27. ## SPDX-License-Identifier: Apache-2.0
  28. ##
  29. ##===----------------------------------------------------------------------===##
  30. function fail() {
  31. echo >&2 "FAILURE: $*"
  32. false
  33. }
  34. function assert_less_than() {
  35. if [[ ! "$1" -lt "$2" ]]; then
  36. fail "assertion '$1' < '$2' failed"
  37. fi
  38. }
  39. function assert_less_than_or_equal() {
  40. if [[ ! "$1" -le "$2" ]]; then
  41. fail "assertion '$1' <= '$2' failed"
  42. fi
  43. }
  44. function assert_greater_than() {
  45. if [[ ! "$1" -gt "$2" ]]; then
  46. fail "assertion '$1' > '$2' failed"
  47. fi
  48. }
  49. g_has_previously_infoed=false
  50. function info() {
  51. if ! $g_has_previously_infoed; then
  52. echo || true # echo an extra newline so it looks better
  53. g_has_previously_infoed=true
  54. fi
  55. echo "info: $*" || true
  56. }
  57. function warn() {
  58. echo "warning: $*"
  59. }