diff --git a/Makefile b/Makefile index 1575b9f..9166cb6 100644 --- a/Makefile +++ b/Makefile @@ -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)) diff --git a/tests/support/assertStringContains.m b/tests/support/assertStringContains.m new file mode 100644 index 0000000..2a4dc21 --- /dev/null +++ b/tests/support/assertStringContains.m @@ -0,0 +1,5 @@ + +function assertStringContains(text, subtext) + assert(~isempty(strfind(text, subtext)), ... + 'String ''%s'' should contain ''%s'', but it doesn''t.'); +end diff --git a/tests/support/create_tempfile.m b/tests/support/create_tempfile.m new file mode 100644 index 0000000..152f093 --- /dev/null +++ b/tests/support/create_tempfile.m @@ -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 diff --git a/tests/support/create_tempfolder.m b/tests/support/create_tempfolder.m new file mode 100644 index 0000000..d788600 --- /dev/null +++ b/tests/support/create_tempfolder.m @@ -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 diff --git a/tests/support/ensure_path_in_tempdir.m b/tests/support/ensure_path_in_tempdir.m new file mode 100644 index 0000000..867107d --- /dev/null +++ b/tests/support/ensure_path_in_tempdir.m @@ -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 diff --git a/tests/test_MOcovMFile_recognizes_classdef_syntax.m b/tests/test_MOcovMFile_recognizes_classdef_syntax.m index 0cb62ec..a77844e 100644 --- a/tests/test_MOcovMFile_recognizes_classdef_syntax.m +++ b/tests/test_MOcovMFile_recognizes_classdef_syntax.m @@ -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