Skip to content

Commit 249f183

Browse files
Add .editorconfig.
Add failing test for failFast option. Have `nonull: true` cause the task to fail. Update readme to reflect new missing files behavior. Add additional clarification on skipping over missing files. Replace `force` task with a `--force` flag in the call to `exec`. Move readme changes to the docs directory. Remove distracting changes. Update readme.
1 parent de879a5 commit 249f183

6 files changed

Lines changed: 62 additions & 15 deletions

File tree

Gruntfile.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ module.exports = function(grunt) {
4848
'tmp/custom_options': ['test/fixtures/file1', 'test/fixtures/file2']
4949
}
5050
},
51-
handling_invalid_files: {
52-
src: ['test/fixtures/file1', 'invalid_file/should_warn/but_not_fail', 'test/fixtures/file2'],
53-
dest: 'tmp/handling_invalid_files',
54-
nonull: true,
55-
},
5651
process_function: {
5752
options: {
5853
process: function(src, filepath) {
@@ -160,6 +155,31 @@ module.exports = function(grunt) {
160155

161156
});
162157

158+
// Encapsulates tasks which invoke `grunt.fail.warn` and should abort.
159+
grunt.registerTask('concat-warn', function() {
160+
grunt.config('concat', {
161+
handling_invalid_files: {
162+
src: ['test/fixtures/file1', 'invalid_file/should_warn/and_abort', 'test/fixtures/file2'],
163+
dest: 'tmp/handling_invalid_files',
164+
nonull: true
165+
}
166+
});
167+
grunt.task.run(['concat']);
168+
});
169+
170+
// Encapsulates tasks which invoke `grunt.fail.warn` and should abort, but the
171+
// test is checking behavior in the case of a user-specified `--force` flag.
172+
grunt.registerTask('concat-force', function() {
173+
grunt.config('concat', {
174+
handling_invalid_files_force: {
175+
src: ['test/fixtures/file1', 'invalid_file/should_warn/but_not_fail', 'test/fixtures/file2'],
176+
dest: 'tmp/handling_invalid_files_force',
177+
nonull: true
178+
}
179+
});
180+
grunt.task.run(['concat']);
181+
});
182+
163183
// Actually load this plugin's task(s).
164184
grunt.loadTasks('tasks');
165185

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ grunt.initConfig({
236236
```
237237

238238
#### Invalid or Missing Files Warning
239-
If you would like the `concat` task to warn if a given file is missing or invalid be sure to set `nonull` to `true`:
239+
If you would like the `concat` task to warn and abort if a given file is missing or invalid be sure to set `nonull` to `true`:
240240

241241
```js
242242
grunt.initConfig({
@@ -250,6 +250,8 @@ grunt.initConfig({
250250
});
251251
```
252252

253+
Additionally invoke grunt with `--force` to skip over missing files.
254+
253255
See [configuring files for a task](http://gruntjs.com/configuring-tasks#files) for how to configure file globbing in Grunt.
254256

255257

@@ -296,4 +298,4 @@ grunt.initConfig({
296298

297299
Task submitted by ["Cowboy" Ben Alman](http://benalman.com/)
298300

299-
*This file was generated on Wed Feb 18 2015 22:55:48.*
301+
*This file was generated on Thu Feb 19 2015 09:05:03.*

docs/concat-examples.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ grunt.initConfig({
136136
```
137137

138138
## Invalid or Missing Files Warning
139-
If you would like the `concat` task to warn if a given file is missing or invalid be sure to set `nonull` to `true`:
139+
If you would like the `concat` task to warn and abort if a given file is missing or invalid be sure to set `nonull` to `true`:
140140

141141
```js
142142
grunt.initConfig({
@@ -150,6 +150,8 @@ grunt.initConfig({
150150
});
151151
```
152152

153+
Additionally invoke grunt with `--force` to skip over missing files.
154+
153155
See [configuring files for a task](http://gruntjs.com/configuring-tasks#files) for how to configure file globbing in Grunt.
154156

155157

tasks/concat.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ module.exports = function(grunt) {
6767

6868
// Concat banner + specified files + footer.
6969
var src = banner + f.src.filter(function(filepath) {
70-
// Warn on and remove invalid source files (if nonull was set).
70+
// Warn on invalid source files (if nonull was set). They will be
71+
// removed if --force is specified.
7172
if (!grunt.file.exists(filepath)) {
72-
grunt.log.warn('Source file "' + filepath + '" not found.');
73+
grunt.fail.warn('Source file "' + filepath + '" not found.');
7374
return false;
7475
} else {
7576
return true;

test/concat_test.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
var grunt = require('grunt');
44
var comment = require('../tasks/lib/comment').init(grunt);
5+
var exec = require('child_process').exec;
6+
var path = require('path');
7+
var fs = require('fs');
8+
9+
var execOptions = {cwd: path.join(__dirname, '..')};
510

611
function getNormalizedFile(filepath) {
712
return grunt.util.normalizelf(grunt.file.read(filepath));
@@ -27,13 +32,30 @@ exports.concat = {
2732
test.done();
2833
},
2934
handling_invalid_files: function(test) {
30-
test.expect(1);
35+
test.expect(3);
3136

32-
var actual = getNormalizedFile('tmp/handling_invalid_files');
33-
var expected = getNormalizedFile('test/expected/handling_invalid_files');
34-
test.equal(actual, expected, 'will have warned, but should not fail.');
37+
exec('grunt concat-warn', execOptions, function(error, stdout) {
38+
test.ok(stdout.indexOf('Warning:') > -1, 'should print a warning.');
39+
test.ok(stdout.indexOf('Aborted due to warnings.') > -1, 'should abort.');
3540

36-
test.done();
41+
fs.exists('tmp/handling_invalid_files', function(exists) {
42+
test.ok(!exists, 'should not have created a file.');
43+
test.done();
44+
});
45+
});
46+
},
47+
handling_invalid_files_force: function(test) {
48+
test.expect(2);
49+
50+
exec('grunt concat-force --force', execOptions, function(error, stdout) {
51+
test.ok(stdout.indexOf('Warning:') > -1, 'should print a warning.');
52+
53+
var actual = getNormalizedFile('tmp/handling_invalid_files_force');
54+
var expected = getNormalizedFile('test/expected/handling_invalid_files_force');
55+
test.equal(actual, expected, 'should not fail.');
56+
57+
test.done();
58+
});
3759
},
3860
strip_banner: function(test) {
3961
test.expect(10);
File renamed without changes.

0 commit comments

Comments
 (0)