Skip to content

Commit

Permalink
tests: add cc files for testing oct files
Browse files Browse the repository at this point in the history
Fixes Issue #181.
  • Loading branch information
cbm755 committed Jan 3, 2023
1 parent 7ad4cbf commit fa73e0b
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/octfiles/test_all.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
%% -*- texinfo -*-
%% @defun test_all ()
%% tests
%%
%% @example
%% 42
%% @result{} ans = 42
%% @end example
%%
%% Note its not possible to call doctest from a doctest [1].
%% Instead, we use octave BIST mechanism.
%%
%% [1] https://github.com/catch22/octave-doctest/issues/184
%%
%% @end defun

function test_all()

end

%!test
%! [numpass, numtests, ~] = doctest ('test_octfile_single_fcn');
%! assert (numtests, 2)
%! assert (numpass, 2)

%!test
%! % different behaviour with or without extension
%! [dir, ~, ~] = fileparts (which ('test_octfile_multi.oct'));
%! autoload ('test_subfcn1', fullfile (dir, 'test_octfile_multi.oct'));
%! [numpass, numtests, ~] = doctest ('test_octfile_multi');
%! assert (numtests, 1)
%! assert (numpass, 1)
%! [numpass, numtests, ~] = doctest ('test_octfile_multi.oct');
%! assert (numtests, 4)
%! assert (numpass, 4)
45 changes: 45 additions & 0 deletions test/octfiles/test_octfile_multi.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <octave/oct.h>

DEFUN_DLD (test_octfile_multi, args, ,
"-*- texinfo -*-\n\
@deftypefn {} {} test_octfile_multi ()\n\
Testing\n\
\n\
@example\n\
a = 42\n\
@result{} a = 42\n\
@end example\n\
@end deftypefn")
{
return ovl (0);
}

DEFUN_DLD (test_subfcn1, args, ,
"-*- texinfo -*-\n\
@deftypefn {} {} test_subfcn1 ()\n\
Testing\n\
\n\
@example\n\
a = 43\n\
@result{} a = 43\n\
@end example\n\
@end deftypefn")
{
return ovl (0);
}

DEFUN_DLD (test_subfcn2, args, ,
"-*- texinfo -*-\n\
@deftypefn {} {} test_subfcn2 ()\n\
Testing\n\
\n\
@example\n\
a = 44\n\
@result{} a = 44\n\
a = a + 1\n\
@result{} a = 45\n\
@end example\n\
@end deftypefn")
{
return ovl (0);
}
17 changes: 17 additions & 0 deletions test/octfiles/test_octfile_single_fcn.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <octave/oct.h>

DEFUN_DLD (test_octfile_single_fcn, args, ,
"-*- texinfo -*-\n\
@deftypefn {} {} test_octfile_single_fcn ()\n\
Testing\n\
\n\
@example\n\
b = 42\n\
@result{} b = 42\n\
b = b + 1\n\
@result{} b = 43\n\
@end example\n\
@end deftypefn")
{
return ovl (0);
}

0 comments on commit fa73e0b

Please sign in to comment.