Skip to content

Instantly share code, notes, and snippets.

@eksperimental
Last active November 10, 2015 17:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eksperimental/80c31600308a31c9b630 to your computer and use it in GitHub Desktop.
Save eksperimental/80c31600308a31c9b630 to your computer and use it in GitHub Desktop.
A script to ease development of the Elixir programming code base. Allowing the developer to run selected tests.
#!/bin/sh
# make-test-file
# https://git.io/make-test-file
#
# DESCRIPTION:
# make-test-file is a script to ease development of the Elixir programming code
# base. Allowing the developer to run selected tests.
#
# INTRODUCTION:
# This script will only be useful if you are hacking into the source code of the
# Elixir programming language itself.
# It eases the process of running a test of a single or multiple test files,
# without the need to have to run all the test in the project.
#
# Normally, if you are editing a file in the elixir project, you will have to
# run the test by doing:
# $ make test_stdlib
# and all the tests in the elixir project will be executed,
# while if you know the test you need to check, you can just do for example:
# $ ./make-test-file lib/elixir/test/elixir/integer_test.exs
# or you can run multiple tests:
# $ ./make-test-file lib/elixir/test/elixir/range_test.exs \
# lib/elixir/test/elixir/kernel_test.exs \
# lib/elixir/test/elixir/kernel/*_test.exs
#
# USAGE:
# $ ./make-test-file TEST_FILE [TEST_FILE ...]
#
# INSTALLATION:
# 1. Enter to the root folder of Elixir.
# $ cd ~/git/elixir
#
# 2. Download this script and make it executable
# $ curl -o make-test-file -sSfL https://git.io/make-test-file_raw
# $ chmod +x make-test-file
#
# 3. Add this script to the files that you want to ignore in this project
# $ git config --local --add core.excludesfile ~/.gitignore_elixir
# $ echo "/make-test-file" >> ~/.gitignore_elixir
#
# CONTRIBUTE:
# This script will be maintained, so please send your suggestions or
# improvements to:
# https://git.io/make-test-file
#
# LICENSE:
# This script was written by eksperimental
# https://github.com/eksperimental/
# Released under the Public Domain. Do whatever you want with it.
PROJECTS="elixir eex ex_unit iex logger mix"
FILES=$(echo "${@}" | sed -e 's/\s\+/\n/g' | sort | uniq)
# TODO: WARN provided file is not found
# test_file PROJECT
test_file(){
local PROJECT="${1}"
if [ "${PROJECT}" = "elixir" ]; then
local HELPER="test/elixir/test_helper.exs"
else
local HELPER="test/test_helper.exs"
fi
local FILES_PATH="$(echo "${FILES}" | grep "^lib/${PROJECT}/" | cut -d'/' -f3-)"
if [ -n "${FILES_PATH}" ]; then
local PR="$(for f in ${FILES_PATH}; do echo " -pr ${f}"; done)"
PR="$(echo ${PR} | sed -e 's/\n\+/ /g')"
echo "==> ${PROJECT} (exunit)";
echo "==> files: $(echo ${FILES_PATH} | sed -e 's/\s\+/ /g')"
cd lib/"${PROJECT}"
if [ "${OS}" = "Windows_NT" ]; then
cmd //C call ../../bin/elixir.bat -r "${HELPER}" ${PR}
else
../../bin/elixir -r "${HELPER}" ${PR}
fi;
cd ../../
fi
}
if [ -n "${FILES}" ]; then
make compile && (
exec epmd &
for p in ${PROJECTS}; do
test_file "${p}"
done
)
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment