Sha256: ce23d683b533efae45f2c86553d793ce9c597301c48250c24a88184084a33600

Contents?: true

Size: 1.8 KB

Versions: 281

Compression:

Stored size: 1.8 KB

Contents

#!/bin/sh

# This file moves all stub files out of the way so that they don't get built,
# runs the tests, then moves the stub files back.

# We use this instead of build constraints to have less noise in stub files.
# Newcomers to go might be confused by build constraints

# It's useful to move the stub files back instead of outright deleting them.
# That way no maintainer will mistakenly commit the deleted files,
# which could otherwise happen after running tests locally.

for dir in exercises/*/; do
  stub=$(echo $(basename $dir) | tr - _)
  file="$dir/$stub.go"
  if [ -f $file ]; then
    echo "moving stub $file"
    mv $file "$dir/$stub.notgo"
  fi
done

root=$(pwd)

cleanup () {
  echo "moving stub files back"
  # the cd for go fmt or go vet could leave us in an unexpected place.
  # cd to a known place.
  cd "$root"

  # could use `rename` here, but it's not uniform among platforms.
  # some renames take two arguments while others take a single regex.
  for file in exercises/*/*.notgo; do
    dir=$(dirname $file)
    base=$(basename $file .notgo)
    mv "$dir/$base.notgo" "$dir/$base.go"
  done
}

trap cleanup EXIT INT TERM

if [ "$1" = "fmt" ]; then
  for dir in exercises/*/; do
    cd $dir
    if [ -n "$(go fmt)" ]; then
      echo "please run 'go fmt' on $dir" >&2
      exit 1
    fi
    cd "$root"
  done
  exit 0
fi

if [ "$1" = "vet" ]; then
  for dir in exercises/*/; do
    cd $dir
    if ! go vet; then
      echo "please follow the 'go vet' suggestions in $dir" >&2
      exit 1
    fi
    cd "$root"
  done
  exit 0
fi

# This is the last command in the file,
# so the exit status of this script is the exit status of go test.
# If this ever changes, remember to preserve the exit status accordingly.
# Otherwise Travis may falsely report a test as passed when it has failed.
go test -cpu 2 $RACE ./...

Version data entries

281 entries across 281 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/go/bin/test-without-stubs
trackler-2.2.1.179 tracks/go/bin/test-without-stubs
trackler-2.2.1.178 tracks/go/bin/test-without-stubs
trackler-2.2.1.177 tracks/go/bin/test-without-stubs
trackler-2.2.1.176 tracks/go/bin/test-without-stubs
trackler-2.2.1.175 tracks/go/bin/test-without-stubs
trackler-2.2.1.174 tracks/go/bin/test-without-stubs
trackler-2.2.1.173 tracks/go/bin/test-without-stubs
trackler-2.2.1.172 tracks/go/bin/test-without-stubs
trackler-2.2.1.171 tracks/go/bin/test-without-stubs
trackler-2.2.1.170 tracks/go/bin/test-without-stubs
trackler-2.2.1.169 tracks/go/bin/test-without-stubs
trackler-2.2.1.167 tracks/go/bin/test-without-stubs
trackler-2.2.1.166 tracks/go/bin/test-without-stubs
trackler-2.2.1.165 tracks/go/bin/test-without-stubs
trackler-2.2.1.164 tracks/go/bin/test-without-stubs
trackler-2.2.1.163 tracks/go/bin/test-without-stubs
trackler-2.2.1.162 tracks/go/bin/test-without-stubs
trackler-2.2.1.161 tracks/go/bin/test-without-stubs
trackler-2.2.1.160 tracks/go/bin/test-without-stubs