File: run_matlab_tests.m

package info (click to toggle)
mwrap 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,480 kB
  • sloc: cpp: 3,315; python: 1,850; ansic: 856; makefile: 255; lex: 233; sh: 145
file content (124 lines) | stat: -rw-r--r-- 4,050 bytes parent folder | download
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function run_matlab_tests(build_dir, source_dir)
% run_matlab_tests  Run all MATLAB tests for mwrap.
%
%   run_matlab_tests(BUILD_DIR, SOURCE_DIR) runs the example and unit tests
%   using MEX binaries from BUILD_DIR and test scripts from SOURCE_DIR.
%
%   This script is designed for use with matlab-actions/run-command in CI.
%   It exits with a non-zero status on failure.

if nargin < 2
    error('Usage: run_matlab_tests(build_dir, source_dir)');
end

n_pass = 0;
n_fail = 0;
failures = {};

%% -- Example tests ----------------------------------------------------------

example_tests = {
    % {test_name, mex_dir, script_dirs, script_name, needs_cd}
    {'eventq_plain',  fullfile(build_dir, 'example', 'eventq_plain'),  ...
        {fullfile(source_dir, 'example', 'eventq')}, 'testq_plain', false}
    {'eventq_handle', fullfile(build_dir, 'example', 'eventq_handle'), ...
        {fullfile(source_dir, 'example', 'eventq')}, 'testq_handle', false}
    {'eventq_class',  fullfile(build_dir, 'example', 'eventq_class'),  ...
        {fullfile(source_dir, 'example', 'eventq')}, 'testq_class', false}
    {'eventq2',       fullfile(build_dir, 'example', 'eventq2'),       ...
        {fullfile(source_dir, 'example', 'eventq2')}, 'testq2', false}
    {'zlib',          fullfile(build_dir, 'example', 'zlib'),          ...
        {fullfile(source_dir, 'example', 'zlib')}, 'testgz', true}
    {'fem_simple',    fullfile(build_dir, 'example', 'fem_interface'), ...
        {fullfile(source_dir, 'example', 'fem')}, 'test_simple', true}
    {'fem_patch',     fullfile(build_dir, 'example', 'fem_interface'), ...
        {fullfile(source_dir, 'example', 'fem')}, 'test_patch', true}
    {'fem_assembler', fullfile(build_dir, 'example', 'fem_interface'), ...
        {fullfile(source_dir, 'example', 'fem')}, 'test_assembler', true}
};

for i = 1:numel(example_tests)
    t = example_tests{i};
    test_name  = t{1};
    mex_dir    = t{2};
    script_dirs = t{3};
    script_name = t{4};
    needs_cd   = t{5};

    fprintf('\n=== Running example test: %s ===\n', test_name);
    saved_path = path;
    saved_dir = pwd;
    try
        addpath(mex_dir);
        for j = 1:numel(script_dirs)
            addpath(script_dirs{j});
        end
        if needs_cd
            cd(mex_dir);
        end
        feval(script_name);
        fprintf('PASS: %s\n', test_name);
        n_pass = n_pass + 1;
    catch ME
        fprintf('FAIL: %s -- %s\n', test_name, ME.message);
        n_fail = n_fail + 1;
        failures{end+1} = test_name; %#ok<AGROW>
    end
    cd(saved_dir);
    path(saved_path);
end

%% -- Unit tests (testing/) --------------------------------------------------

testing_mex_dir = fullfile(build_dir, 'testing');
testing_gen_dir = fullfile(build_dir, 'testing', 'octave');
testing_src_dir = fullfile(source_dir, 'testing');

unit_tests = {
    'test_transfers'
    'test_cpp_complex'
    'test_c99_complex'
    'test_catch'
    'test_fortran1'
    'test_fortran2'
    'test_redirect'
    'test_include'
    'test_single'
    'test_char'
};

for i = 1:numel(unit_tests)
    test_name = unit_tests{i};
    fprintf('\n=== Running unit test: %s ===\n', test_name);
    saved_path = path;
    saved_dir = pwd;
    try
        addpath(testing_mex_dir);
        addpath(testing_gen_dir);
        addpath(testing_src_dir);
        feval(test_name);
        fprintf('PASS: %s\n', test_name);
        n_pass = n_pass + 1;
    catch ME
        fprintf('FAIL: %s -- %s\n', test_name, ME.message);
        n_fail = n_fail + 1;
        failures{end+1} = test_name; %#ok<AGROW>
    end
    cd(saved_dir);
    path(saved_path);
end

%% -- Summary -----------------------------------------------------------------

fprintf('\n============================\n');
fprintf('Results: %d passed, %d failed\n', n_pass, n_fail);
if n_fail > 0
    fprintf('Failures:\n');
    for i = 1:numel(failures)
        fprintf('  - %s\n', failures{i});
    end
    error('mwrap:testFailure', '%d test(s) failed.', n_fail);
end
fprintf('All tests passed.\n');

end