-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_validateTestFileSave.m
40 lines (35 loc) · 1.22 KB
/
test_validateTestFileSave.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function [path_full] = test_validateTestFileSave(path, allow_existing)
if ~exist('allow_existing', 'var') || isempty(allow_existing)
allow_existing = false;
end
test_setGlobals();
global TESTDIR;
[path_dir, path_fname, path_ext] = fileparts(path);
path_basename = [path_fname, path_ext];
if strcmp(path_basename, path)
path_full = fullfile(TESTDIR, path);
if exist(TESTDIR, 'dir') ~= 7
fprintf("Creating 'testFiles' directory: %s\n", TESTDIR);
fprintf("Modify `testing` module init file to change directory location\n");
mkdir(TESTDIR);
end
else
path_full = path;
end
if ~allow_existing
while exist(path_full, 'file') == 2
opt = input(sprintf('Test file "%s" already exists. Overwrite/append? (y/n): ', strrep(path_full, TESTDIR, '{TESTDIR}')), 's');
if strcmpi(opt, 'y')
break;
else
opt = input('Append description to filename (or press [ENTER] to cancel): ', 's');
if isempty(opt)
path_full = [];
return;
else
path_fname_root = path_fname;
path_full = sprintf('%s~%s%s', path_fname_root, strrep(opt,' ','-'), path_ext);
end
end
end
end