aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/unit-tests/varmod-mtime.mk
blob: 189bb8cadc9a9d490190ac0c622bbfb21748ecea (plain) (blame)
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
# $NetBSD: varmod-mtime.mk,v 1.10 2024/04/20 10:18:55 rillig Exp $
#
# Tests for the ':mtime' variable modifier, which maps each word of the
# expression to that file's modification time.

# Note: strftime() uses mktime() for %s and mktime() assumes localtime
# so this should match time()
start:=	${%s:L:localtime}	# see varmod-gmtime.mk, keyword '%s'


# Ensure that this makefile exists and has a modification time.  If the file
# didn't exist, the ':mtime' modifier would return the current time.
.if ${MAKEFILE:mtime} >= ${start}
.  error
.endif


# For a file that doesn't exist, the ':mtime' modifier returns the current
# time, without an error or warning message.  The returned timestamp differs
# from the 'now' that is used when updating the timestamps in archives or for
# touching files using the '-t' option, which is taken once when make is
# started.
not_found_mtime:=	${no/such/file:L:mtime}
.if ${not_found_mtime} < ${start}
.  error
.endif


# The ':mtime' modifier accepts a timestamp in seconds as an optional
# argument.  This timestamp is used as a fallback in case the file's time
# cannot be determined, without any error or warning message.
.if ${no/such/file:L:mtime=0} != "0"
.  error
.endif


# The fallback timestamp must start with a digit, and it is interpreted as a
# decimal integer.
.if ${no/such/file:L:mtime=00042} != "42"
.  error
.endif


# The fallback timestamp must only be an integer, without trailing characters.
# expect+2: while evaluating variable "no/such/file": Invalid argument '123x' for modifier ':mtime'
# expect+1: Malformed conditional (${no/such/file:L:mtime=123x})
.if ${no/such/file:L:mtime=123x}
.  error
.else
.  error
.endif


# The timestamp of a newly created file must be at least as great as the
# timestamp when parsing of this makefile started.
COOKIE=	${TMPDIR:U/tmp}/varmod-mtime.cookie
_!=	touch ${COOKIE}
.if ${COOKIE:mtime=0} < ${start}
.   error ${COOKIE:mtime=0} < ${start}
.endif
_!=	rm -f ${COOKIE}


# If the optional argument of the ':mtime' modifier is the word 'error', the
# modifier fails with an error message, once for each affected file.
#
# expect+3: while evaluating variable "no/such/file1 no/such/file2": Cannot determine mtime for 'no/such/file1': <ENOENT>
# expect+2: while evaluating variable "no/such/file1 no/such/file2": Cannot determine mtime for 'no/such/file2': <ENOENT>
# expect+1: Malformed conditional (${no/such/file1 no/such/file2:L:mtime=error})
.if ${no/such/file1 no/such/file2:L:mtime=error}
.  error
.else
.  error
.endif


# Only the word 'error' is a special argument to the ':mtime' modifier, all
# other words result in a parse error.
# expect+2: while evaluating variable "MAKEFILE": Invalid argument 'errorhandler-no' for modifier ':mtime'
# expect+1: Malformed conditional (${MAKEFILE:mtime=errorhandler-no} > 0)
.if ${MAKEFILE:mtime=errorhandler-no} > 0
.else
.  error
.endif


# Only the word 'error' can be used as a fallback argument to the modifier.
# expect+2: while evaluating variable "MAKEFILE": Invalid argument 'warn' for modifier ':mtime'
# expect+1: Malformed conditional (${MAKEFILE:mtime=warn} > 0)
.if ${MAKEFILE:mtime=warn} > 0
.  error
.else
.  error
.endif


# Ensure that the fallback for a missing modification time is indeed the
# current time, and not any later time.
end:=	${%s:L:gmtime}
.if ${not_found_mtime} > ${end}
.  error
.endif


# If the expression is irrelevant, the ':mtime' modifier is only parsed, it
# does not perform any filesystem operations.
.if 0 && ${no/such/file:L:mtime=error}
.  error
.endif


# If there is a typo in the modifier name, it does not match.
# expect+2: while evaluating variable "anything": Unknown modifier "mtim"
# expect+1: Malformed conditional (${anything:L:mtim})
.if ${anything:L:mtim}
.  error
.else
.  error
.endif


# An empty word list results in an empty mtime list.
.if ${:U:mtime} != ""
.  error
.endif