Sha256: 30e4dad5d8148f7698a8792e76fd9a5e979c0828aa2f966c2c057350e20e98e0

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

#!/usr/bin/env bash
set -e

encode_name() {
  local name="$1"
  local result="test_"

  if [[ ! "$name" =~ [^[:alnum:]\ _-] ]]; then
    name="${name//_/-5f}"
    name="${name//-/-2d}"
    name="${name// /_}"
    result+="$name"
  else
    local length="${#name}"
    local char i

    for ((i=0; i<length; i++)); do
      char="${name:$i:1}"
      if [ "$char" = " " ]; then
        result+="_"
      elif [[ "$char" =~ [[:alnum:]] ]]; then
        result+="$char"
      else
        result+="$(printf -- "-%02x" \'"$char")"
      fi
    done
  fi

  echo "$result"
}

tests=()
index=0
pattern='^ *@test  *([^ ].*)  *\{ *(.*)$'

while IFS= read -r line; do
  let index+=1
  if [[ "$line" =~ $pattern ]]; then
    quoted_name="${BASH_REMATCH[1]}"
    body="${BASH_REMATCH[2]}"
    name="$(eval echo "$quoted_name")"
    encoded_name="$(encode_name "$name")"
    tests["${#tests[@]}"]="$encoded_name"
    echo "${encoded_name}() { bats_test_begin ${quoted_name} ${index}; ${body}"
  else
    printf "%s\n" "$line"
  fi
done

for test_name in "${tests[@]}"; do
  echo "bats_test_function ${test_name}"
done

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
busser-bats-0.5.0 vendor/bats/libexec/bats-preprocess
busser-bats-0.4.0 vendor/bats/libexec/bats-preprocess
busser-bats-0.3.0 vendor/bats/libexec/bats-preprocess