Skip to content

Commit 199a4eb

Browse files
committed
Fixing tests
1 parent c378964 commit 199a4eb

File tree

4 files changed

+194
-2
lines changed

4 files changed

+194
-2
lines changed

inst/hooks/exported/validate-renv-lock.R

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,91 @@ library(readr)
1212
library(jsonvalidate)
1313

1414
files <- commandArgs(trailing = TRUE)
15-
path_renv_schema <- file.path("inst", "renv.schema.json")
16-
renv_schema <- readr::read_file(path_renv_schema)
15+
renv_schema <- '{
16+
"$schema": "http://json-schema.org/draft-07/schema#",
17+
"title": "renv.lock file.",
18+
"description": "A schema for renv.lock files generated by {renv}",
19+
"type": "object",
20+
"properties": {
21+
"R": {
22+
"type": "object",
23+
"properties": {
24+
"Version": {
25+
"type": "string"
26+
},
27+
"Repositories": {
28+
"type": "array",
29+
"items": {
30+
"type": "object",
31+
"properties": {
32+
"Name": {
33+
"type": "string"
34+
},
35+
"URL": {
36+
"type": "string",
37+
"format": "uri"
38+
}
39+
},
40+
"required": ["Name", "URL"]
41+
}
42+
}
43+
},
44+
"required": ["Version", "Repositories"]
45+
},
46+
"Packages": {
47+
"type": "object",
48+
"additionalProperties": {
49+
"type": "object",
50+
"properties": {
51+
"Package": {
52+
"type": "string"
53+
},
54+
"Version": {
55+
"type": "string"
56+
},
57+
"Source": {
58+
"type": "string"
59+
},
60+
"Repository": {
61+
"type": "string"
62+
},
63+
"Hash": {
64+
"type": "string",
65+
"pattern": "^[a-fA-F0-9]{32}$"
66+
},
67+
"RemoteType": {
68+
"type": "string"
69+
},
70+
"RemoteHost": {
71+
"type": "string",
72+
"format": "uri"
73+
},
74+
"RemoteUsername": {
75+
"type": "string"
76+
},
77+
"RemoteRepo": {
78+
"type": "string"
79+
},
80+
"RemoteRef": {
81+
"type": "string"
82+
},
83+
"RemoteSha": {
84+
"type": "string",
85+
"pattern": "^[a-fA-F0-9]{40}$"
86+
},
87+
"Requirements": {
88+
"type": "array",
89+
"items": {
90+
"type": "string"
91+
}
92+
}
93+
},
94+
"required": ["Package", "Version", "Source", "Hash"]
95+
}
96+
}
97+
},
98+
"required": ["R", "Packages"]
99+
}'
17100

18101
validate_renv_lock <- function(renv_path, renv_lock_schema) {
19102
renv_json <- readr::read_file(renv_path)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"R": {
3+
"Version": "4.3.2",
4+
"Repositories": [
5+
{
6+
"Name": "CRAN",
7+
"URL": "https://cloud.r-project.org"
8+
}
9+
]
10+
},
11+
"Packages": {
12+
"ggplot2": {
13+
"Package": "ggplot2",
14+
"Version": "3.4.4",
15+
"Source": "Repository",
16+
"Repository": "CRAN",
17+
"Requirements": [
18+
"MASS",
19+
"R",
20+
"cli",
21+
"glue",
22+
"grDevices",
23+
"grid",
24+
"gtable",
25+
"isoband",
26+
"lifecycle",
27+
"mgcv",
28+
"rlang",
29+
"scales",
30+
"stats",
31+
"tibble",
32+
"vctrs",
33+
"withr"
34+
],
35+
"Hash": "313d31eff274ecf4c1d3581db7241f9"
36+
},
37+
"renv": {
38+
"Package": "renv",
39+
"Version": "1.0.3",
40+
"Source": "Repository",
41+
"Repository": "CRAN",
42+
"Requirements": [
43+
"utils"
44+
],
45+
"Hash": "41b847654f567341725473431dd0d5ab"
46+
}
47+
}
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"R": {
3+
"Version": "4.3.2",
4+
"Repositories": [
5+
{
6+
"Name": "CRAN",
7+
"URL": "https://cloud.r-project.org"
8+
}
9+
]
10+
},
11+
"Packages": {
12+
"ggplot2": {
13+
"Package": "ggplot2",
14+
"Version": "3.4.4",
15+
"Source": "Repository",
16+
"Repository": "CRAN",
17+
"Requirements": [
18+
"MASS",
19+
"R",
20+
"cli",
21+
"glue",
22+
"grDevices",
23+
"grid",
24+
"gtable",
25+
"isoband",
26+
"lifecycle",
27+
"mgcv",
28+
"rlang",
29+
"scales",
30+
"stats",
31+
"tibble",
32+
"vctrs",
33+
"withr"
34+
],
35+
"Hash": "313d31eff2274ecf4c1d3581db7241f9"
36+
},
37+
"renv": {
38+
"Package": "renv",
39+
"Version": "1.0.3",
40+
"Source": "Repository",
41+
"Repository": "CRAN",
42+
"Requirements": [
43+
"utils"
44+
],
45+
"Hash": "41b847654f567341725473431dd0d5ab"
46+
}
47+
}
48+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# success
2+
run_test(
3+
"validate-renv-lock",
4+
file_name = c("validate-renv-lock"),
5+
suffix = "-success.lock"
6+
)
7+
8+
# failure
9+
run_test(
10+
"validate-renv-lock",
11+
file_name = c("validate-renv-lock"),
12+
suffix = "-fail.lock"
13+
)

0 commit comments

Comments
 (0)