...

Text file src/github.com/datawire/ambassador/v2/build-aux/tests/prelude.bats

Documentation: github.com/datawire/ambassador/v2/build-aux/tests

     1#!/usr/bin/env bats
     2
     3load common
     4
     5@test "prelude.mk: joinlist with separator" {
     6	check_expr_eq echo '$(call joinlist,/,foo bar baz)' 'foo/bar/baz'
     7}
     8
     9@test "prelude.mk: joinlist without separator" {
    10	check_expr_eq echo '$(call joinlist,,foo bar baz)' 'foobarbaz'
    11}
    12
    13@test "prelude.mk: quote.shell" {
    14	# This test relies on the fact that 'var.mk' is implemented
    15	# using `quote.shell`.
    16	cat >>Makefile <<-'__EOT__'
    17		include build-aux/prelude.mk
    18		include build-aux/var.mk
    19		define actual
    20		some'string"with`special characters)
    21		and newlines	and tabs
    22		and 2 trailing newlines
    23
    24
    25		endef
    26		tst: $(var.)actual
    27	__EOT__
    28
    29	make
    30	printf 'some'\''string"with`special characters)\nand newlines\tand tabs\nand 2 trailing newlines\n\n' > expected
    31	diff -u expected build-aux/.var.actual
    32}
    33
    34@test "prelude.mk: lazyonce" {
    35	if [[ "$(make --version | head -n1)" == 'GNU Make 3.81' ]]; then
    36		skip
    37	fi
    38	cat >>Makefile <<-'__EOT__'
    39		include build-aux/prelude.mk
    40		var = $(call lazyonce,var,$(info eval-time)value)
    41		$(info before)
    42		$(info a: $(var))
    43		$(info b: $(var))
    44		$(info c: $(var))
    45		tst: noop
    46		noop: ; @true
    47		.PHONY: noop
    48	__EOT__
    49
    50	make > actual
    51	printf '%s\n' > expected \
    52	       'before' \
    53	       'eval-time' \
    54	       'a: value' \
    55	       'b: value' \
    56	       'c: value'
    57	diff -u expected actual
    58}
    59
    60@test "prelude.mk: build-aux.dir" {
    61	cat >>Makefile <<-'__EOT__'
    62		include build-aux/prelude.mk
    63		include build-aux/var.mk
    64		tst: $(var.)build-aux.dir
    65	__EOT__
    66
    67	make
    68	# Check that it points to the right place
    69	[[ "$(cat build-aux/.var.build-aux.dir)" -ef build-aux ]]
    70}
    71
    72@test "prelude.mk: clobber" {
    73	if ! [[ -e build-aux/.git ]]; then
    74		# Because we check `git clean -ndx` to make sure
    75		# things are clean.
    76		skip
    77	fi
    78	(cd build-aux && git clean -fdx)
    79
    80	cat >>Makefile <<-'__EOT__'
    81		include build-aux/prelude.mk
    82		include build-aux/var.mk
    83		tst: $(COPY_IFCHANGED) $(MOVE_IFCHANGED) $(WRITE_IFCHANGED) $(TAP_DRIVER)
    84	__EOT__
    85
    86	[[ -d build-aux ]]
    87	[[ ! -d build-aux/bin ]]
    88	make tst
    89	[[ -d build-aux/bin ]]
    90	[[ -f build-aux/bin/copy-ifchanged && -x build-aux/bin/copy-ifchanged ]]
    91	[[ -n "$(cd build-aux && git clean -ndx)" ]]
    92	make clobber
    93	[[ -d build-aux ]]
    94	[[ ! -d build-aux/bin ]]
    95	[[ -z "$(cd build-aux && git clean -ndx)" ]]
    96}
    97
    98@test "prelude.mk: build-aux.bin-go.rule" {
    99	# TODO
   100}
   101
   102@test "prelude.mk: FORCE" {
   103	cat >>Makefile <<-'__EOT__'
   104		include build-aux/prelude.mk
   105		tst: without-force with-force
   106		without-force: ; touch $@
   107		with-force: FORCE ; touch $@
   108	__EOT__
   109
   110	make
   111	cp -a with-force with-force.bak
   112	cp -a without-force without-force.bak
   113
   114	sleep 2
   115
   116	make
   117	ls -l
   118	[[ with-force -nt with-force.bak ]]
   119	[[ ! without-force -nt without-force.bak ]]
   120	[[ ! without-force -ot without-force.bak ]]
   121}

View as plain text