mirror of https://github.com/deuill/fawkss.git
Move from BASH-based task runner to Makefile
This commit is contained in:
parent
98fcc7b634
commit
c270602e37
|
@ -0,0 +1,95 @@
|
|||
# ------------------
|
||||
# Makefile for Fawks
|
||||
# ------------------
|
||||
|
||||
# Run `make help` for information on available actions.
|
||||
|
||||
# --------------------
|
||||
# Variable definitions
|
||||
# --------------------
|
||||
|
||||
# Default name for Fawkss executable.
|
||||
FAWKSS = $(CURDIR)/fawkss
|
||||
|
||||
# Diff executable to use, prefer `colordiff` if installed.
|
||||
DIFF = $(shell which colordiff || which diff)
|
||||
TMPPID = $(shell echo $$PPID)
|
||||
|
||||
# Test files to execute.
|
||||
TESTS ?= $(shell find tests/*.scss)
|
||||
|
||||
# Color & style definitions.
|
||||
BOLD = \033[1m
|
||||
UNDERLINE = \033[4m
|
||||
RED = \033[31m
|
||||
GREEN = \033[32m
|
||||
BLUE = \033[36m
|
||||
RESET = \033[0m
|
||||
|
||||
# ----------------
|
||||
# Other directives
|
||||
# ----------------
|
||||
|
||||
# Make `help` be the default action when no arguments are passed to `make`.
|
||||
.DEFAULT_GOAL = help
|
||||
.PHONY: $(TESTS) test help
|
||||
|
||||
# Awk script for extracting Fawkss documentation as Markdown.
|
||||
define EXTRACT_MARKDOWN
|
||||
/^(#|# .*)$$/ {
|
||||
if (f==1) {f=0; printf "```\n\n"}
|
||||
print substr($$0, 3)
|
||||
}
|
||||
/^[^#]/ {
|
||||
if (f==0) {f=1; printf "\n```awk\n"}
|
||||
print
|
||||
}
|
||||
!NF {
|
||||
print
|
||||
}
|
||||
END {
|
||||
if (f==1) {printf "```\n"}
|
||||
}
|
||||
endef
|
||||
export EXTRACT_MARKDOWN
|
||||
|
||||
# ----------------
|
||||
# Rule definitions
|
||||
# ----------------
|
||||
|
||||
## Build documentation from source file in Markdown format.
|
||||
doc:
|
||||
@awk "$$EXTRACT_MARKDOWN" "$(FAWKSS)"
|
||||
|
||||
## Execute test suite, accepts list of specific files to run.
|
||||
test: test-before $(TESTS) test-after
|
||||
|
||||
test-before:
|
||||
@printf ">> $(BOLD)Executing tests...$(RESET)\n"
|
||||
|
||||
test-after:
|
||||
@printf ">> $(BOLD)Finished executing tests.$(RESET)\n"
|
||||
|
||||
$(TESTS):
|
||||
@awk "/--- TEST ---/ {f=1;next} /--- EXPECTED ---/ {exit} f" $@ >> $@.test.$(TMPPID)
|
||||
@awk "/--- EXPECTED ---/ {f=1;next} /--- END ---/ {exit} f" $@ >> $@.expected.$(TMPPID)
|
||||
|
||||
@$(FAWKSS) $@.test.$(TMPPID) > $@.actual.$(TMPPID)
|
||||
@printf ">> $(BOLD)Testing file '$@'...$(RESET) "
|
||||
|
||||
@result=$$($(DIFF) -ud $@.actual.$(TMPPID) $@.expected.$(TMPPID) | tail -n +3); \
|
||||
if [ -z "$${result}" ]; then \
|
||||
printf "$(GREEN)OK$(RESET)\n"; \
|
||||
else \
|
||||
printf "$(RED)FAIL$(RESET)\n"; \
|
||||
echo "$${result}"; \
|
||||
fi \
|
||||
|
||||
@rm -f $@.test.$(TMPPID) $@.expected.$(TMPPID) $@.actual.$(TMPPID)
|
||||
|
||||
## Show usage information for this Makefile.
|
||||
help:
|
||||
@printf "Fawkss — The simple CSS preprocessor.\n\n"
|
||||
@printf "$(UNDERLINE)Available Tasks$(RESET)\n\n"
|
||||
@awk -F ':|##' '/^##/ {c=$$2; getline; printf "$(BLUE)%10s$(RESET) %s\n", $$1, c}' $(MAKEFILE_LIST)
|
||||
@printf "\n"
|
95
task-runner
95
task-runner
|
@ -1,95 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Task runner for Fawks. Used for producing documentation, running test cases,
|
||||
# and other similar tasks.
|
||||
|
||||
# ----------------
|
||||
# Global variables
|
||||
# ----------------
|
||||
|
||||
# Current working directory.
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# Fawkss main script location.
|
||||
FAWKSS="${ROOT}/fawkss"
|
||||
|
||||
# ANSI Color definitions.
|
||||
WHITE="\033[1m"
|
||||
UNDERLINE="\033[4m"
|
||||
RED="\033[31m"
|
||||
GREEN="\033[32m"
|
||||
BLUE="\033[36m"
|
||||
RESET="\033[0m"
|
||||
|
||||
# ---------------
|
||||
# Task defintions
|
||||
# ---------------
|
||||
|
||||
## doc - Build documentation from source file in Markdown format.
|
||||
function task_doc() {
|
||||
read -d '' extract_markdown <<-'_EOF_'
|
||||
/^(#|# .*)$/ {if (f==1) {f=0; printf "```\\n\\n"} print substr($0, 3)}
|
||||
/^[^#]/ {if (f==0) {f=1; printf "\\n```awk\\n"} print}
|
||||
!NF {print}
|
||||
END {if (f==1) {printf "```\\n"}}
|
||||
_EOF_
|
||||
|
||||
awk "${extract_markdown}" "${FAWKSS}"
|
||||
}
|
||||
|
||||
## test - Execute test suite, accepts list of specific files to run.
|
||||
function task_test() {
|
||||
local differ=$(which colordiff || which diff)
|
||||
local actual="/--- TEST ---/ {f=1;next} /--- EXPECTED ---/ {exit} f"
|
||||
local expected="/--- EXPECTED ---/ {f=1;next} /--- END ---/ {exit} f"
|
||||
local summary=(0 0)
|
||||
|
||||
echo -e ">> ${WHITE}Executing tests...${RESET}"
|
||||
|
||||
for file in ${@:-${ROOT}/tests/*.scss}
|
||||
do
|
||||
# Check if file exists and is readable.
|
||||
if [ ! -f "${file}" ]
|
||||
then
|
||||
echo -e ">> ${RED}Failed to find test file '${file}'${RESET}"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Get diff between expected and actual output.
|
||||
result=$(${differ} -ud <(awk "${expected}" "${file}") <(exec ${FAWKSS} <(awk "${actual}" "${file}")) | tail -n +3)
|
||||
|
||||
# Echo per-test results.
|
||||
echo -ne ">> ${WHITE}Testing file '$(basename ${file})'...${RESET} "
|
||||
|
||||
if [ "x${result}" != "x" ]
|
||||
then
|
||||
printf "${RED}FAIL${RESET}\n${result}\n"
|
||||
summary[0]=$((${summary[0]} + 1))
|
||||
else
|
||||
printf "${GREEN}OK${RESET}\n"
|
||||
summary[1]=$((${summary[1]} + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
printf ">> ${WHITE}summary:${RESET} "
|
||||
printf "Total ${WHITE}$((${summary[0]} + ${summary[1]}))${RESET}, "
|
||||
printf "Failed ${RED}${summary[0]}${RESET}, "
|
||||
printf "Successful ${GREEN}${summary[1]}${RESET}\n"
|
||||
}
|
||||
|
||||
function task_help() {
|
||||
printf "Fawkss — The simple CSS preprocessor.\n\n"
|
||||
printf "${UNDERLINE}Available Tasks${RESET}\n\n"
|
||||
|
||||
tasklist="/^##/ {printf \"${BLUE}%10s${RESET} %s\n\", substr(\$1, 4), \$NF}"
|
||||
awk -F ' - ' "${tasklist}" "${BASH_SOURCE[0]}"
|
||||
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
# --------------
|
||||
# Task execution
|
||||
# --------------
|
||||
|
||||
action=${1:-help}
|
||||
test "$(type -t "task_${action}")" == "function" && task_${action} ${@:2} || task_help
|
Loading…
Reference in New Issue