File: test-lint.R

package info (click to toggle)
r-cran-rsconnect 0.8.15-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,068 kB
  • sloc: python: 77; sh: 13; makefile: 6
file content (84 lines) | stat: -rw-r--r-- 2,503 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
context("lint")

test_that("linter warns about absolute paths and relative paths", {

  ## Create a local file that 'server.R' tries to use
  testDir <- "~/.rsconnect-tests"
  exists <- file.exists(testDir)

  dir.create("~/.rsconnect-tests", showWarnings = FALSE)
  file.create("~/.rsconnect-tests/local-file.txt")

  serverPath <- list.files("shinyapp-with-absolute-paths",
                           pattern = "server\\.R$")

  result <- lint("shinyapp-with-absolute-paths")

  absPathLintedIndices <- result[[serverPath]]$absolute.paths$indices
  expect_identical(as.numeric(absPathLintedIndices), 15)

  relPathLintedIndices <- result[[serverPath]]$invalid.relative.paths$indices
  expect_identical(as.numeric(relPathLintedIndices), 16)

  if (!exists)
    unlink(testDir, recursive = TRUE)
})

test_that("badRelativePaths identifies bad paths correctly", {

  path <- "R/test.R"
  ok <- "file.path('../inst/include')"
  expect_false(badRelativePaths(ok, path = path))

  bad <- "file.path('../../elsewhere')"
  expect_true(badRelativePaths(bad, path = path))

  ok <- "'../foo', '../bar', '../baz'"
  expect_false(badRelativePaths(ok, path = path))

})

test_that("The linter identifies invalid application structures", {
  expect_error(lint("shiny-app-in-subdir"))
  lint("shiny-app-in-subdir/my-app")
})

test_that("The linter identifies files not matching in case sensitivity", {
  result <- lint("shinyapp-with-absolute-paths")
  server.R <- result[["server.R"]]
  filepath.capitalization <- server.R[["filepath.capitalization"]]
  # expect_true(filepath.capitalization$indices == 31)   # FIXME: This test fails for unknown reasons.  Leave this foe later inspection
})

test_that("The linter believes that the Shiny example apps are okay", {

  examples <- list.files(system.file("examples", package = "shiny"), full.names = TRUE)
  if (length(examples)) {

    results <- lapply(examples, lint)

    lints <- suppressMessages(lapply(results, printLinterResults))
    lapply(lints, function(project) {
      lapply(project, function(file) {
        lapply(file, function(linter) {
          expect_true(length(linter$indices) == 0)
        })
      })
    })

  }


})

test_that("The linter accepts a plumber API", {
  result <- lint("test-plumber")
  expect_false(is.null(result$plumber.R))
})

test_that("The linter accepts a TensorFlow Saved Model", {
  lint("tf-saved-model")
  lint("tf-human-readable-saved-model")
  lint("tf-saved-model-rootdir")
  expect_true(TRUE) # didn't stop()
})