1
2context("Install from SVN repositories")
3
4test_that("install_svn", {
5
6  skip_on_cran()
7  skip_if_offline()
8
9  Sys.unsetenv("R_TESTS")
10
11  lib <- tempfile()
12  on.exit(unlink(lib, recursive = TRUE), add = TRUE)
13  dir.create(lib)
14
15  url <- "https://github.com/mangothecat/simplegraph/trunk"
16  install_svn(url, lib = lib, quiet = TRUE)
17
18  expect_silent(packageDescription("simplegraph", lib.loc = lib))
19  expect_equal(
20    packageDescription("simplegraph", lib.loc = lib)$RemoteType,
21    "svn")
22
23  remote <- package2remote("simplegraph", lib = lib)
24  expect_s3_class(remote, "remote")
25  expect_s3_class(remote, "svn_remote")
26  expect_equal(format(remote), "SVN")
27  expect_equal(remote$url, url)
28  expect_equal(remote$svn_subdir, NULL)
29  expect_true(!is.na(remote$revision) && nzchar(remote$revision))
30  expect_equal(remote$args, NULL)
31})
32
33test_that("install_svn branch", {
34
35  skip_on_cran()
36  skip_if_offline()
37
38  Sys.unsetenv("R_TESTS")
39
40  lib <- tempfile()
41  on.exit(unlink(lib, recursive = TRUE), add = TRUE)
42  dir.create(lib)
43
44  url <- "https://github.com/mangothecat/simplegraph"
45  install_svn(
46    url,
47    subdir = "branches/remotes-test",
48    lib = lib,
49    quiet = TRUE
50  )
51
52  expect_silent(packageDescription("simplegraph", lib.loc = lib))
53  expect_equal(
54    packageDescription("simplegraph", lib.loc = lib)$RemoteType,
55    "svn")
56
57  remote <- package2remote("simplegraph", lib = lib)
58  expect_s3_class(remote, "remote")
59  expect_s3_class(remote, "svn_remote")
60  expect_equal(format(remote), "SVN")
61  expect_equal(remote$url, url)
62  expect_equal(remote$svn_subdir, "branches/remotes-test")
63  expect_true(!is.na(remote$revision) && nzchar(remote$revision))
64  expect_equal(remote$args, NULL)
65})
66
67test_that("install_svn subdir", {
68
69  skip_on_cran()
70  skip_if_offline()
71
72  Sys.unsetenv("R_TESTS")
73
74  lib <- tempfile()
75  on.exit(unlink(lib, recursive = TRUE), add = TRUE)
76  dir.create(lib)
77
78  mockery::stub(
79    install_svn,
80    "install_remotes",
81    function(remotes, ...) remotes)
82
83  rem <- install_svn(
84    "https://github.com/dmlc/xgboost/trunk",
85    subdir = "R-package"
86  )
87
88  expect_equal(rem[[1]]$svn_subdir, "R-package")
89})
90
91test_that("remote_download.svn_remote error", {
92
93  skip_on_cran()
94
95  x <- list(url = "http://foo.bar.com")
96
97  mockery::stub(remote_download.svn_remote, "system2", 1)
98  expect_error(
99    remote_download.svn_remote(x),
100    "There seems to be a problem retrieving"
101  )
102})
103
104test_that("downloading an SVN revision", {
105
106  skip_on_cran()
107  skip_if_offline()
108
109  x <- list(
110    url = "https://github.com/mangothecat/simplegraph/trunk",
111    revision = "r28"
112  )
113
114  bundle <- remote_download.svn_remote(x)
115  on.exit(unlink(bundle), add = TRUE)
116
117  expect_output(
118    print(list.files(bundle)),
119    "DESCRIPTION"
120  )
121})
122
123test_that("downloading a wrong SVN revision", {
124
125  skip_on_cran()
126  skip_if_offline()
127
128  x <- list(
129    url = "https://github.com/mangothecat/simplegraph/trunk",
130    revision = "xxx"
131  )
132
133  expect_error(
134    remote_download.svn_remote(x)
135  )
136})
137
138
139test_that("svn_path", {
140
141  tmp <- tempfile()
142  expect_error(
143    svn_path(tmp),
144    "does not exist"
145  )
146
147  cat("Hello", file = tmp)
148  expect_equal(svn_path(tmp), tmp)
149
150  mockery::stub(svn_path, "Sys.which", "")
151  mockery::stub(svn_path, "os_type", "windows")
152  mockery::stub(svn_path, "file.exists", FALSE)
153  expect_error(
154    svn_path(),
155    "SVN does not seem to be installed on your system"
156  )
157})
158