Skip to content

Commit 5feb20c

Browse files
authored
Merge pull request #5 from jakubsob/4-indentation
✨ Allow setting feature file indentation
2 parents 463ddff + d5f4d85 commit 5feb20c

File tree

16 files changed

+203
-15
lines changed

16 files changed

+203
-15
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
33
on:
44
push:
5-
branches: [main, master]
5+
branches: [main, master, dev]
66
pull_request:
7-
branches: [main, master]
7+
branches: [main, master, dev]
88

99
name: R-CMD-check
1010

.github/workflows/test-coverage.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
33
on:
44
push:
5-
branches: [main, master]
5+
branches: [main, master, dev]
66
pull_request:
7-
branches: [main, master]
7+
branches: [main, master, dev]
88

99
name: test-coverage
1010

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: cucumber
22
Type: Package
33
Title: Behavior-Driven Development for R
4-
Version: 1.1.0
4+
Version: 1.1.1
55
Authors@R: person("Jakub", "Sobolewski", email = "[email protected]", role = c("aut", "cre"))
66
Description: Write executable specifications in a natural language that describes how your code should behave.
77
Write specifications in feature files using 'Gherkin' language and execute them using functions implemented in R.
@@ -24,6 +24,7 @@ Suggests:
2424
Config/testthat/edition: 3
2525
Imports:
2626
checkmate,
27+
cli,
2728
dplyr,
2829
fs,
2930
glue,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ importFrom(checkmate,assert_string)
1616
importFrom(checkmate,assert_subset)
1717
importFrom(checkmate,test_character)
1818
importFrom(checkmate,test_subset)
19+
importFrom(cli,cli_abort)
1920
importFrom(dplyr,bind_cols)
2021
importFrom(fs,dir_ls)
2122
importFrom(glue,glue)

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# cucumber 1.1.1
2+
3+
- ✨ Added option to set the indent of feature files. Useful when you use a different indent than the default 2 whitespaces. All user-facing options are documented in `?cucumber::opts`. (#5)
4+
- ✨ Added validation of feature files to check if they have a consistent indentation. (#5)
5+
16
# cucumber 1.1.0
27

38
- ✨ Added scenario `before` and `after` hooks.

R/options.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#' {cucumber} Options
2+
#'
3+
#' Internally used, package-specific options.
4+
#' They allow overriding the default behavior of the package.
5+
#'
6+
#' @details
7+
#'
8+
#' The following options are available:
9+
#'
10+
#' - `cucumber.indent`
11+
#'
12+
#' Regular expression for the indent of the feature files.
13+
#'
14+
#' default: `^\\s{2}`
15+
#'
16+
#' - `cucumber.interactive`
17+
#'
18+
#' Logical value indicating whether to ask which feature files to run.
19+
#'
20+
#' default: `FALSE`
21+
#'
22+
#' See [base::options()] and [base::getOption()] on how to work with options.
23+
#'
24+
#' @md
25+
#' @name opts
26+
NULL

R/test.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ test <- function(
5656
} # nocov end
5757
feature_files |>
5858
map(readLines) |>
59+
map(validate_feature) |>
5960
map(normalize_feature) |>
6061
walk(run, steps = steps, parameters = get_parameters())
6162
}

R/tokenize.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
INDENT <- "^\\s{2}"
21
NODE_REGEX <- paste0(
32
"^(?!\\s+)(",
43
paste0(
@@ -32,7 +31,7 @@ remove_trailing_colon <- function(x) {
3231

3332
#' @importFrom stringr str_remove_all
3433
remove_indent <- function(x) {
35-
str_remove_all(x, INDENT)
34+
str_remove_all(x, getOption("cucumber.indent", default = "^\\s{2}"))
3635
}
3736

3837
#' @importFrom stringr str_detect

R/validate.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#' Validate lines read from a feature file
2+
#' @keywords internal
3+
validate_feature <- function(lines) {
4+
# Remove comments and empty lines for validation
5+
clean_lines <- remove_comments(remove_empty_lines(lines))
6+
clean_lines |>
7+
validate_indentation()
8+
invisible(lines)
9+
}
10+
11+
#' @keywords internal
12+
#' @importFrom stringr str_detect
13+
#' @importFrom cli cli_abort
14+
validate_indentation <- function(lines) {
15+
indent <- getOption("cucumber.indent", default = "^\\s{2}")
16+
test_lines <- lines[!str_detect(lines, "^Feature")] |>
17+
remove_empty_lines()
18+
if (any(!str_detect(test_lines, indent))) {
19+
cli_abort(c(
20+
"All lines must be indented with {indent}",
21+
"i" = "Check the {.code getOption('cucumber.indent')} option if it is set to your feature file indent."
22+
))
23+
}
24+
invisible(lines)
25+
}

man/opts.Rd

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)