diff --git a/src/spmBatching/bidsCopyRawFolder.m b/src/spmBatching/bidsCopyRawFolder.m index 86de8af1..ad91721a 100644 --- a/src/spmBatching/bidsCopyRawFolder.m +++ b/src/spmBatching/bidsCopyRawFolder.m @@ -70,19 +70,22 @@ function bidsCopyRawFolder(opt, deleteZippedNii) % use a call to system cp function to use the derefence option (-L) % to get the data 'out' of an eventual datalad dataset try - system( ... - sprintf('cp -Lr %s %s', ... + status = system( ... + sprintf('cp -R -L %s %s', ... fullfile(rawDir, subDir), ... fullfile(derivativesDir, subDir))); - catch - message = [ ... - 'Copying data with system command failed: ' ... - 'are you running Windows?\n', ... - 'Will use matlab/octave copyfile command instead.\n', ... - 'Could be an issue if your data set contains symbolic links' ... - '(e.g. if you use datalad or git-annex.']; - warning(message); + if status > 0 + message = [ ... + 'Copying data with system command failed: ' ... + 'are you running Windows?\n', ... + 'Will use matlab/octave copyfile command instead.\n', ... + 'Could be an issue if your data set contains symbolic links' ... + '(e.g. if you use datalad or git-annex.']; + error(message); + end + + catch copyfile(fullfile(rawDir, subDir), ... fullfile(derivativesDir, subDir)); end diff --git a/tests/test_bidsCopyRawFolder.m b/tests/test_bidsCopyRawFolder.m new file mode 100644 index 00000000..c56857f2 --- /dev/null +++ b/tests/test_bidsCopyRawFolder.m @@ -0,0 +1,45 @@ +function test_suite = test_bidsCopyRawFolder %#ok<*STOUT> + try % assignment of 'localfunctions' is necessary in Matlab >= 2016 + test_functions = localfunctions(); %#ok<*NASGU> + catch % no problem; early Matlab versions can use initTestSuite fine + end + initTestSuite; +end + +function test_bidsCopyRawFolderBasic() + + % directory with this script becomes the current directory + opt.dataDir = fullfile( ... + fileparts(mfilename('fullpath')), ... + '..', 'demos', 'MoAE', 'output', 'MoAEpilot'); + + % group of subjects to analyze + opt.groups = {''}; + % suject to run in each group + opt.subjects = {[]}; + % task to analyze + opt.taskName = 'auditory'; + + checkDependencies(); + opt = checkOptions(opt); + + bidsCopyRawFolder(opt, 1); + + assertEqual(exist( ... + fullfile(opt.dataDir, '..', ... + 'derivatives', 'SPM12_CPPL', ... + 'dataset_description.json'), 'file'), ... + 2); + + assertEqual(exist( ... + fullfile(opt.dataDir, '..', ... + 'derivatives', 'SPM12_CPPL', 'sub-01', 'func', ... + 'sub-01_task-auditory_bold.nii'), 'file'), ... + 2); + + assertEqual(exist( ... + fullfile(opt.dataDir, '..', ... + 'derivatives', 'SPM12_CPPL', 'sub-01', 'anat', ... + 'sub-01_T1w.nii'), 'file'), ... + 2); +end