Skip to content

Commit

Permalink
Merge pull request #774 from DaNish808/cmd-tool-returns-0-761
Browse files Browse the repository at this point in the history
bring back correct exit code on validation w/ errors
  • Loading branch information
rwblair authored May 31, 2019
2 parents afb599e + fab7ba4 commit fa00fd7
Show file tree
Hide file tree
Showing 265 changed files with 193 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bids-validator/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,30 @@ var colors = require('colors/safe')
var fs = require('fs')
const remoteFiles = require('./utils/files/remoteFiles')

const exitProcess = issues => {
if (
issues === 'Invalid' ||
(issues.errors && issues.errors.length >= 1) ||
(issues.config && issues.config.length >= 1)
) {
process.exit(1)
} else {
process.exit(0)
}
}

module.exports = function(dir, options) {
if (fs.existsSync(dir)) {
if (options.json) {
validate.BIDS(dir, options, function(issues, summary) {
console.log(JSON.stringify({ issues, summary }))
exitProcess(issues)
})
} else {
validate.BIDS(dir, options, function(issues, summary) {
console.log(validate.consoleFormat.issues(issues, options) + '\n')
console.log(validate.consoleFormat.summary(summary, options))
exitProcess(issues)
})
}
} else {
Expand Down
36 changes: 36 additions & 0 deletions bids-validator/tests/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const { spawn } = require('child_process')
const dir = process.cwd()
const data_dir = dir + '/bids-validator/tests/data/'
const test_data = data_dir + 'valid_headers/'
const data_with_errors = data_dir + 'empty_files'
const data_without_errors = data_dir + 'valid_dataset'

const cli_path = './bids-validator/bin/bids-validator'

Expand Down Expand Up @@ -55,6 +57,40 @@ describe('CLI', () => {
})
})

it('without errors should exit with code 0', done => {
const command = spawn(cli_path, [data_without_errors, '--json'])
command.on('exit', code => {
assert.equal(code, 0)
done()
})
})

it('with errors should not exit with code 0', done => {
const command = spawn(cli_path, [data_with_errors])
command.on('exit', code => {
assert.notEqual(code, 0)
done()
})
})

it('with errors should not exit with code 0 with --json argument', done => {
const command = spawn(cli_path, [data_with_errors, '--json'])
let commandOutput = []
let output = {}
command.stdout.on('data', data => {
const dataLines = data.toString().split('\n')
commandOutput = commandOutput.concat(dataLines)
})
command.stderr.on('end', () => {
output = JSON.parse(commandOutput.join(''))
})
command.on('exit', code => {
assert(output.issues.errors.length > 0)
assert.notEqual(code, 0)
done()
})
})

it('should print valid json when the --json argument is provided', done => {
const command = spawn(cli_path, [test_data, '--json'])
let commandOutput = ''
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Name": "Synthetic dataset for inclusion in BIDS-examples",
"BIDSVersion": "1.0.2",
"License": "PD",
"Authors": ["Markiewicz, C. J."]
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions bids-validator/tests/data/valid_dataset/participants.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
participant_id age sex
sub-01 34 F
sub-02 38 M
sub-03 22 M
sub-04 21 F
sub-05 42 M
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filename acq_time
anat/sub-01_ses-01_T1w.nii.gz 1880-01-10T05:17:54
func/sub-01_ses-01_task-nback_run-01_bold.nii.gz 1880-01-10T05:22:54
func/sub-01_ses-01_task-nback_run-02_bold.nii.gz 1880-01-10T05:37:54
func/sub-01_ses-01_task-rest_bold.nii.gz 1880-01-10T05:52:54
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filename acq_time
anat/sub-01_ses-02_T1w.nii.gz 1802-06-04T22:54:25
func/sub-01_ses-02_task-nback_run-01_bold.nii.gz 1802-06-04T22:59:25
func/sub-01_ses-02_task-nback_run-02_bold.nii.gz 1802-06-04T23:14:25
func/sub-01_ses-02_task-rest_bold.nii.gz 1802-06-04T23:29:25
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
session_id systolic_blood_pressure
ses-01 112
ses-02 113
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filename acq_time
anat/sub-02_ses-01_T1w.nii.gz 1874-04-12T01:43:17
func/sub-02_ses-01_task-nback_run-01_bold.nii.gz 1874-04-12T01:48:17
func/sub-02_ses-01_task-nback_run-02_bold.nii.gz 1874-04-12T02:03:17
func/sub-02_ses-01_task-rest_bold.nii.gz 1874-04-12T02:18:17
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filename acq_time
anat/sub-02_ses-02_T1w.nii.gz 1814-09-10T07:05:33
func/sub-02_ses-02_task-nback_run-01_bold.nii.gz 1814-09-10T07:10:33
func/sub-02_ses-02_task-nback_run-02_bold.nii.gz 1814-09-10T07:25:33
func/sub-02_ses-02_task-rest_bold.nii.gz 1814-09-10T07:40:33
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
session_id systolic_blood_pressure
ses-01 114
ses-02 115
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filename acq_time
anat/sub-03_ses-01_T1w.nii.gz 1852-10-11T23:35:34
func/sub-03_ses-01_task-nback_run-01_bold.nii.gz 1852-10-11T23:40:34
func/sub-03_ses-01_task-nback_run-02_bold.nii.gz 1852-10-11T23:55:34
func/sub-03_ses-01_task-rest_bold.nii.gz 1852-10-12T00:10:34
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filename acq_time
anat/sub-03_ses-02_T1w.nii.gz 1843-04-22T00:23:54
func/sub-03_ses-02_task-nback_run-01_bold.nii.gz 1843-04-22T00:28:54
func/sub-03_ses-02_task-nback_run-02_bold.nii.gz 1843-04-22T00:43:54
func/sub-03_ses-02_task-rest_bold.nii.gz 1843-04-22T00:58:54
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
session_id systolic_blood_pressure
ses-01 112
ses-02 115
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filename acq_time
anat/sub-04_ses-01_T1w.nii.gz 1800-05-21T11:18:59
func/sub-04_ses-01_task-nback_run-01_bold.nii.gz 1800-05-21T11:23:59
func/sub-04_ses-01_task-nback_run-02_bold.nii.gz 1800-05-21T11:38:59
func/sub-04_ses-01_task-rest_bold.nii.gz 1800-05-21T11:53:59
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filename acq_time
anat/sub-04_ses-02_T1w.nii.gz 1847-10-17T10:15:19
func/sub-04_ses-02_task-nback_run-01_bold.nii.gz 1847-10-17T10:20:19
func/sub-04_ses-02_task-nback_run-02_bold.nii.gz 1847-10-17T10:35:19
func/sub-04_ses-02_task-rest_bold.nii.gz 1847-10-17T10:50:19
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
session_id systolic_blood_pressure
ses-01 111
ses-02 115
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filename acq_time
anat/sub-05_ses-01_T1w.nii.gz 1899-07-07T16:04:21
func/sub-05_ses-01_task-nback_run-01_bold.nii.gz 1899-07-07T16:09:21
func/sub-05_ses-01_task-nback_run-02_bold.nii.gz 1899-07-07T16:24:21
func/sub-05_ses-01_task-rest_bold.nii.gz 1899-07-07T16:39:21
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filename acq_time
anat/sub-05_ses-02_T1w.nii.gz 1868-01-31T20:57:43
func/sub-05_ses-02_task-nback_run-01_bold.nii.gz 1868-01-31T21:02:43
func/sub-05_ses-02_task-nback_run-02_bold.nii.gz 1868-01-31T21:17:43
func/sub-05_ses-02_task-rest_bold.nii.gz 1868-01-31T21:32:43
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
session_id systolic_blood_pressure
ses-01 114
ses-02 110
4 changes: 4 additions & 0 deletions bids-validator/tests/data/valid_dataset/task-nback_bold.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"TaskName": "N-Back",
"RepetitionTime": 2.5
}
43 changes: 43 additions & 0 deletions bids-validator/tests/data/valid_dataset/task-nback_events.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
onset duration trial_type weight
2.016 1 scene_nontarget_nbackparam -0.5
4.0169999999999995 1 scene_target_nbackparam -0.5
6.018 1 scene_target_nbackparam -0.5
8.019 1 scene_nontarget_nbackparam -0.5
10.02 1 scene_dist_rtparam 0.348
12.02 1 scene_nontarget_nbackparam -0.5
14.005 1 scene_nontarget_nbackparam -0.5
16.005 1 scene_dist_rtparam -0.122
18.006 1 scene_nontarget_nbackparam -0.5
20.007 1 scene_dist_rtparam 0.10400000000000001
24.025 1 faces_nontarget_rtparam 0.026000000000000002
26.01 1 faces_nontarget_rtparam -0.09699999999999999
28.01 1 faces_nontarget_rtparam -0.024
30.011 1 faces_nontarget_rtparam 0.049
32.012 1 faces_nontarget_rtparam 0.019
34.013000000000005 1 faces_dist_nbackparam -0.455
36.014 1 faces_target_rtparam -0.07400000000000001
38.014 1 faces_nontarget_rtparam -0.062
40.015 1 faces_nontarget_rtparam 0.01
42.016000000000005 1 faces_dist_nbackparam -0.455
68.01 1 scene_nontarget_nbackparam 0.5
70.01100000000001 1 scene_nontarget_nbackparam 0.5
72.012 1 scene_nontarget_nbackparam 0.5
74.013 1 scene_nontarget_nbackparam 0.5
76.013 1 scene_dist_rtparam 0.136
78.014 1 scene_target_nbackparam 0.5
80.015 1 scene_nontarget_nbackparam 0.5
82.016 1 scene_nontarget_nbackparam 0.5
84.01700000000001 1 scene_nontarget_nbackparam 0.5
86.01799999999999 1 scene_target_nbackparam 0.5
90.01899999999999 1 faces_nontarget_rtparam -0.175
92.02 1 faces_nontarget_rtparam -0.195
94.021 1 faces_dist_nbackparam 0.545
96.022 1 faces_dist_nbackparam 0.545
98.022 1 faces_target_rtparam -0.068
100.023 1 faces_nontarget_rtparam 0.018000000000000002
102.024 1 faces_nontarget_rtparam -0.019
104.025 1 faces_target_rtparam 0.156
106.009 1 faces_nontarget_rtparam -0.035
108.01 1 faces_target_rtparam -0.057
154.012 1 scene_nontarget_nbackparam -0.5
156.013 1 scene_nontarget_nbackparam -0.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"SamplingFrequency": 10.0,
"StartTime": 0.0,
"Columns": ["respiratory", "cardiac"]
}
5 changes: 5 additions & 0 deletions bids-validator/tests/data/valid_dataset/task-nback_stim.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"SamplingFrequency": 2.0,
"StartTime": 0.0,
"Columns": ["stimA", "stimB"]
}
4 changes: 4 additions & 0 deletions bids-validator/tests/data/valid_dataset/task-rest_bold.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"TaskName": "Rest",
"RepetitionTime": 2.5
}
5 changes: 5 additions & 0 deletions bids-validator/tests/data/valid_dataset/task-rest_physio.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"SamplingFrequency": 10.0,
"StartTime": 0.0,
"Columns": ["respiratory", "cardiac"]
}

0 comments on commit fa00fd7

Please sign in to comment.