Skip to content

Commit

Permalink
Merge pull request #102 from selkamand/101-snapshot-tests-fail-on-new…
Browse files Browse the repository at this point in the history
…-version-of-testthat

fix: updated snapshots to work with new version of testthat
  • Loading branch information
selkamand authored Jan 11, 2024
2 parents b8cc4db + b2ee12d commit 7b36c38
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 251 deletions.
230 changes: 138 additions & 92 deletions tests/testthat/_snaps/assert_compare.md

Large diffs are not rendered by default.

45 changes: 27 additions & 18 deletions tests/testthat/_snaps/assert_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,71 @@

Code
assert_is_numeric(2)
Error <rlang_error>
Assertion Function `function(x) x` must return TRUE if assertion passes and FALSE or a String if assertion should fail. Instead returned: `2`
Condition
Error in `assert_is_numeric()`:
! Assertion Function `function(x) x` must return TRUE if assertion passes and FALSE or a String if assertion should fail. Instead returned: `2`

# assertion function aborts if func returns FALSE without a default error message [plain]

Code
bad_assert_no_default_error(2)
Error <rlang_error>
Assertion Function `function(x) FALSE` returned FALSE, indicating assertion should fail, however no `default_error_msg` was supplied! Please add a `default_error_msg` to your assert_create call, or change function to return a string describing the error instead of `FALSE`
Condition
Error in `bad_assert_no_default_error()`:
! Assertion Function `function(x) FALSE` returned FALSE, indicating assertion should fail, however no `default_error_msg` was supplied! Please add a `default_error_msg` to your assert_create call, or change function to return a string describing the error instead of `FALSE`

---

Code
good_assert_no_default_error(2)
Error <rlang_error>
an error message
Condition
Error:
! an error message

# assertion function throws appropriate error when returning neither a flag NOR a string [plain]

Code
bad_assert_returns_char("foo")
Error <rlang_error>
Assertion Function `function(x) c("a", "b")` must return TRUE if assertion passes and FALSE or a String if assertion should fail. Instead returned: `a and b`
Condition
Error in `bad_assert_returns_char()`:
! Assertion Function `function(x) c("a", "b")` must return TRUE if assertion passes and FALSE or a String if assertion should fail. Instead returned: `a and b`

---

Code
bad_assert_returns_logical("foo")
Error <rlang_error>
Assertion Function `function(x) c(TRUE, TRUE)` must return TRUE if assertion passes and FALSE or a String if assertion should fail. Instead returned: `TRUE and TRUE`
Condition
Error in `bad_assert_returns_logical()`:
! Assertion Function `function(x) c(TRUE, TRUE)` must return TRUE if assertion passes and FALSE or a String if assertion should fail. Instead returned: `TRUE and TRUE`

---

Code
bad_assert_returns_factor("foo")
Error <rlang_error>
Assertion Function `function(x) factor(c(1, 4))` must return TRUE if assertion passes and FALSE or a String if assertion should fail. Instead returned: `1 and 4`
Condition
Error in `bad_assert_returns_factor()`:
! Assertion Function `function(x) factor(c(1, 4))` must return TRUE if assertion passes and FALSE or a String if assertion should fail. Instead returned: `1 and 4`

# assertion function works as expected with string-returning assertion functions [plain]

Code
assert_between_min_and_max("foo", min = 3, max = 5)
Error <rlang_error>
"foo" is a character, not numeric
Condition
Error:
! "foo" is a character, not numeric

---

Code
assert_between_min_and_max(6, min = 3, max = 5)
Error <rlang_error>
6 is over 5
Condition
Error:
! 6 is over 5

---

Code
assert_between_min_and_max(2, min = 3, max = 5)
Error <rlang_error>
2 is under 3
Condition
Error:
! 2 is under 3

135 changes: 81 additions & 54 deletions tests/testthat/_snaps/assert_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,190 +2,217 @@

Code
assert_file_exists(c("sdasda", "file2"))
Error <rlang_error>
'c("sdasda", "file2")' is not a string! (length is 2, not 1)
Condition
Error:
! 'c("sdasda", "file2")' is not a string! (length is 2, not 1)

---

Code
assert_file_exists(2)
Error <rlang_error>
'2' is not a string! (class is numeric, not character)
Condition
Error:
! '2' is not a string! (class is numeric, not character)

---

Code
assert_file_exists(c(dirpath, dirpath2))
Error <rlang_error>
'c(dirpath, dirpath2)' is not a string! (length is 2, not 1)
Condition
Error:
! 'c(dirpath, dirpath2)' is not a string! (length is 2, not 1)

# assert_all_files_exist() works

Code
assert_all_files_exist(c("sdasda", "file2"))
Error <rlang_error>
Failed to find files: 'sdasda' and 'file2'
Condition
Error:
! Failed to find files: 'sdasda' and 'file2'

---

Code
assert_all_files_exist(2)
Error <rlang_error>
'2' must be a character vector, not a numeric
Condition
Error:
! '2' must be a character vector, not a numeric

---

Code
assert_all_files_exist(c("sdasda", "file2"))
Error <rlang_error>
Failed to find files: 'sdasda' and 'file2'
Condition
Error:
! Failed to find files: 'sdasda' and 'file2'

# assert_directory_exists() works

Code
assert_directory_exists("asdasdaw")
Error <rlang_error>
Failed to find directory: 'asdasdaw'
Condition
Error:
! Failed to find directory: 'asdasdaw'

---

Code
assert_directory_exists(100)
Error <rlang_error>
'100' is not a string! (class is numeric, not character)
Condition
Error:
! '100' is not a string! (class is numeric, not character)

---

Code
assert_directory_exists(c("asdasdaw", "adwadwad"))
Error <rlang_error>
'c("asdasdaw", "adwadwad")' is not a string! (length is 2, not 1)
Condition
Error:
! 'c("asdasdaw", "adwadwad")' is not a string! (length is 2, not 1)

---

Code
assert_directory_exists(c(dirpath, dirpath2))
Error <rlang_error>
'c(dirpath, dirpath2)' is not a string! (length is 2, not 1)
Condition
Error:
! 'c(dirpath, dirpath2)' is not a string! (length is 2, not 1)

# assert_all_directories_exist() works

Code
assert_all_directories_exist("asdasdaw")
Error <rlang_error>
Failed to find directory: 'asdasdaw'
Condition
Error:
! Failed to find directory: 'asdasdaw'

---

Code
assert_all_directories_exist(c("asdasdaw", "adwadwad"))
Error <rlang_error>
Failed to find directories: 'asdasdaw' and 'adwadwad'
Condition
Error:
! Failed to find directories: 'asdasdaw' and 'adwadwad'

---

Code
assert_all_directories_exist(100)
Error <rlang_error>
'100' must be a character, not a numeric
Condition
Error:
! '100' must be a character, not a numeric

# assert_file_has_extension() works

Code
assert_file_has_extension(c("file.ext.gz", "file.ext"), extensions = "ext",
compression = TRUE)
Error <rlang_error>
'c("file.ext.gz", "file.ext")' is not a string! (length is 2, not 1)
Condition
Error:
! 'c("file.ext.gz", "file.ext")' is not a string! (length is 2, not 1)

---

Code
assert_file_has_extension(c("file.fns", "billy.fasta", "bob.fa", "billy.fa"),
extensions = c("fasta", "fa", "fns"))
Error <rlang_error>
'c("file.fns", "billy.fasta", "bob.fa", "billy.fa")' is not a string! (length is 4, not 1)
Condition
Error:
! 'c("file.fns", "billy.fasta", "bob.fa", "billy.fa")' is not a string! (length is 4, not 1)

---

Code
assert_file_has_extension("file.ext", extensions = "bob")
Error <rlang_error>
'"file.ext"' has an invalid extension (required extension/s: bob). The following file has an unexpected extension: [file.ext]
Condition
Error:
! '"file.ext"' has an invalid extension (required extension/s: bob). The following file has an unexpected extension: [file.ext]

---

Code
assert_file_has_extension("file.ADSAWD", extensions = "ext", compression = TRUE)
Error <rlang_error>
'"file.ADSAWD"' has an invalid extension (required extension/s: ext). The following file has an unexpected extension: [file.ADSAWD]
Condition
Error:
! '"file.ADSAWD"' has an invalid extension (required extension/s: ext). The following file has an unexpected extension: [file.ADSAWD]

---

Code
assert_file_has_extension("bob.blablaext", extensions = "ext")
Error <rlang_error>
'"bob.blablaext"' has an invalid extension (required extension/s: ext). The following file has an unexpected extension: [bob.blablaext]
Condition
Error:
! '"bob.blablaext"' has an invalid extension (required extension/s: ext). The following file has an unexpected extension: [bob.blablaext]

---

Code
assert_file_has_extension(c(TRUE), extensions = "ext")
Error <rlang_error>
'c(TRUE)' is not a string! (class is logical, not character)
Condition
Error:
! 'c(TRUE)' is not a string! (class is logical, not character)

# assert_all_files_have_extension() works

Code
assert_all_files_have_extension("file.ext", extensions = "bob")
Error <rlang_error>
'"file.ext"' has an invalid extension (required extension/s: bob). The following file has an unexpected extension: [file.ext]
Condition
Error:
! '"file.ext"' has an invalid extension (required extension/s: bob). The following file has an unexpected extension: [file.ext]

---

Code
assert_all_files_have_extension("file.ADSAWD", extensions = "ext", compression = TRUE)
Error <rlang_error>
'"file.ADSAWD"' has an invalid extension (required extension/s: ext). The following file has an unexpected extension: [file.ADSAWD]
Condition
Error:
! '"file.ADSAWD"' has an invalid extension (required extension/s: ext). The following file has an unexpected extension: [file.ADSAWD]

---

Code
assert_all_files_have_extension("bob.blablaext", extensions = "ext")
Error <rlang_error>
'"bob.blablaext"' has an invalid extension (required extension/s: ext). The following file has an unexpected extension: [bob.blablaext]
Condition
Error:
! '"bob.blablaext"' has an invalid extension (required extension/s: ext). The following file has an unexpected extension: [bob.blablaext]

---

Code
assert_all_files_have_extension(c(TRUE), extensions = "ext")
Error <rlang_error>
'c(TRUE)' must be a character, not a logical
Condition
Error:
! 'c(TRUE)' must be a character, not a logical

# assert_file_does_not_exist() works

Code
assert_file_does_not_exist(c("foo", "bar"))
Error <rlang_error>
'c("foo", "bar")' is not a string! (length is 2, not 1)
Condition
Error:
! 'c("foo", "bar")' is not a string! (length is 2, not 1)

---

Code
assert_file_does_not_exist(2)
Error <rlang_error>
'2' is not a string! (class is numeric, not character)
Condition
Error:
! '2' is not a string! (class is numeric, not character)

# assert_directory_does_not_exist() works

Code
assert_directory_does_not_exist(c("foo", "bar"))
Error <rlang_error>
'c("foo", "bar")' is not a string! (length is 2, not 1)
Condition
Error:
! 'c("foo", "bar")' is not a string! (length is 2, not 1)

---

Code
assert_directory_does_not_exist(2)
Error <rlang_error>
'2' is not a string! (class is numeric, not character)
Condition
Error:
! '2' is not a string! (class is numeric, not character)

Loading

0 comments on commit 7b36c38

Please sign in to comment.