Debian Codegraph @

testsuite/bin/install_test_r

raw
1 #!/usr/bin/env Rscript
2 #
3 # INSTALL_TEST_R, R test script for install non-reg suite
4 # Copyright (C) 2017-2021 Xavier Delaruelle
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 ##########################################################################
20
21 args = commandArgs(trailingOnly=TRUE)
22
23 if (length(args) != 2) {
24 # print usage message
25 stop('Usage: install_test_r initfile command[:command]')
26 }
27
28 initfile <- args[1]
29 cmdlist <- strsplit(args[2], ':')[[1]]
30 # empty command list, means one empty command
31 if (length(cmdlist) == 0) {
32 cmdlist <- list('')
33 }
34
35 if (file.access(initfile, 4) != 0) {
36 stop('Cannot read ', initfile)
37 }
38
39 # source module init file
40 source(initfile)
41
42 # execute command list
43 code <- 0
44 runml <- FALSE
45 for (cmd in cmdlist) {
46 # call ml procedure instead of module
47 if (cmd == 'ml') {
48 runml <- TRUE
49 ret <- TRUE
50 # if command equals to NOARG string, means call with no arg passed
51 } else if (cmd == 'NOARG') {
52 if (identical(runml, FALSE)) {
53 ret <- do.call(module, list())
54 } else {
55 ret <- do.call(ml, list())
56 }
57 } else {
58 # append ',' to take into account eventual empty string arg
59 if (identical(runml, FALSE)) {
60 ret <- do.call(module, as.list(strsplit(paste0(cmd,',',collapse='')[[1]], ',')[[1]]))
61 } else {
62 ret <- do.call(ml, as.list(strsplit(paste0(cmd,',',collapse='')[[1]], ',')[[1]]))
63 }
64 }
65 if (identical(ret, FALSE)) {
66 code <- 1
67 } else if (!(identical(ret, TRUE))) {
68 print(ret)
69 }
70 }
71
72 if (code != 0) {
73 stop()
74 }
75
76 # vim:set tabstop=3 shiftwidth=3 expandtab autoindent: