UNPKG

3.33 kBPlain TextView Raw
1-RELEASE_DIR := out/release/
2-COVERAGE_DIR := out/test/
3-RELEASE_COPY := lib
4-COVERAGE_COPY := lib tests
5
6
7-BIN_MOCHA := ./node_modules/.bin/mocha
8-BIN_JSCOVER := ./node_modules/.bin/jscover
9-BIN_COFFEE := ./node_modules/coffee-script/bin/coffee
10-BIN_YAML := ./node_modules/.bin/yaml2json -sp
11
12-TESTS := $(shell find tests -type f -name 'test-*')
13
14-COFFEE_LIB := $(shell find lib -type f -name '*.coffee')
15-COFFEE_TEST := $(shell find tests -type f -name 'test-*.coffee')
16
17-COFFEE_RELEASE := $(addprefix $(-RELEASE_DIR),$(-COFFEE_LIB) )
18
19-COFFEE_COVERAGE := $(-COFFEE_LIB)
20-COFFEE_COVERAGE += $(-COFFEE_TEST)
21-COFFEE_COVERAGE := $(addprefix $(-COVERAGE_DIR),$(-COFFEE_COVERAGE) )
22
23-COVERAGE_FILE := coverage.html
24-COVERAGE_TESTS := $(addprefix $(-COVERAGE_DIR),$(-TESTS))
25-COVERAGE_TESTS := $(-COVERAGE_TESTS:.coffee=.js)
26
27default: dev
28
29json:
30 @echo "make package.json"
31 @$(-BIN_YAML) ./package.yaml
32
33
34dev: clean json
35 @$(-BIN_MOCHA) \
36 --colors \
37 --compilers coffee:coffee-script/register \
38 --reporter list \
39 --growl \
40 $(-TESTS)
41
42test: clean json
43 @$(-BIN_MOCHA) \
44 --compilers coffee:coffee-script/register \
45 --reporter tap \
46 $(-TESTS)
47
48release: dev
49 @echo 'copy files'
50 @mkdir -p $(-RELEASE_DIR)
51 @cp -r $(-RELEASE_COPY) $(-RELEASE_DIR)
52
53 @echo "compile coffee-script files"
54 @$(-BIN_COFFEE) -cb $(-COFFEE_RELEASE)
55 @rm -f $(-COFFEE_RELEASE)
56
57 @echo "all codes in \"$(-RELEASE_DIR)\""
58
59
60test-cov: clean json
61 @echo 'copy files'
62 @mkdir -p $(-COVERAGE_DIR)
63 @cp -r $(-COVERAGE_COPY) $(-COVERAGE_DIR)
64
65 @echo "compile coffee-script files"
66 @$(-BIN_COFFEE) -cb $(-COFFEE_COVERAGE)
67 @rm -f $(-COFFEE_COVERAGE)
68
69 @echo "generate coverage files"
70 @$(-BIN_JSCOVER) $(-COVERAGE_DIR)/lib $(-COVERAGE_DIR)/lib
71
72 @echo "run test"
73 @$(-BIN_MOCHA) \
74 --reporter tap \
75 $(-COVERAGE_TESTS)
76
77 @echo "make coverage report"
78
79 @if [ `echo $$OSTYPE | grep -c 'darwin'` -eq 1 ]; then \
80 echo "coverage info"; \
81 $(-BIN_MOCHA) \
82 --reporter html-cov \
83 $(-COVERAGE_TESTS) \
84 > $(-COVERAGE_FILE); \
85 echo "test report saved \"$(-COVERAGE_FILE)\""; \
86 open $(-COVERAGE_FILE); \
87 else \
88 $(-BIN_MOCHA) \
89 --reporter json-cov \
90 $(-COVERAGE_TESTS) \
91 > $(-COVERAGE_DIR)/cov.json; \
92 echo "cov = require './$(-COVERAGE_DIR)/cov.json'\npad = (num) ->\n if num < 10 then ' ' + num.toString()\n else if num < 100 then ' ' + num.toString()\n else if num < 1000 then ' ' + num.toString()\n else num.toString()\ncolor = (cover) ->\n if cover >= 90 then '\x1B[32m'\n else if cover >= 80 then '\x1B[36m'\n else if cover >= 70 then '\x1B[33m'\n else '\x1B[31m'\nend = '\x1B[0m'\nconsole.log '---------- \x1B[36mSummary' + end + ' ----------'\nconsole.log 'coverage: ', color(cov.coverage) + Math.round(cov.coverage) + '%' + end\nconsole.log 'sloc: ', cov.sloc, 'lines'\nconsole.log 'hits: ', cov.hits, 'lines'\nconsole.log 'misses: ', cov.misses, 'lines'\nfor file in cov.files\n console.log '---- \x1B[36m' + file.filename+':', color(file.coverage) + Math.round(file.coverage) + '%', end + '----'\n for num, line of file.source\n if line.coverage is 0 \n head = '\x1B[31m'\n else\n head = '\x1B[32m'\n console.log head + pad(num), '|', line.source + end" | $(-BIN_COFFEE) --stdio ; \
93 fi
94
95.-PHONY: default
96
97clean:
98 @echo 'clean'
99 @-rm -fr out
100 @-rm -f package.json
101 @-rm -f coverage.html
102
103