Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ before_script:
# Add to src functions to path
- octave $OCTFLAGS --eval "addpath(genpath(fullfile(pwd, 'src'))); savepath ();"
# Change current directory
- cd manualTests
- cd tests/manualTests

jobs:
include:
Expand Down
9 changes: 0 additions & 9 deletions manualTests/miss_hit.cfg

This file was deleted.

14 changes: 5 additions & 9 deletions src/convertSourceToRaw.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ function convertSourceToRaw(cfg)
rawDir = fullfile(cfg.dir.output, 'raw');

% add dummy README and CHANGE file
copyfile(fullfile( ...
fileparts(mfilename('fullpath')), '..', 'manualTests', 'dummyData', ...
'README'), ...
templateFolder = fullfile(fileparts(mfilename('fullpath')), '..', 'templates');

copyfile(fullfile(templateFolder, 'README'), ...
sourceDir);
copyfile(fullfile( ...
fileparts(mfilename('fullpath')), '..', 'manualTests', 'dummyData', ...
'CHANGES'), ...
copyfile(fullfile(templateFolder, 'CHANGES'), ...
sourceDir);
copyfile(fullfile( ...
fileparts(mfilename('fullpath')), '..', 'manualTests', 'dummyData', ...
'.bidsignore'), ...
copyfile(fullfile(templateFolder, '.bidsignore'), ...
sourceDir);

copyfile(sourceDir, rawDir);
Expand Down
2 changes: 2 additions & 0 deletions src/templates/test_templateTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function test_templateTestBasic()
% expectedOuput = X;

% assertEqual(actualOupout, expectedOuput)
% assertTrue( );
% assertFalse( );

%% clean up (delete temporary files that were created)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
82 changes: 28 additions & 54 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,43 @@
- Install [MOcov for matlab and octave](https://github.com/MOcov/MOcov) to get
the code coverage

- Make sure you are in the `tests` directory.
- Make sure the following folders and sub-folders are in the Octave / MATLAB
path:

- Run `moxunit_runtests` or `moxunit_runtests -verbose` to run the tests.
- `src`
- `lib`
- `tests/utils`

- Run `moxunit_runtests tests` or `moxunit_runtests tests -verbose` to run the
tests.

This should tell you which tests pass or fail.

## code coverage
## Adding more tests

You can use the function template to write more tests.

It is in the [`src/templates` folder](../src/templates)

## Manual tests

This is the folder where we keep tests that can not be run in continuous
integration even as simple "smoke tests".

<!-- ## code coverage

A lot of what follows does not really work locally because of needing to add the right
folders to the path to get an accurate coverage.

The following command would give more info and will give you HTML output in a
`coverage_html` folder showing you which lines of code is or is not checked by
your test suite.

```matlab
success = moxunit_runtests(pwd, ... % the path where the tests are
success = moxunit_runtests('tests', ... % the path where the tests are
'-verbose', ...
'-with_coverage', ...
'-cover', fullfile(pwd, '..'), ... % the path of the code whose coverage we want to estimate
'-cover', fullfile(pwd, 'src'), ... % the path of the code whose coverage we want to estimate
'-cover_xml_file','coverage.xml', ...
'-cover_html_dir','coverage_html');
```
Expand All @@ -38,9 +58,9 @@ some tests.

```matlab
coverage = mocov( ...
'-expression', 'moxunit_runtests()', ...
'-expression', "moxunit_runtests('test')", ...
'-verbose', ...
'-cover', fullfile(pwd, '..'), ...
'-cover', fullfile(pwd, 'src'), ...
'-cover_exclude', '*jsonread.m', ...
'-cover_exclude', '*json*code.m', ...
'-cover_exclude', '*Contents.m', ...
Expand All @@ -54,50 +74,4 @@ coverage = mocov( ...
'-cover_exclude', '*test_*', ...
'-cover_xml_file','coverage.xml', ...
'-cover_html_dir','coverage_html')
```

## Adding more tests

You can use the following function template to write more tests.

```matlab
function test_suite = test_functionToTest()
% This top function is necessary for mox unit to run tests.
% DO NOT CHANGE IT except to adapt the name of the function.
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_functionToTestBasic()

%% set up


%% data to test against


%% test
% assertTrue( );
% assertFalse( );
% assertEqual( );

end

function test_functionToTestUseCase1()

%% set up


%% data to test against


%% test
% assertTrue( );
% assertFalse( );
% assertEqual( );

end
```
``` -->
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,23 @@ function test_makeRawDataset()
createJson(cfg, extraInfo);

%% add dummy data
templateFolder = fullfile(fileparts(mfilename('fullpath')), '..', '..', 'templates');

subjectDir = fullfile(cfg.dir.output, 'source', 'sub-001', 'ses-001');
funcDir = fullfile(subjectDir, 'func');

boldFilename = 'sub-001_ses-001_task-testtask_run-001_bold.nii.gz';

copyfile( ...
fullfile('dummyData', 'dummyData.nii.gz'), ...
fullfile(templateFolder, 'dummyData.nii.gz'), ...
fullfile(funcDir, boldFilename));

boldFilename = ['sub-001_ses-001_task-rest', ...
'_acq-newTYpe_ce-test_dir-yPos_rec-fastRecon', ...
'_run-001_echo-1_bold.nii.gz'];

copyfile( ...
fullfile('dummyData', 'dummyData.nii.gz'), ...
fullfile(templateFolder, 'dummyData.nii.gz'), ...
fullfile(funcDir, boldFilename));

eegDir = fullfile(subjectDir, 'eeg');
Expand All @@ -241,19 +243,19 @@ function test_makeRawDataset()
behFilename = 'sub-001_ses-001_task-easyTargetPractice_run-001_beh.tsv';

copyfile( ...
fullfile('dummyData', 'dummyData.nii.gz'), ...
fullfile(templateFolder, 'dummyData.nii.gz'), ...
fullfile(eegDir, eegFilename));

copyfile( ...
fullfile('dummyData', 'dummyData.nii.gz'), ...
fullfile(templateFolder, 'dummyData.nii.gz'), ...
fullfile(megDir, megFilename));

copyfile( ...
fullfile('dummyData', 'dummyData.nii.gz'), ...
fullfile(templateFolder, 'dummyData.nii.gz'), ...
fullfile(ieegDir, ieegFilename));

copyfile( ...
fullfile('dummyData', 'dummyData.nii.gz'), ...
fullfile(templateFolder, 'dummyData.nii.gz'), ...
fullfile(behDir, behFilename));

%% actually do the conversion of the source data thus created
Expand Down
2 changes: 1 addition & 1 deletion tests/test_readAndFilterLogfile.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function test_readAndFilterLogfileFromFile()

%% set up

inputFile = fullfile(fileparts(mfilename('fullpath')), 'dummyData', ...
inputFile = fullfile(fileparts(mfilename('fullpath')), 'testData', ...
'sub-blind01_ses-01_task-vislocalizer_events.tsv');

% filter file
Expand Down