Sha256: bf0dd9a897f4995b530f8be2860c5c386353382b01fd8b9582303c4a5d389a2f

Contents?: true

Size: 1.15 KB

Versions: 221

Compression:

Stored size: 1.15 KB

Contents

#!/usr/bin/env bash
# Run the given SCRIPT and expect its exit code to be EXPECTED_EXIT_CODE and its
# output to include the given EXPECTED_TEXT.
# If the expectation succeeds, exit with 0, otherwise exit with 1.
# This is useful when you want don't care about a script's exit code but only
# care about its output.

SCRIPT=$1
EXPECTED_EXIT_CODE=$2
EXPECTED_TEXT=$3

mkdir -p gitlab-qa-run-expect_text
log_file="gitlab-qa-run-expect_text/log.txt"

if [ -z "$SCRIPT" ] || [ -z "$EXPECTED_EXIT_CODE" ] || [ -z "$EXPECTED_TEXT" ]; then
  echo "Missing argument(s) - Use: $0 script expected_exit_code expected_text"
else
  $SCRIPT > $log_file
  SCRIPT_EXIT_CODE=$?

  if [ "$SCRIPT_EXIT_CODE" -eq "$EXPECTED_EXIT_CODE" ]
  then
    echo "'$SCRIPT' exited with '$SCRIPT_EXIT_CODE', as expected!"
    grep "$EXPECTED_TEXT" $log_file > /dev/null

    if [ "$?" -eq "0" ]; then
      echo "'$SCRIPT' outputted '$EXPECTED_TEXT', as expected!"
    else
      echo "'$SCRIPT' was expected to output '$EXPECTED_TEXT', but did not!"
      exit 1
    fi
  else
    echo "'$SCRIPT' was expected to exit with '$EXPECTED_EXIT_CODE', but exited with '$SCRIPT_EXIT_CODE' instead!"
    exit 1
  fi
fi

Version data entries

221 entries across 221 versions & 1 rubygems

Version Path
gitlab-qa-8.7.0 bin/expect_exit_code_and_text
gitlab-qa-8.6.0 bin/expect_exit_code_and_text
gitlab-qa-8.5.0 bin/expect_exit_code_and_text
gitlab-qa-8.4.2 bin/expect_exit_code_and_text
gitlab-qa-8.4.1 bin/expect_exit_code_and_text
gitlab-qa-8.4.0 bin/expect_exit_code_and_text
gitlab-qa-8.3.2 bin/expect_exit_code_and_text
gitlab-qa-8.3.1 bin/expect_exit_code_and_text
gitlab-qa-8.3.0 bin/expect_exit_code_and_text
gitlab-qa-8.2.0 bin/expect_exit_code_and_text
gitlab-qa-8.1.0 bin/expect_exit_code_and_text
gitlab-qa-8.0.0 bin/expect_exit_code_and_text
gitlab-qa-7.36.0 bin/expect_exit_code_and_text
gitlab-qa-7.35.0 bin/expect_exit_code_and_text
gitlab-qa-7.34.0 bin/expect_exit_code_and_text
gitlab-qa-7.33.0 bin/expect_exit_code_and_text
gitlab-qa-7.32.0 bin/expect_exit_code_and_text
gitlab-qa-7.31.0 bin/expect_exit_code_and_text
gitlab-qa-7.30.0 bin/expect_exit_code_and_text
gitlab-qa-7.29.1 bin/expect_exit_code_and_text