Skip to content

Commit

Permalink
prelude_str.mk: Add a 'str.eq' function
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeShu committed Sep 5, 2019
1 parent 6d78aac commit 5311af3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions prelude.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# String support:
# - Variable: export NL
# - Variable: SPACE
# - Function: str.eq
#
# Path support:
# - Function: path.trimprefix
Expand Down
4 changes: 4 additions & 0 deletions prelude_str.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ export NL
define SPACE

endef

# Usage: $(call str.eq,STR1,STR2)
# Evaluates to either $(TRUE) or $(FALSE)
str.eq = $(if $(subst x$1,,x$2)$(subst x$2,,x$1),$(FALSE),$(TRUE))
26 changes: 26 additions & 0 deletions tests/prelude_str.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,29 @@ load common
# Honestly, this checks `quote.shell` more than it does SPACE.
check_expr_eq strict '$(SPACE)' ' '
}

@test "prelude_str.mk: str.eq" {
cat >>Makefile <<-'__EOT__'
include build-aux/prelude.mk
test = $(info ("$1" == "$2") => $(if $(call str.eq,$1,$2),$$(TRUE),$$(FALSE)))
$(call test,foo,foo)
$(call test,foo,bar)
$(call test,bar,bar)
$(call test,f%,foo)
$(call test,foo,f%)
$(call test,f%,f%)
all: noop
noop: ; @true
.PHONY: noop
__EOT__

make >actual
printf '("%s" == "%s") => $(%s)\n' >expected \
foo foo TRUE \
foo bar FALSE \
bar bar TRUE \
f% foo FALSE \
foo f% FALSE \
f% f% TRUE
diff -u expected actual
}

0 comments on commit 5311af3

Please sign in to comment.