Permalink
Browse files

ENH: Improve #9 by extracting support functions

  • Loading branch information...
1 parent b0af5e1 commit e17637779f4f2651555981b582c37de7adc92c81 Anderson Bravalheri committed with (none) Dec 20, 2016
View
@@ -7,9 +7,11 @@ MATLAB?=matlab
OCTAVE?=octave
TESTDIR=$(CURDIR)/tests
+SUPPORTDIR=$(TESTDIR)/support
ROOTDIR=$(CURDIR)/MOcov
ADDPATH=orig_dir=pwd();cd('$(ROOTDIR)');addpath(pwd);cd(orig_dir)
+ADDSUPPORT=orig_dir=pwd();cd('$(SUPPORTDIR)');addpath(pwd);cd(orig_dir)
RMPATH=rmpath('$(ROOTDIR)');
SAVEPATH=savepath();exit(0)
@@ -49,7 +51,7 @@ ifdef JUNIT_XML_FILE
endif
-TEST=$(ADDPATH);if(isempty(which('moxunit_runtests'))),error('MOxUnit is required; see https://github.com/MOxUnit/MOxUnit');end;success=moxunit_runtests($(RUNTESTS_ARGS));exit(~success);
+TEST=$(ADDPATH);$(ADDSUPPORT);if(isempty(which('moxunit_runtests'))),error('MOxUnit is required; see https://github.com/MOxUnit/MOxUnit');end;success=moxunit_runtests($(RUNTESTS_ARGS));exit(~success);
MATLAB_BIN=$(shell which $(MATLAB))
OCTAVE_BIN=$(shell which $(OCTAVE))
@@ -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
@@ -2,37 +2,6 @@
initTestSuite;
end
-function folderpath = create_tempfolder(foldername)
- % Create a folder inside the default temporary director
- % and returns it path.
- %
- % If the folder already exists, do nothing...
-
- len = length(tempdir);
- if length(foldername) >= len && strcmp(foldername(1:len), tempdir)
- % Just ignore if foldername already include the tempdir path
- folderpath = foldername;
- else
- folderpath = fullfile(tempdir, foldername);
- end
-
- [unused, unused, unused] = mkdir(folderpath);
- % Avoid existing folder warnings by receiving all the 3 outputs of mkdir
-end
-
-
-function filepath = create_tempfile(filename, contents)
- filepath = fullfile(tempdir, filename);
-
- % Make sure eventual folder exists
- tempfolder = fileparts(filepath);
- create_tempfolder(tempfolder);
-
- fid = fopen(filepath, 'w');
- fprintf(fid, contents);
- fclose(fid);
-end
-
function filepath = create_classdef(classname)
if nargin < 1
classname = 'AClass';
@@ -60,11 +29,6 @@
]);
end
-function assertStringContains(text, subtext)
- assert(~isempty(strfind(text, subtext)), ...
- 'String ''%s'' should contain ''%s'', but it doesn''t.');
-end
-
function test_classdef_line_not_executable
% Test subject: `MOcovMFile` constructor

0 comments on commit e176377

Please sign in to comment.