Home | History | Annotate | Line # | Download | only in unit-tests
opt-debug-file.mk revision 1.10.2.1
      1  1.10.2.1  perseant # $NetBSD: opt-debug-file.mk,v 1.10.2.1 2024/07/01 01:01:15 perseant 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.4    rillig # file, the content of that log file must not be stored in a variable.
     31       1.7    rillig #
     32       1.7    rillig # XXX: In the :M modifier, a dollar is escaped using '$$', not '\$'.  This
     33       1.7    rillig # escaping scheme unnecessarily differs from all other modifiers.
     34       1.4    rillig .if !${:!cat opt-debug-file.debuglog!:tW:M*VAR = value $${:Uexpanded}*}
     35       1.4    rillig .  error
     36       1.4    rillig .endif
     37       1.4    rillig 
     38       1.7    rillig .MAKEFLAGS: -d0
     39       1.7    rillig 
     40       1.7    rillig 
     41       1.7    rillig # See Parse_Error.
     42       1.7    rillig .MAKEFLAGS: -dFstdout
     43       1.9    rillig # expect+1: This goes to stderr only, once.
     44       1.7    rillig .  info This goes to stderr only, once.
     45       1.7    rillig .MAKEFLAGS: -dFstderr
     46       1.9    rillig # expect+1: This goes to stderr only, once.
     47       1.7    rillig .  info This goes to stderr only, once.
     48       1.7    rillig .MAKEFLAGS: -dFopt-debug-file.debuglog
     49       1.9    rillig # expect+1: This goes to stderr, and in addition to the debug log.
     50       1.7    rillig .  info This goes to stderr, and in addition to the debug log.
     51       1.7    rillig .MAKEFLAGS: -dFstderr -d0c
     52       1.7    rillig .if ${:!cat opt-debug-file.debuglog!:Maddition:[#]} != 1
     53       1.7    rillig .  error
     54       1.7    rillig .endif
     55       1.7    rillig 
     56       1.7    rillig 
     57  1.10.2.1  perseant # See Main_ParseArgLine, which calls Error.
     58       1.7    rillig .MAKEFLAGS: -dFstdout
     59  1.10.2.1  perseant # expect: make: Unterminated quoted string [make 'This goes to stdout only, once.]
     60  1.10.2.1  perseant .MAKEFLAGS: 'This goes to stdout only, once.
     61       1.7    rillig .MAKEFLAGS: -dFstderr
     62  1.10.2.1  perseant # expect: make: Unterminated quoted string [make 'This goes to stderr only, once.]
     63  1.10.2.1  perseant .MAKEFLAGS: 'This goes to stderr only, once.
     64       1.7    rillig .MAKEFLAGS: -dFopt-debug-file.debuglog
     65  1.10.2.1  perseant # expect: make: Unterminated quoted string [make 'This goes to stderr, and in addition to the debug log.]
     66  1.10.2.1  perseant .MAKEFLAGS: 'This goes to stderr, and in addition to the debug log.
     67       1.7    rillig .MAKEFLAGS: -dFstderr -d0c
     68  1.10.2.1  perseant .if ${:!cat opt-debug-file.debuglog!:MUnterminated:[#]} != 1
     69       1.7    rillig .  error
     70       1.7    rillig .endif
     71       1.7    rillig 
     72       1.5    rillig 
     73       1.6    rillig # If the debug log file cannot be opened, make prints an error message and
     74       1.6    rillig # exits immediately since the debug log file is usually selected from the
     75       1.6    rillig # command line.
     76       1.8    rillig _:=	${:!rm opt-debug-file.debuglog!}
     77       1.8    rillig .MAKEFLAGS: -dF/nonexistent-6f21c672-a22d-4ef7/opt-debug-file.debuglog
     78