1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
|
#
# Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
default: all
include $(SPEC)
include MakeBase.gmk
include UtilsForTests.gmk
THIS_FILE := $(TOPDIR)/test/make/TestMakeBase.gmk
DEPS := $(THIS_FILE) \
$(TOPDIR)/make/common/MakeBase.gmk \
#
OUTPUT_DIR := $(TESTMAKE_OUTPUTDIR)/make-base
$(call MakeDir, $(OUTPUT_DIR))
################################################################################
# Escape $
ifneq ($(call EscapeDollar, foo$$bar), foo\$$bar)
$(error EscapeDollar failed $(call EscapeDollar, foo$$bar) foo\$$bar)
endif
ESCAPE_DOLLAR_DIR := $(OUTPUT_DIR)/escape-dollar
$(ESCAPE_DOLLAR_DIR)/_escape_dollar: $(DEPS)
$(RM) -r $(@D)
$(MKDIR) -p $(@D)
$(ECHO) foo\$$bar > $(@D)/file1
$(ECHO) $(call EscapeDollar, foo$$bar) > $(@D)/file2
$(ECHO) $(call EscapeDollar, foo\$$bar) > $(@D)/file3
$(DIFF) $(@D)/file1 $(@D)/file2
$(DIFF) $(@D)/file1 $(@D)/file3
$(TOUCH) $@
TEST_TARGETS += $(ESCAPE_DOLLAR_DIR)/_escape_dollar
################################################################################
# Test containing and not-containing
CONT_LIST := foo bar baz foobar foobaz
# Param 1 - string to look for
# Param 2 - expected result
define TestContaining
value := $$(call containing, $1, $(CONT_LIST))
ifneq ($$(value), $2)
$$(info (call containing, $1, $(CONT_LIST)))
$$(error result >$$(value)<, expected >$2<)
endif
endef
$(eval $(call TestContaining,bar,bar foobar))
$(eval $(call TestContaining,foo bar,foo bar foobar foobaz))
# Param 1 - string to look for
# Param 2 - expected result
define TestNotContaining
value := $$(call not-containing, $1, $(CONT_LIST))
ifneq ($$(value), $2)
$$(info (call not-containing, $1, $(CONT_LIST)))
$$(error result >$$(value)<, expected >$2<)
endif
endef
$(eval $(call TestNotContaining,bar,foo baz foobaz))
$(eval $(call TestNotContaining,foo bar,baz))
################################################################################
# Test Equals
EQUALS_VALUE1 := value1$(SPACE)
EQUALS_VALUE2 := value2
ifneq ($(call equals, $(EQUALS_VALUE1), $(EQUALS_VALUE2)), )
$(error The strings >$(EQUALS_VALUE1)< and >$(EQUALS_VALUE2)< are equal)
endif
ifeq ($(call equals, $(EQUALS_VALUE1), $(EQUALS_VALUE1)), )
$(error The strings >$(EQUALS_VALUE1)< and >$(EQUALS_VALUE1)< are not equal)
endif
################################################################################
# Test remove-prefixes
$(eval $(call assert-equals, \
$(call remove-prefixes, pre, prefix postfix), fix postfix, \
Prefixes not properly removed))
$(eval $(call assert-equals, \
$(call remove-prefixes, pre post, prefix postfix), fix fix, \
Prefixes not properly removed))
################################################################################
# Test ShellQuote
SHELL_QUOTE_VALUE := foo '""' "''" bar
SHELL_QUOTE_RESULT := $(shell $(ECHO) $(call ShellQuote, \
$(SHELL_QUOTE_VALUE)))
ifneq ($(SHELL_QUOTE_VALUE), $(SHELL_QUOTE_RESULT))
$(error Expected: >$(SHELL_QUOTE_VALUE)< - Result: >$(SHELL_QUOTE_RESULT)<)
endif
################################################################################
# Test read and write to file
READ_WRITE_FILE := $(OUTPUT_DIR)/read-write
READ_WRITE_VALUE := foo '""' "''" \t\n\\ bar
$(call WriteFile, $(READ_WRITE_VALUE), $(READ_WRITE_FILE))
READ_WRITE_RESULT := $(call ReadFile, $(READ_WRITE_FILE))
ifneq ($(READ_WRITE_VALUE), $(READ_WRITE_RESULT))
$(error Expected: >$(READ_WRITE_VALUE)< - Result: >$(READ_WRITE_RESULT)<)
endif
################################################################################
# Test creating dependencies on make variables
VARDEP_DIR := $(OUTPUT_DIR)/vardep
VARDEP_SRC_FILE := $(VARDEP_DIR)/src-file
VARDEP_TARGET_FILE := $(VARDEP_DIR)/target-file
VARDEP_FLAG_FILE := $(VARDEP_DIR)/flag-file
$(VARDEP_DIR)/src-file:
$(MKDIR) -p $(@D)
$(ECHO) "some string XXX" > $@
$(VARDEP_TARGET_FILE): $(VARDEP_DIR)/src-file \
$(call DependOnVariable, VARDEP_TEST_VAR)
$(MKDIR) -p $(@D)
$(SED) -e 's/XXX/$(VARDEP_TEST_VAR)/g' $< > $@
$(TOUCH) $(VARDEP_FLAG_FILE)
test-vardep:
$(RM) $(VARDEP_SRC_FILE) $(VARDEP_TARGET_FILE) $(VARDEP_FLAG_FILE)
#
# Simply create the target file and verify that it has the correct value
#
$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value1 $(VARDEP_TARGET_FILE)
$(PRINTF) "Expecting value1: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`"
test "some string value1" = "`$(CAT) $(VARDEP_DIR)/target-file`"
test -e $(VARDEP_FLAG_FILE)
#
# Make the target file again and verify that the value is updated with
# the new value
#
$(SLEEP_ON_MAC)
$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value2 $(VARDEP_TARGET_FILE)
$(PRINTF) "Expecting value2: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`"
test "some string value2" = "`$(CAT) $(VARDEP_DIR)/target-file`"
test -e $(VARDEP_FLAG_FILE)
#
# Make the target again with the same value and verify that the recipe
# was never run by checking that the flag file was not recreated
#
$(SLEEP_ON_MAC)
$(RM) $(VARDEP_FLAG_FILE)
$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=value2 $(VARDEP_TARGET_FILE)
$(PRINTF) "Expecting value2: %s\n" "`$(CAT) $(VARDEP_DIR)/target-file`"
test "some string value2" = "`$(CAT) $(VARDEP_DIR)/target-file`"
test ! -e $(VARDEP_FLAG_FILE)
#
# Test running with spaces at the end and the middle of the value
# and verify that the file isn't rewritten the second time
#
$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR="value3 foo " $(VARDEP_TARGET_FILE)
$(RM) $(VARDEP_FLAG_FILE)
$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR="value3 foo" $(VARDEP_TARGET_FILE)
test ! -e $(VARDEP_FLAG_FILE)
$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR=" value3 foo" $(VARDEP_TARGET_FILE)
test ! -e $(VARDEP_FLAG_FILE)
#
# Test including some problematic characters
$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR='value4 \$$ORIGIN' $(VARDEP_TARGET_FILE)
$(RM) $(VARDEP_FLAG_FILE)
$(MAKE) -f $(THIS_FILE) VARDEP_TEST_VAR='value4 \$$ORIGIN' $(VARDEP_TARGET_FILE)
test ! -e $(VARDEP_FLAG_FILE)
# Test specifying a specific value file to store variable in
VARDEP_VALUE_FILE := $(VARDEP_DIR)/value-file
VARDEP_TEST_VAR2 := value3
VARDEP_RETURN_VALUE := $(call DependOnVariable, VARDEP_TEST_VAR2, $(VARDEP_VALUE_FILE))
$(eval $(call assert-equals, $(VARDEP_RETURN_VALUE), $(VARDEP_VALUE_FILE), \
Wrong filename returned))
-include $(VARDEP_VALUE_FILE)
$(eval $(call assert-equals, $(VARDEP_TEST_VAR2_old), $(VARDEP_TEST_VAR2), \
Wrong contents in vardeps file))
# Test with a variable value containing some problematic characters
VARDEP_TEST_VAR3 := foo '""' "''" bar \$$ORIGIN &\#x00a9
VARDEP_VALUE_FILE := $(call DependOnVariable, VARDEP_TEST_VAR3)
-include $(VARDEP_VALUE_FILE)
$(eval $(call assert-equals, $(call EscapeHash,$(VARDEP_TEST_VAR3_old)), \
$(call EscapeHash,$(VARDEP_TEST_VAR3)), \
Wrong contents in vardep file))
TEST_TARGETS += test-vardep
################################################################################
# Test sequence
ifneq ($(call sequence, 1, 1), 1)
$(error Sequence 1, 1 should be "1", but was $(call sequence, 1, 1))
endif
ifneq ($(call sequence, 2, 3), 2 3)
$(error Sequence 2, 3 should be "2 3", but was $(call sequence, 2, 3))
endif
ifneq ($(call sequence, 4, 9), 4 5 6 7 8 9)
$(error Sequence 4, 9 should be "4 5 6 7 8 9", but was $(call sequence, 4, 9))
endif
ifneq ($(call sequence, 5, 15), 5 6 7 8 9 10 11 12 13 14 15)
$(error Sequence 5, 15 should be "5 6 7 8 9 10 11 12 13 14 15", \
but was $(call sequence, 5, 15))
endif
################################################################################
# Test that PathList is safe when called multiple nested times.
PATHLIST_INPUT := foo bar baz
$(eval $(call assert-equals, \
$(call PathList, $(call PathList, $(PATHLIST_INPUT))), \
$(call PathList, $(PATHLIST_INPUT)), \
PathList call not safe for calling twice))
################################################################################
# Test FindCommonPathPrefix
$(eval $(call assert-equals, \
$(call FindCommonPathPrefix, /foo/bar/baz, /foo/bar/banan), \
/foo/bar, \
FindCommonPathPrefix, \
))
$(eval $(call assert-equals, \
$(call FindCommonPathPrefix, /foo/bar/baz, /foo/bar), \
/foo/bar, \
FindCommonPathPrefix, \
))
$(eval $(call assert-equals, \
$(call FindCommonPathPrefix, /foo/bar/baz, /foo/bar/), \
/foo/bar, \
FindCommonPathPrefix, \
))
$(eval $(call assert-equals, \
$(call FindCommonPathPrefix, foo/bar/baz, foo/bar/banan), \
foo/bar, \
FindCommonPathPrefix, \
))
$(eval $(call assert-equals, \
$(call FindCommonPathPrefix, foo/bar/baz, /foo/bar/banan), \
, \
FindCommonPathPrefix, \
))
################################################################################
# DirToDotDot
$(eval $(call assert-equals, \
$(call DirToDotDot, foo/bar/baz/), \
../../.., \
DirToDotDot, \
))
$(eval $(call assert-equals, \
$(call DirToDotDot, foo/bar), \
../.., \
DirToDotDot, \
))
$(eval $(call assert-equals, \
$(call DirToDotDot, /foo), \
.., \
DirToDotDot, \
))
################################################################################
# RelativePath
$(eval $(call assert-equals, \
$(call RelativePath, foo/bar/baz, foo/bar/banan), \
../baz, \
RelativePath, \
))
$(eval $(call assert-equals, \
$(call RelativePath, foo/bar/baz/banan/kung, foo/bar/banan/kung), \
../../baz/banan/kung, \
RelativePath, \
))
$(eval $(call assert-equals, \
$(call RelativePath, /foo/bar/baz/banan/kung, /foo/bar/banan/kung/), \
../../baz/banan/kung, \
RelativePath, \
))
################################################################################
# Test ParseKeywordVariable
KWBASE := APA=banan;GURKA=tomat;COUNT=1%202%203%204%205;SUM=1+2+3+4+5;MANY_WORDS=I have the best words.
$(eval $(call ParseKeywordVariable, KWBASE, \
KEYWORDS := APA GURKA SUM, \
STRING_KEYWORDS := COUNT MANY_WORDS, \
))
$(eval $(call assert-equals, \
$(KWBASE_APA), \
banan, \
ParseKeywordVariable failed to parse APA, \
))
$(eval $(call assert-equals, \
$(KWBASE_COUNT), \
1 2 3 4 5, \
ParseKeywordVariable failed to parse COUNT, \
))
$(eval $(call assert-equals, \
$(KWBASE_SUM), \
1+2+3+4+5, \
ParseKeywordVariable failed to parse SUM, \
))
$(eval $(call assert-equals, \
$(KWBASE_MANY_WORDS), \
I have the best words., \
ParseKeywordVariable failed to parse MANY_WORDS, \
))
# Simulate variable set from command line by using "override"
override KWBASE_WEIRD_GURKA := paprika
KWBASE_WEIRD := ;;APA=banan;;;GURKA=apelsin;APA=skansen;;
$(eval $(call ParseKeywordVariable, KWBASE_WEIRD, \
KEYWORDS := APA GURKA SUM, \
STRING_KEYWORDS := COUNT, \
))
$(eval $(call assert-equals, \
$(KWBASE_WEIRD_APA), \
skansen, \
ParseKeywordVariable failed to overwrite APA, \
))
$(eval $(call assert-equals, \
$(KWBASE_WEIRD_GURKA), \
paprika, \
ParseKeywordVariable failed to preserve GURKA, \
))
################################################################################
all: $(TEST_TARGETS)
|