Debian Codegraph @

tests/test-cran/test-github.R

raw
1 library(testit)
2
3 assert('release_versions() handles X.Y and X.Y.0 formats', {
4 r = release_versions('0.59')
5 (r$next_ver %==% '0.60')
6 (r$patch %==% '0.59.1')
7
8 r = release_versions('1.2.0')
9 (r$next_ver %==% '1.3.0')
10 (r$patch %==% '1.2.1')
11
12 r = release_versions('10.0')
13 (r$next_ver %==% '10.1')
14 (r$patch %==% '10.0.1')
15
16 (has_error(release_versions('1.2.3')))
17 (has_error(release_versions('1')))
18 (has_error(release_versions('1.2.1')))
19 })
20
21 assert('news_tpl() detects header format and falls back correctly', {
22 hdr = function(news, pkg, ver, v) sprintf(news_tpl(news, pkg, ver), pkg, v)
23
24 (hdr(c('# CHANGES IN foo VERSION 1.0', '', 'text'), 'foo', '1.0', '1.1') %==% '# CHANGES IN foo VERSION 1.1')
25 (hdr(c('# foo 1.0', '', 'text'), 'foo', '1.0', '1.1') %==% '# foo 1.1')
26 (hdr(c('# foo (version 1.0)', '', 'text'), 'foo', '1.0', '1.1') %==% '# foo (version 1.1)')
27
28 # pkg name must match as whole word (not substring of another word)
29 (hdr(c('# CHANGES in GE 1.1'), 'GE', '1.1', '1.2') %==% '# CHANGES in GE 1.2')
30
31 # fallback: empty NEWS or unrecognized heading
32 (hdr(character(0), 'foo', '1.0', '1.1') %==% '# CHANGES IN foo VERSION 1.1')
33 (hdr(c('# Some unrelated heading'), 'foo', '1.0', '1.1') %==% '# CHANGES IN foo VERSION 1.1')
34 })
35
36 assert('github_token() returns the token from environment variables', {
37 # save original env vars
38 orig = Sys.getenv(c('GITHUB_PAT', 'GITHUB_TOKEN', 'GH_TOKEN'), names = TRUE)
39 on.exit({
40 do.call(Sys.setenv, as.list(orig))
41 }, add = TRUE)
42 # unset all three
43 Sys.unsetenv(c('GITHUB_PAT', 'GITHUB_TOKEN', 'GH_TOKEN'))
44 (github_token() %==% '')
45
46 Sys.setenv(GITHUB_PAT = 'pat_token')
47 (github_token() %==% 'pat_token')
48
49 Sys.unsetenv('GITHUB_PAT')
50 Sys.setenv(GITHUB_TOKEN = 'token_val')
51 (github_token() %==% 'token_val')
52
53 Sys.unsetenv('GITHUB_TOKEN')
54 Sys.setenv(GH_TOKEN = 'gh_token_val')
55 (github_token() %==% 'gh_token_val')
56
57 # priority: GITHUB_PAT > GITHUB_TOKEN > GH_TOKEN
58 Sys.setenv(GITHUB_PAT = 'pat_1st', GITHUB_TOKEN = 'token_2nd', GH_TOKEN = 'gh_3rd')
59 (github_token() %==% 'pat_1st')
60 })