Skip to content

Commit fd67ab9

Browse files
committed
Added branch unit tests (#5)
- also now `git_checkout()` obeys the echo cmd framework (silenceable) with `gitr_echo_cmd = FALSE`
1 parent 402df75 commit fd67ab9

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎R/git.R‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ git_checkout <- function(branch = NULL) {
109109
} else {
110110
out <- git("checkout", branch)
111111
}
112-
cat(out$stdout, sep = "\n")
113-
cat(out$stderr, sep = "\n")
112+
if ( getOption("gitr_echo_cmd", TRUE) ) {
113+
cat(out$stdout, sep = "\n")
114+
cat(out$stderr, sep = "\n")
115+
}
114116
}
115117
invisible()
116118
}

‎tests/testthat/test-git-branch.R‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
withr::local_options(list(gitr_echo_cmd = FALSE))
3+
skip_if_not(is_git())
4+
5+
# Testing ----
6+
# tests `git_checkout()` and current and default branch functions
7+
8+
test_that("`git_default_br()` returns proper default", {
9+
expect_equal(git_default_br(), "main")
10+
})
11+
12+
test_that("`git_current_br()` returns proper default", {
13+
cur <- git_current_br()
14+
withr::defer(git_checkout(cur))
15+
withr::defer(git("branch", "-D", "wip-foo"), priority = "last")
16+
git_checkout("wip-foo")
17+
expect_equal(git_current_br(), "wip-foo")
18+
})

0 commit comments

Comments
 (0)