Skip to content

Commit e324c50

Browse files
committed
[GR-29739] Fixes for module testing.
PullRequest: fastr/2578
2 parents 990e491 + 9b42794 commit e324c50

File tree

6 files changed

+64
-58
lines changed

6 files changed

+64
-58
lines changed
Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# This code is free software; you can redistribute it and/or modify it
@@ -21,47 +21,58 @@
2121

2222
# Contains tests for some ALTREP API functions for standard vectors.
2323

24+
# Note that for api.*_IS_SORTED we do not care about the return value because there may be
25+
# different internal representation of data in FastR and GNU-R for the same vector, and both can
26+
# correctly claim that the data is sorted or that they do not know.
27+
# The same applies for api.*_NO_NA functions.
28+
29+
stopifnot( require(testrffi))
30+
2431
# Integer API
2532
integer_api_tests <- function(int_vec) {
26-
for (i in 1:length(int_vec)) {
27-
api.INTEGER_ELT(int_vec, i)
33+
for (i in 0:(length(int_vec) - 1)) {
34+
print(api.INTEGER_ELT(int_vec, i))
2835
}
29-
api.INTEGER_IS_SORTED(int_vec)
30-
api.INTEGER_NO_NA(int_vec)
36+
invisible(api.INTEGER_IS_SORTED(int_vec))
37+
invisible(api.INTEGER_NO_NA(int_vec))
3138
}
3239
integer_api_tests(1:10)
3340
integer_api_tests(as.integer(c(14, 51, 157, 42, 20, 15, 15)))
3441

3542
# Real API
3643
real_api_tests <- function(real_vec) {
37-
for (i in 1:length(real_vec)) {
38-
api.REAL_ELT(real_vec, i)
44+
for (i in 0:(length(real_vec) - 1)) {
45+
print(api.REAL_ELT(real_vec, i))
3946
}
40-
api.REAL_IS_SORTED(real_vec)
41-
api.REAL_NO_NA(real_vec)
47+
invisible(api.REAL_IS_SORTED(real_vec))
48+
invisible(api.REAL_NO_NA(real_vec))
4249
}
43-
real_api_tests(as.double(1:100))
50+
real_api_tests(as.double(1:8))
4451
real_api_tests(as.double(c(0, 0, 0, 0, 1)))
4552

4653
# Logical API
4754
logical_api_tests <- function(lgl_vec) {
48-
for (i in 1:length(lgl_vec)) {
49-
api.LOGICAL_ELT(lgl_vec, i)
55+
for (i in 0:(length(lgl_vec) - 1)) {
56+
print(api.LOGICAL_ELT(lgl_vec, i))
5057
}
51-
api.LOGICAL_IS_SORTED(lgl_vec)
52-
api.LOGICAL_NO_NA(lgl_vec)
58+
invisible(api.LOGICAL_IS_SORTED(lgl_vec))
59+
invisible(api.LOGICAL_NO_NA(lgl_vec))
5360
}
5461
logical_api_tests(c(TRUE, TRUE, FALSE, TRUE))
5562
logical_api_tests(c(TRUE, FALSE))
5663
logical_api_tests(TRUE)
5764

5865
# String API
5966
string_api_tests <- function(str_vec) {
60-
for (i in 1:length(str_vec)) {
61-
api.STRING_ELT(str_vec, i)
67+
for (i in 0:(length(str_vec) - 1)) {
68+
# api.STRING_ELT returns CHARSXP, which is not correctly handled by GNU-R's print, thus
69+
# we wrap it in ScalarString and then print it instead.
70+
string_elt <- api.STRING_ELT(str_vec, i)
71+
string <- api.Rf_ScalarString(string_elt)
72+
print(string)
6273
}
63-
api.STRING_IS_SORTED(str_vec)
64-
api.STRING_NO_NA(str_vec)
74+
invisible(api.STRING_IS_SORTED(str_vec))
75+
invisible(api.STRING_NO_NA(str_vec))
6576
}
6677
string_api_tests(c("hello", "world"))
6778
string_api_tests(c(""))
@@ -70,6 +81,6 @@ string_api_tests(c("a", "b", "c"))
7081

7182
# Raw API
7283
raw_vec <- as.raw(c(12, 117, 45, 0, 1))
73-
for (i in 1:length(raw_vec)) {
74-
api.RAW_ELT(raw_vec, i)
84+
for (i in 0:(length(raw_vec) - 1)) {
85+
print(api.RAW_ELT(raw_vec, i))
7586
}

com.oracle.truffle.r.test.native/packages/testrffi/testrffi/tests/rapiTests.R

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ assertEquals(NULL, api.SET_ATTRIB(x, as.pairlist(list(names=c('a','b')))))
7575
assertEquals(c('a','b'), names(x))
7676
# note: printing x on GNU-R causes segfault
7777

78-
# ---------------------------------------------------------------------------------------
79-
# Rf_mkCharLenCE, note: last arg is encoding and 0 ~ native encoding
80-
81-
assertEquals("hello world", api.Rf_mkCharLenCE("hello world", 11, 0))
82-
ignore("FastR bug", assertEquals("hello", api.Rf_mkCharLenCE("hello this will be cut away", 5, 0)))
83-
8478

8579
# ----------------------------------------------------------------------------------------
8680
# Rf_eval

com.oracle.truffle.r.test.packages/pkgtest/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -188,7 +188,7 @@ def _run_install_packages_script(rscript_path, args, kwargs):
188188

189189
def _fastr_installpkgs(args, **kwargs):
190190
"""
191-
Runs 'install.packages.R' script with GnuR.
191+
Runs 'install.packages.R' script with fastr.
192192
"""
193193
if "FASTR_WORKING_DIR" in os.environ:
194194
env["TMPDIR"] = os.environ["FASTR_WORKING_DIR"]
@@ -362,10 +362,10 @@ def __init__(self):
362362
self.install_data = None
363363
self.pkg = None
364364
self.mode = None
365-
self.start_install_pattern = re.compile(r"^BEGIN processing: (?P<package>[a-zA-Z0-9\.\-]+) .*")
366-
self.test_pattern = re.compile(r"^(?P<status>BEGIN|END) testing: (?P<package>[a-zA-Z0-9\.\-]+) .*")
367-
self.time_pattern = re.compile(r"^TEST_TIME: (?P<package>[a-zA-Z0-9\.\-]+) (?P<time>[0-9\.\-]+) .*")
368-
self.status_pattern = re.compile(r"^(?P<package>[a-zA-Z0-9\.\-]+): (?P<status>OK|FAILED).*")
365+
self.start_install_pattern = re.compile(r"^BEGIN processing:\s*(?P<package>[a-zA-Z0-9.-]+)")
366+
self.test_pattern = re.compile(r"^(?P<status>BEGIN|END) testing:\s*(?P<package>[a-zA-Z0-9.-]+)")
367+
self.time_pattern = re.compile(r"^TEST_TIME:\s*(?P<package>[a-zA-Z0-9.-]+) (?P<time>[0-9.-]+)")
368+
self.status_pattern = re.compile(r"^(?P<package>[a-zA-Z0-9.-]+):\s*(?P<status>OK|FAILED)")
369369
self.install_data = dict()
370370
self.install_status = dict()
371371
self.test_info = dict()

com.oracle.truffle.r.test.packages/pkgtest/fuzzy_compare.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -195,9 +195,9 @@ def _get_next_line(prompt, content, content_len, line_idx):
195195
while i < content_len:
196196
line = content[i]
197197
if prompt is not None:
198-
line = line.replace(prompt, "", 1);
199-
line = line.strip();
200-
if line is not "":
198+
line = line.replace(prompt, "", 1)
199+
line = line.strip()
200+
if line != "":
201201
return line, i
202202
i = i + 1
203203
return None, i
@@ -264,10 +264,10 @@ def _is_ignored_function(fun_name, gnur_content, gnur_stmt, fastr_content, fastr
264264

265265
def _is_statement_begin(captured_prompt, line):
266266
if captured_prompt is None:
267-
return False;
268-
if not line is None:
267+
return False
268+
if line is not None:
269269
line_wo_prompt = line.replace(captured_prompt, "").strip()
270-
return line.startswith(captured_prompt) and line_wo_prompt is not "" and not line_wo_prompt.startswith("#")
270+
return line.startswith(captured_prompt) and line_wo_prompt != "" and not line_wo_prompt.startswith("#")
271271
return False
272272

273273

com.oracle.truffle.r.test.packages/r/install.cache.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ pkg.cache.get <- function(pkg.cache.env, pkg, lib) {
174174
}
175175

176176
pkg.name <- as.character(pkg["Package"])
177-
pkg.version <- as.character(pkg["Version"])
178177

179178
log.message("using package cache directory ", version.dir, level=1)
180179
cache.entry.name <- pkg.cache.entry.filename(pkg)
@@ -251,7 +250,6 @@ pkg.cache.insert <- function(pkg.cache.env, pkg, lib) {
251250
}
252251

253252
tryCatch({
254-
pkg.version <- as.character(pkg["Version"])
255253
fromPath <- file.path(lib, pkgname)
256254
cache.entry.name <- pkg.cache.entry.filename(pkg)
257255
toPath <- pkg.cache.file.path(pkg.cache.env, version.dir, cache.entry.name)
@@ -263,6 +261,9 @@ pkg.cache.insert <- function(pkg.cache.env, pkg, lib) {
263261
# cleanup older package versions
264262
pkg.cache.cleanup.pkg.versions(pkg.cache.env, version.dir, pkgname)
265263

264+
if (file.exists(toPath)) {
265+
file.remove(toPath)
266+
}
266267
if(zip(toPath, pkgname, flags="-r9Xq") != 0L) {
267268
pkg.cache.unlock(pkg.cache.env, version.dir)
268269
log.message("could not compress package dir ", fromPath , " and store it to ", toPath, level=1)

com.oracle.truffle.r.test.packages/r/install.packages.R

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ install.pkgs <- function(pkgnames, dependents.install=F, log=T) {
628628
result <- TRUE
629629
for (pkgname in pkgnames) {
630630
if (log) {
631-
log.message.always("BEGIN processing:", pkgname, "\n")
631+
log.message.always("BEGIN processing: ", pkgname, "\n")
632632
log.timestamp()
633633
}
634634
dependent.install.ok <- T
@@ -643,12 +643,12 @@ install.pkgs <- function(pkgnames, dependents.install=F, log=T) {
643643
# 3. a mixture of TRUE and NA: ok, but some more to install (the NAs)
644644
if (any(!dep.status, na.rm=T)) {
645645
# case 2
646-
log.message.always("not installing dependents of:", pkgname, ", one or more previously failed", "\n")
646+
log.message.always("not installing dependents of: ", pkgname, ", one or more previously failed", "\n")
647647
dependent.install.ok <- F
648648
} else {
649649
if (anyNA(dep.status)) {
650650
# case 3
651-
log.message.always("installing dependents of:", pkgname, "\n")
651+
log.message.always("installing dependents of: ", pkgname, "\n")
652652
dependent.install.ok <- install.pkgs(dependents, dependents.install=T)
653653
} else {
654654
# case 1
@@ -661,7 +661,7 @@ install.pkgs <- function(pkgnames, dependents.install=F, log=T) {
661661
cat("would install:", pkgname, "\n")
662662
} else {
663663
if (!dependent.install.ok) {
664-
log.message.always("not installing:", pkgname, "dependent install failure","\n")
664+
log.message.always("not installing: ", pkgname, "dependent install failure","\n")
665665
} else {
666666
should.install <- T
667667
if (pkgname %in% names(install.status)) {
@@ -678,7 +678,7 @@ install.pkgs <- function(pkgnames, dependents.install=F, log=T) {
678678
}
679679
}
680680
if (should.install) {
681-
log.message.always("installing:", pkgname, "(", install.count, "of", install.total, ")", "\n")
681+
log.message.always("installing: ", pkgname, "(", install.count, "of", install.total, ")", "\n")
682682
log.timestamp()
683683
this.result <- install.pkg(pkgname)
684684
result <- result && this.result
@@ -688,12 +688,12 @@ install.pkgs <- function(pkgnames, dependents.install=F, log=T) {
688688
}
689689
} else {
690690
msg <- if (install.status[pkgname]) "already installed" else "failed earlier"
691-
log.message.always("not installing:", pkgname, "(", install.count, "of", install.total, ")", msg)
691+
log.message.always("not installing: ", pkgname, "(", install.count, "of", install.total, ")", msg)
692692
}
693693
}
694694
}
695695
if (log) {
696-
log.message.always("END processing:", pkgname, "\n")
696+
log.message.always("END processing: ", pkgname, "\n")
697697
}
698698

699699
install.count = install.count + 1
@@ -711,15 +711,15 @@ install.suggests <- function(pkgnames) {
711711
ignore <- c(ignore, suggests[grepl(ignore.pattern[[i]], suggests)])
712712
}
713713
suggests <- if (class(ignore.pattern) == 'negation') ignore else setdiff(suggests, ignore)
714-
log.message("NOTE: ignoring suggested:", paste(ignore, collapse=','))
714+
log.message("NOTE: ignoring suggested: ", paste(ignore, collapse=','))
715715
}
716716
if (length(suggests) > 0) {
717717
if (is.fastr() && !ignore.blacklist) {
718718
# no point in trying to install blacklisted packages (which are likely)
719719
blacklist <- get.blacklist()
720720
nsuggests <- suggests[!suggests %in% blacklist]
721721
if (length(nsuggests) != length(suggests)) {
722-
log.message("not installing Suggests of:", pkgname, ", one or more is blacklisted: ", paste0(suggests[suggests %in% blacklist], collapse=","))
722+
log.message("not installing Suggests of: ", pkgname, ", one or more is blacklisted: ", paste0(suggests[suggests %in% blacklist], collapse=","))
723723
return()
724724
}
725725
}
@@ -730,11 +730,11 @@ install.suggests <- function(pkgnames) {
730730
# 3. a mixture of TRUE and NA: ok, but some more to install (the NAs)
731731
if (any(!dep.status, na.rm=T)) {
732732
# case 2
733-
log.message("not installing Suggests of:", pkgname, ", one or more previously failed")
733+
log.message("not installing Suggests of: ", pkgname, ", one or more previously failed")
734734
} else {
735735
if (anyNA(dep.status)) {
736736
# case 3
737-
log.message("installing Suggests of:", pkgname,":",paste(suggests[is.na(dep.status)], sep=", "))
737+
log.message("installing Suggests of: ", pkgname, ": ", paste(suggests[is.na(dep.status)], sep=", "))
738738
dependent.install.ok <- install.pkgs(suggests[is.na(dep.status)], dependents.install=F, log=F)
739739
} else {
740740
# case 1
@@ -785,7 +785,7 @@ show.install.status <- function(test.pkgnames) {
785785
do.it <- function() {
786786
log.message("Getting the list of packages to install", level = 2)
787787
test.pkgnames <- get.pkgs()
788-
log.message("List of packages to install:", paste0(test.pkgnames, collapse=","), level = 2)
788+
log.message("List of packages to install: ", paste0(test.pkgnames, collapse=","), level = 2)
789789

790790
if (list.versions) {
791791
for (pkgname in test.pkgnames) {
@@ -837,12 +837,12 @@ do.it <- function() {
837837
if (dry.run) {
838838
cat("would test:", pkgname, "\n")
839839
} else {
840-
log.message.always("BEGIN testing:", pkgname, "(", test.count, "of", test.total, ")")
840+
log.message.always("BEGIN testing: ", pkgname, "(", test.count, "of", test.total, ")")
841841
test.package(pkgname)
842-
log.message.always("END testing:", pkgname)
842+
log.message.always("END testing: ", pkgname)
843843
}
844844
} else {
845-
log.message.always("install failed, not testing:", pkgname)
845+
log.message.always("install failed, not testing: ", pkgname)
846846
}
847847
test.count = test.count + 1
848848
}
@@ -936,7 +936,7 @@ test.package <- function(pkgname) {
936936
res <- 1L
937937
}
938938
end.time <- proc.time()[[3]]
939-
log.message("TEST_TIME:", pkgname, end.time - start.time)
939+
log.message("TEST_TIME: ", pkgname, end.time - start.time)
940940
return (res)
941941
}
942942

@@ -1147,7 +1147,7 @@ quiet <- F
11471147
verbose <- F
11481148
very.verbose <- F
11491149
log.file <- file.path(getwd(), 'install.packages.R.log')
1150-
cat("The output is also logged into:", log.file, "\n")
1150+
cat("The output is also logged into: ", log.file, "\n")
11511151

11521152
loggable <- function(level) {
11531153
result <- T

0 commit comments

Comments
 (0)