Home | History | Annotate | Line # | Download | only in unit-tests
directive-include.mk revision 1.8
      1 # $NetBSD: directive-include.mk,v 1.8 2021/12/14 00:38:32 rillig Exp $
      2 #
      3 # Tests for the .include directive, which includes another file.
      4 
      5 # TODO: Implementation
      6 
      7 .MAKEFLAGS: -dc
      8 
      9 # All included files are recorded in the variable .MAKE.MAKEFILES.
     10 # In this test, only the basenames of the files are compared since
     11 # the directories can differ.
     12 .include "/dev/null"
     13 .if ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null"
     14 .  error
     15 .endif
     16 
     17 # Each file is recorded only once in the variable .MAKE.MAKEFILES.
     18 # Between 2015-11-26 and 2020-10-31, the very last file could be repeated,
     19 # due to an off-by-one bug in ParseTrackInput.
     20 .include "/dev/null"
     21 .if ${.MAKE.MAKEFILES:T} != "${.PARSEFILE} null"
     22 .  error
     23 .endif
     24 
     25 .include "nonexistent.mk"
     26 .include "/dev/null"		# size 0
     27 # including a directory technically succeeds, but shouldn't.
     28 #.include "."			# directory
     29 
     30 # As of 2020-11-21, anything after the delimiter '"' is ignored.
     31 .include "/dev/null" and ignore anything in the rest of the line.
     32 
     33 # The filename to be included can contain expressions.
     34 DEV=	null
     35 .include "/dev/${DEV}"
     36 
     37 # Expressions in double quotes or angle quotes are first parsed naively, to
     38 # find the closing '"'.  In a second step, the expressions are expanded.  This
     39 # means that the expressions cannot include the characters '"' or '>'.  This
     40 # restriction is not practically relevant since the expressions inside
     41 # '.include' directives are typically kept as simple as possible.
     42 #
     43 # If the whole line were expanded before parsing, the filename to be included
     44 # would be empty, and the closing '"' would be in the trailing part of the
     45 # line, which is ignored as of 2021-12-03.
     46 DQUOT=	"
     47 .include "${DQUOT}"
     48 
     49 # When the expression in a filename cannot be evaluated, the failing
     50 # expression is skipped and the file is included nevertheless.
     51 # FIXME: Add proper error handling, no file must be included here.
     52 .include "nonexistent${:U123:Z}.mk"
     53 
     54 # The traditional include directive is seldom used.
     55 include /dev/null		# comment
     56 # expect+1: Cannot open /nonexistent
     57 include /nonexistent		# comment
     58 sinclude /nonexistent		# comment
     59 include ${:U/dev/null}		# comment
     60 include /dev/null /dev/null
     61 # expect+1: Invalid line type
     62 include
     63 # XXX: trailing whitespace in diagnostic, missing quotes around filename
     64 # expect+1: Could not find
     65 include ${:U}
     66 
     67 all:
     68