Skip to content

Commit

Permalink
prelude_bool.mk: Add
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeShu committed Sep 5, 2019
1 parent 049918e commit 6d78aac
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions prelude.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
# (none)
## Outputs ##
#
# Boolean support:
# - Variable: TRUE = T
# - Variable: FALSE =
# - Function: not
#
# String support:
# - Variable: export NL
# - Variable: SPACE
Expand Down Expand Up @@ -53,6 +58,7 @@ _prelude.mk := $(lastword $(MAKEFILE_LIST))
# [GMSL](https://gmsl.sourceforge.io/). Absolutely nothing in any of
# the `prelude_*.mk` files is allowed to be eager, so ordering doesn't
# matter. Anything eager must go in this main `prelude.mk` file.
include $(dir $(_prelude.mk))prelude_bool.mk
include $(dir $(_prelude.mk))prelude_str.mk
include $(dir $(_prelude.mk))prelude_path.mk
include $(dir $(_prelude.mk))prelude_go.mk
Expand Down
12 changes: 12 additions & 0 deletions prelude_bool.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This is part of `prelude.mk`, split out for organizational purposes.
# !!! NOTHING EAGER IS ALLOWED TO HAPPEN IN THIS FILE !!!

#
# Boolean support

# $(TRUE) is a non-empty string; $(FALSE) is an empty string.
TRUE = T
FALSE =

# Usage: $(call not,BOOL)
not = $(if $1,$(FALSE),$(TRUE))
23 changes: 23 additions & 0 deletions tests/prelude_bool.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bats

load common

@test "prelude_bool.mk: TRUE" {
check_expr_eq strict '$(if $(TRUE),pass,fail)' 'pass'
}

@test "prelude_bool.mk: FALSE" {
check_expr_eq strict '$(if $(FALSE),fail,pass)' 'pass'
}

@test "prelude_bool.mk: not TRUE" {
check_expr_eq strict '$(if $(call not,$(TRUE)),fail,pass)' 'pass'
}

@test "prelude_bool.mk: not FALSE" {
check_expr_eq strict '$(if $(call not,$(FALSE)),pass,fail)' 'pass'
}

@test "prelude_bool.mk: not truthy" {
check_expr_eq strict '$(if $(call not,truthy),fail,pass)' 'pass'
}

0 comments on commit 6d78aac

Please sign in to comment.