|
| 1 | +% (C) Copyright 2020 bidspm developers |
| 2 | + |
| 3 | +function test_suite = test_addGitIgnore %#ok<*STOUT> |
| 4 | + try % assignment of 'localfunctions' is necessary in Matlab >= 2016 |
| 5 | + test_functions = localfunctions(); %#ok<*NASGU> |
| 6 | + catch % no problem; early Matlab versions can use initTestSuite fine |
| 7 | + end |
| 8 | + initTestSuite; |
| 9 | +end |
| 10 | + |
| 11 | +function test_addGitIgnore_basic() |
| 12 | + |
| 13 | + if exist(fullfile(pwd, '.gitignore'), 'file') |
| 14 | + delete(fullfile(pwd, '.gitignore')); |
| 15 | + end |
| 16 | + |
| 17 | + addGitIgnore(pwd); |
| 18 | + |
| 19 | + assertEqual(exist(fullfile(pwd, '.gitignore'), 'file'), 2); |
| 20 | + |
| 21 | + fid = fopen(fullfile(pwd, '.gitignore'), 'r'); |
| 22 | + c = fread(fid, Inf, 'uint8=>char')'; |
| 23 | + |
| 24 | + assertEqual(strfind(c, '.DS_store'), 1); |
| 25 | + |
| 26 | + fclose(fid); |
| 27 | + |
| 28 | + delete(fullfile(pwd, '.gitignore')); |
| 29 | + |
| 30 | +end |
| 31 | + |
| 32 | +function test_addGitIgnore_already_present() |
| 33 | + |
| 34 | + if exist(fullfile(pwd, '.gitignore'), 'file') |
| 35 | + delete(fullfile(pwd, '.gitignore')); |
| 36 | + end |
| 37 | + fid = fopen(fullfile(pwd, '.gitignore'), 'w'); |
| 38 | + fprintf(fid, 'foo\n'); |
| 39 | + fprintf(fid, '.DS_store\n'); |
| 40 | + fclose(fid); |
| 41 | + |
| 42 | + addGitIgnore(pwd); |
| 43 | + |
| 44 | + fid = fopen(fullfile(pwd, '.gitignore'), 'r'); |
| 45 | + c = fread(fid, Inf, 'uint8=>char')'; |
| 46 | + assertEqual(numel(strfind(c, '.DS_store')), 1); |
| 47 | + |
| 48 | + fclose(fid); |
| 49 | + |
| 50 | + delete(fullfile(pwd, '.gitignore')); |
| 51 | +end |
| 52 | + |
| 53 | +function test_addGitIgnore_append() |
| 54 | + |
| 55 | + if isOctave() |
| 56 | + return |
| 57 | + end |
| 58 | + |
| 59 | + if exist(fullfile(pwd, '.gitignore'), 'file') |
| 60 | + delete(fullfile(pwd, '.gitignore')); |
| 61 | + end |
| 62 | + |
| 63 | + fid = fopen(fullfile(pwd, '.gitignore'), 'w'); |
| 64 | + fprintf(fid, 'foo\n'); |
| 65 | + fprintf(fid, 'bar\n'); |
| 66 | + fclose(fid); |
| 67 | + |
| 68 | + addGitIgnore(pwd); |
| 69 | + |
| 70 | + fid = fopen(fullfile(pwd, '.gitignore'), 'r'); |
| 71 | + c = fread(fid, Inf, 'uint8=>char')'; |
| 72 | + assert(strfind(c, '.DS_store') > 0); |
| 73 | + fclose(fid); |
| 74 | + |
| 75 | + delete(fullfile(pwd, '.gitignore')); |
| 76 | +end |
0 commit comments