summaryrefslogtreecommitdiff
path: root/modules/atoms/macros/atomsTest.sci
blob: 4ff2516dbe388c0d18bd4dac7d8abdfc0843e10b (plain)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
// Copyright (C) 2012 - DIGITEO - Allan CORNET
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt

// End user function

// Output argument :


function bResult = atomsTest(packages, test_name)

    rhs         = argn(2);
    path        = [];
    bResult     = %T;

    // Load Atoms Internals lib if it's not already loaded
    // =========================================================================
    if ~ exists("atomsinternalslib") then
        load("SCI/modules/atoms/macros/atoms_internals/lib");
    end

    // Check input parameters
    // =========================================================================

    rhs = argn(2);

    if rhs > 2 | rhs < 1 then
        error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"),"atomsTest", 1, 2));
    end

    if isdef("test_name") then
        if type(test_name) <> 10 then
            error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsTest", 2));
        end
        test_name = stripblanks(test_name);
    else
        test_name = [];
    end

    if type(packages) <> 10 then
        error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"atomsTest",1));
    end

    if size(packages(1,:),"*") > 3 then
        error(msprintf(gettext("%s: Wrong size for input argument #%d: mx1,mx2 or mx3 string matrix expected.\n"),"atomsTest",1));
    end

    packages = stripblanks(packages);

    // Complete packages matrix with empty columns
    // =========================================================================

    if size(packages(1,:),"*") == 1 then
        packages = [ packages emptystr(size(packages(:,1),"*"),1) emptystr(size(packages(:,1),"*"),1) ];

    elseif size(packages(1,:),"*") == 2 then
        packages = [ packages emptystr(size(packages(:,1),"*"),1) ];

    end

    // Check if the module is installed
    // =========================================================================

    if ~ and(atomsIsInstalled(packages)) then
        for i=1:size(packages(:,1),"*")
            if ~ atomsIsInstalled(packages(i,:)) then
                if isempty(packages(i,2)) & isempty(packages(i,3)) then
                    error(msprintf(gettext("%s: Module ''%s'' is not installed.\n"),"atomsTest",packages(i,1)));
                elseif ~isempty(packages(i,2)) & isempty(packages(i,3)) then
                    error(msprintf(gettext("%s: ''%s - %s'' is not installed.\n"),"atomsTest",packages(i,1),packages(i,2)));
                elseif isempty(packages(i,2)) & ~isempty(packages(i,3)) then
                    error(msprintf(gettext("%s: ''%s'' (''%s'' section) is not installed.\n"),"atomsTest",packages(i,1),packages(i,3)));
                elseif ~isempty(packages(i,2)) & ~isempty(packages(i,3)) then
                    error(msprintf(gettext("%s: ''%s - %s'' (''%s'' section) is not installed.\n"),"atomsTest",packages(i,1),packages(i,2),packages(i,3)));
                end
            end
        end
    end

    // Add a fourth column : the module installation path
    // =========================================================================
    packages = [ packages emptystr(size(packages(:,1),"*"),1) ];

    // Loop on input parameter to set the version and the section if it's not
    // already done
    // =========================================================================

    for i=1:size(packages(:,1),"*")

        // The module's installed version hasn't been specified or is empty
        // Set the MRV available
        // =====================================================================

        if isempty(packages(i,2)) then

            if ~ isempty(packages(i,3)) then
                section = packages(i,3);
            else
                section = "all";
            end

            this_module_versions = atomsGetInstalledVers(packages(i,1),section);

            if isempty(this_module_versions) then
                if section == "all" then
                    error(msprintf(gettext("%s: Module ''%s'' is not installed.\n"),"atomsTest",packages(i,1)));
                else
                    error(msprintf(gettext("%s: Module ''%s'' is not installed (''%s'' section).\n"),"atomsTest",packages(i,1),section));
                end
            else
                packages(i,2) = this_module_versions(1);
            end

        else

            if ~atomsIsInstalled([packages(i,1) packages(i,2)]) then
                error(msprintf(gettext("%s: Module ''%s - %s'' is not installed.\n"),"atomsLoad",packages(i,1),packages(i,2)));
            end

        end

        // The module's installed section hasn't been specified or is empty
        // If the module (same name/same version) is installed in both sections,
        // module installed in the "user" section is taken
        // =====================================================================

        if isempty(packages(i,3)) then

            sections = ["user","allusers"];

            for j=1:size(sections,"*")
                if atomsIsInstalled([packages(i,1) packages(i,2)],sections(j)) then
                    packages(i,3) = sections(j);
                end
            end

        else

            // Check if modules are installed
            if ~ atomsIsInstalled([packages(i,1) packages(i,2)],packages(i,3)) then
                mprintf(gettext("%s: The following modules are not installed:\n"),"atomsAutoloadAdd");
                mprintf("\t - ''%s - %s'' (''%s'' section)\n",packages(i,1),packages(i,2),packages(i,3));
                error("");
            end

        end

        // Get the installed path
        // =====================================================================
        packages(i,4) = atomsGetInstalledPath([packages(i,1) packages(i,2) packages(i,3)]);

    end

    // Loop on packages
    // =========================================================================

    if test_name <> [] & (size(packages(:,1), "*") == 1) then
        bResult = bResult & test_run(packages(1,4), test_name);
    else
        for i = 1:size(packages(:,1),"*")
            bResult = bResult & test_run(packages(i,4));
        end
    end

endfunction