Permalink
Please sign in to comment.
Showing
with
46 additions
and 37 deletions.
| @@ -0,0 +1,5 @@ | ||
| + | ||
| +function assertStringContains(text, subtext) | ||
| + assert(~isempty(strfind(text, subtext)), ... | ||
| + 'String ''%s'' should contain ''%s'', but it doesn''t.'); | ||
| +end |
| @@ -0,0 +1,13 @@ | ||
| +function filepath = create_tempfile(filename, contents) | ||
| + % Creates a temporary file with the specified content. | ||
| + | ||
| + filepath = ensure_path_in_tempdir(filename); | ||
| + | ||
| + % Make sure eventual folder exists | ||
| + tempfolder = fileparts(filepath); | ||
| + create_tempfolder(tempfolder); | ||
| + | ||
| + fid = fopen(filepath, 'w'); | ||
| + fprintf(fid, contents); | ||
| + fclose(fid); | ||
| +end |
| @@ -0,0 +1,11 @@ | ||
| +function folderpath = create_tempfolder(foldername) | ||
| + % Create a folder inside the default temporary director | ||
| + % and returns it path. | ||
| + % | ||
| + % If the folder already exists, do nothing... | ||
| + | ||
| + folderpath = ensure_path_in_tempdir(foldername); | ||
| + | ||
| + [unused, unused, unused] = mkdir(folderpath); | ||
| + % Avoid existing folder warnings by receiving all the 3 outputs of mkdir | ||
| +end |
| @@ -0,0 +1,14 @@ | ||
| +function newpath = ensure_path_in_tempdir(oldpath) | ||
| + % Check if path start with the tempdir. | ||
| + % If not, prepend the tempdir to path. | ||
| + % | ||
| + % Returns a path that starts with tempdir. | ||
| + | ||
| + len = length(tempdir); | ||
| + if length(oldpath) >= len && strcmp(oldpath(1:len), tempdir) | ||
| + % Just ignore if oldpath already include the tempdir path | ||
| + newpath = oldpath; | ||
| + else | ||
| + newpath = fullfile(tempdir, oldpath); | ||
| + end | ||
| +end |
0 comments on commit
e176377