Home | History | Annotate | Line # | Download | only in unit-tests
opt-debug-file.mk revision 1.12
      1  1.12  rillig # $NetBSD: opt-debug-file.mk,v 1.12 2025/07/06 08:48:34 rillig Exp $
      2   1.1  rillig #
      3   1.1  rillig # Tests for the -dF command line option, which redirects the debug log
      4   1.1  rillig # to a file instead of writing it to stderr.
      5   1.1  rillig 
      6   1.4  rillig # Enable debug logging for variable assignments and evaluation (-dv)
      7   1.4  rillig # and redirect the debug logging to the given file.
      8   1.4  rillig .MAKEFLAGS: -dvFopt-debug-file.debuglog
      9   1.4  rillig 
     10   1.4  rillig # This output goes to the debug log file.
     11   1.4  rillig VAR=	value ${:Uexpanded}
     12   1.4  rillig 
     13   1.4  rillig # Hide the logging output for the remaining actions.
     14   1.7  rillig # Before main.c 1.362 from 2020-10-03, it was not possible to disable debug
     15   1.7  rillig # logging again.  Since then, an easier way is the undocumented option '-d0'.
     16   1.4  rillig .MAKEFLAGS: -dF/dev/null
     17   1.4  rillig 
     18   1.4  rillig # Make sure that the debug logging file contains some logging.
     19   1.4  rillig DEBUG_OUTPUT:=	${:!cat opt-debug-file.debuglog!}
     20   1.4  rillig # Grmbl.  Because of the := operator in the above line, the variable
     21  1.10  rillig # value contains ${:Uexpanded}.  This expression is expanded
     22   1.7  rillig # when it is used in the condition below.  Therefore, be careful when storing
     23   1.7  rillig # untrusted input in variables.
     24   1.4  rillig #.MAKEFLAGS: -dc -dFstderr
     25   1.4  rillig .if !${DEBUG_OUTPUT:tW:M*VAR = value expanded*}
     26   1.4  rillig .  error ${DEBUG_OUTPUT}
     27   1.4  rillig .endif
     28   1.4  rillig 
     29   1.4  rillig # To get the unexpanded text that was actually written to the debug log
     30  1.12  rillig # file, the content of that log file must not be stored in a variable
     31  1.12  rillig # directly.  Instead, it can be processed in a single expression by a chain
     32  1.12  rillig # of modifiers.
     33   1.7  rillig #
     34   1.7  rillig # XXX: In the :M modifier, a dollar is escaped using '$$', not '\$'.  This
     35   1.7  rillig # escaping scheme unnecessarily differs from all other modifiers.
     36   1.4  rillig .if !${:!cat opt-debug-file.debuglog!:tW:M*VAR = value $${:Uexpanded}*}
     37   1.4  rillig .  error
     38   1.4  rillig .endif
     39   1.4  rillig 
     40  1.12  rillig # To get the unexpanded text that was actually written to the debug log
     41  1.12  rillig # file, the content of that log file must not be stored in a variable
     42  1.12  rillig # directly.  Instead, each dollar sign must be escaped first.
     43  1.12  rillig DEBUG_OUTPUT:=	${:!cat opt-debug-file.debuglog!:S,\$,\$\$,g}
     44  1.12  rillig .if ${DEBUG_OUTPUT:M*Uexpanded*} != "\${:Uexpanded}"
     45  1.12  rillig .  error
     46  1.12  rillig .endif
     47  1.12  rillig 
     48   1.7  rillig .MAKEFLAGS: -d0
     49   1.7  rillig 
     50   1.7  rillig 
     51   1.7  rillig # See Parse_Error.
     52   1.7  rillig .MAKEFLAGS: -dFstdout
     53   1.9  rillig # expect+1: This goes to stderr only, once.
     54   1.7  rillig .  info This goes to stderr only, once.
     55   1.7  rillig .MAKEFLAGS: -dFstderr
     56   1.9  rillig # expect+1: This goes to stderr only, once.
     57   1.7  rillig .  info This goes to stderr only, once.
     58   1.7  rillig .MAKEFLAGS: -dFopt-debug-file.debuglog
     59   1.9  rillig # expect+1: This goes to stderr, and in addition to the debug log.
     60   1.7  rillig .  info This goes to stderr, and in addition to the debug log.
     61   1.7  rillig .MAKEFLAGS: -dFstderr -d0c
     62   1.7  rillig .if ${:!cat opt-debug-file.debuglog!:Maddition:[#]} != 1
     63   1.7  rillig .  error
     64   1.7  rillig .endif
     65   1.7  rillig 
     66   1.7  rillig 
     67  1.11  rillig # See Main_ParseArgLine, which calls Error.
     68   1.7  rillig .MAKEFLAGS: -dFstdout
     69  1.11  rillig # expect: make: Unterminated quoted string [make 'This goes to stdout only, once.]
     70  1.11  rillig .MAKEFLAGS: 'This goes to stdout only, once.
     71   1.7  rillig .MAKEFLAGS: -dFstderr
     72  1.11  rillig # expect: make: Unterminated quoted string [make 'This goes to stderr only, once.]
     73  1.11  rillig .MAKEFLAGS: 'This goes to stderr only, once.
     74   1.7  rillig .MAKEFLAGS: -dFopt-debug-file.debuglog
     75  1.11  rillig # expect: make: Unterminated quoted string [make 'This goes to stderr, and in addition to the debug log.]
     76  1.11  rillig .MAKEFLAGS: 'This goes to stderr, and in addition to the debug log.
     77   1.7  rillig .MAKEFLAGS: -dFstderr -d0c
     78  1.11  rillig .if ${:!cat opt-debug-file.debuglog!:MUnterminated:[#]} != 1
     79   1.7  rillig .  error
     80   1.7  rillig .endif
     81   1.7  rillig 
     82   1.5  rillig 
     83   1.6  rillig # If the debug log file cannot be opened, make prints an error message and
     84   1.6  rillig # exits immediately since the debug log file is usually selected from the
     85   1.6  rillig # command line.
     86   1.8  rillig _:=	${:!rm opt-debug-file.debuglog!}
     87   1.8  rillig .MAKEFLAGS: -dF/nonexistent-6f21c672-a22d-4ef7/opt-debug-file.debuglog
     88