Sha256: a4f84f9e050edddd3cac57cdec087ee041ac265bbbbdc9cfa1716ca35afaa683

Contents?: true

Size: 1.8 KB

Versions: 52

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 acordingly.
# Otherwise Travis may falsely report a test as passed when it has failed.
go test -cpu 2 $RACE ./...

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
trackler-2.0.8.14 tracks/go/bin/test-without-stubs
trackler-2.0.8.13 tracks/go/bin/test-without-stubs
trackler-2.0.8.12 tracks/go/bin/test-without-stubs
trackler-2.0.8.11 tracks/go/bin/test-without-stubs
trackler-2.0.8.10 tracks/go/bin/test-without-stubs
trackler-2.0.8.9 tracks/go/bin/test-without-stubs
trackler-2.0.8.8 tracks/go/bin/test-without-stubs
trackler-2.0.8.7 tracks/go/bin/test-without-stubs
trackler-2.0.8.6 tracks/go/bin/test-without-stubs
trackler-2.0.8.5 tracks/go/bin/test-without-stubs
trackler-2.0.8.4 tracks/go/bin/test-without-stubs
trackler-2.0.8.3 tracks/go/bin/test-without-stubs
trackler-2.0.8.2 tracks/go/bin/test-without-stubs
trackler-2.0.8.1 tracks/go/bin/test-without-stubs
trackler-2.0.7.0 tracks/go/bin/test-without-stubs
trackler-2.0.6.44 tracks/go/bin/test-without-stubs
trackler-2.0.6.43 tracks/go/bin/test-without-stubs
trackler-2.0.6.42 tracks/go/bin/test-without-stubs
trackler-2.0.6.41 tracks/go/bin/test-without-stubs
trackler-2.0.6.40 tracks/go/bin/test-without-stubs