-
Notifications
You must be signed in to change notification settings - Fork 12
/
Gruntfile.coffee
154 lines (133 loc) · 4.13 KB
/
Gruntfile.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
fs = require 'fs'
execSync = require('child_process').execSync
test_path = './test_set/'
#test_sets = ['Text', 'NonText']
test_sets = ['good', 'bad']
module.exports = ->
grunt = @
# Project configuration
@initConfig
pkg: @file.readJSON 'package.json'
# Updating the package manifest files
noflo_manifest:
update:
files:
'component.json': ['graphs/*', 'components/*']
'package.json': ['graphs/*', 'components/*']
# CoffeeScript compilation
coffee:
spec:
options:
bare: true
expand: true
cwd: 'spec'
src: ['**.coffee']
dest: 'spec'
ext: '.js'
test_sets:
options:
bare: true
expand: true
cwd: 'test_set_app'
src: ['**/*.coffee']
dest: 'test_set_app'
ext: '.js'
test_scale:
options:
bare: true
expand: true
cwd: 'test_scale_app'
src: ['**/*.coffee']
dest: 'test_scale_app'
ext: '.js'
root:
options:
bare: true
expand: true
cwd: '.'
src: ['**.coffee']
dest: '.'
ext: '.js'
# Automated recompilation and testing when developing
watch:
files: ['spec/*.coffee', 'components/*.coffee']
tasks: ['test']
# BDD tests on Node.js
mochaTest:
nodejs:
src: ['spec/*.coffee']
options:
reporter: 'spec'
# Coding standards
coffeelint:
components: ['components/*.coffee', 'Gruntfile.coffee', 'spec/*.coffee', 'test_set_app/*.coffee']
options:
'max_line_length':
'level': 'ignore'
# Compiles GMR Saliency C++ code using node-gyp
gyp:
saliency:
command: 'rebuild'
# GMR Saliency doesn't has itself as dependency, so
# for tests, symlink the executable
symlink:
options:
overwrite: true
explicit:
src: 'build/Release/saliency'
dest: 'node_modules/.bin/saliency'
@registerTask 'test_set', 'Test a set of images', () ->
data = {}
for set in test_sets
console.log 'Testing set ' + set
data[set] = []
dir = test_path + set
imgs = fs.readdirSync dir
for img in imgs
unless /filtered|threshold|contours|saliency|histogram_saliency|DS_Store/.test img
img = img.replace /\s/g, '\\ '
abspath = dir + '/' + img
console.log ' ' + abspath
output = execSync './build/Release/saliency ' + abspath
console.log ' ' + abspath + ' finished.'
data[set].push
image: abspath
measurement: JSON.parse output
grunt.file.write './test_set_app/data.js', 'window.DATA = {sets:' + JSON.stringify(data, 1, 1) + '};'
@registerTask 'test_scale', 'Test if saliency performs well with scaled images', () ->
data = {}
for set in test_sets
console.log 'Testing set ' + set
data[set] = []
dir = test_path + set
imgs = fs.readdirSync dir
for img in imgs
unless /filtered|threshold|contours|saliency|DS_Store/.test img
img = img.replace /\s/g, '\\ '
abspath = dir + '/' + img
console.log ' ' + abspath
output = execSync 'node measure_image.js ' + abspath
console.log ' ' + abspath + ' finished.'
console.log output
data[set].push
image: abspath
measurement: JSON.parse output
grunt.file.write './test_scale_app/data.js', 'window.DATA = {sets:' + JSON.stringify(data, 1, 1) + '};'
@registerTask 'test', 'Build and run automated tests', () =>
@task.run 'gyp'
@task.run 'symlink'
@task.run 'coffeelint'
@task.run 'noflo_manifest'
@task.run 'coffee:spec'
@task.run 'mochaTest'
# Grunt plugins used for building
@loadNpmTasks 'grunt-noflo-manifest'
@loadNpmTasks 'grunt-contrib-coffee'
# Grunt plugins used for testing
@loadNpmTasks 'grunt-contrib-watch'
@loadNpmTasks 'grunt-mocha-test'
@loadNpmTasks 'grunt-coffeelint'
@loadNpmTasks 'grunt-node-gyp'
@loadNpmTasks 'grunt-contrib-symlink'
@registerTask 'test_app', ['test_sets']
@registerTask 'default', ['test']