;--------------------------------------------------
; Create the check file, good input, and bad input.
;
; For both good and bad input, make sure the -v trace has at least one remark
; so we can check how trace suppression is affected by -dump-input.
;--------------------------------------------------

; RUN: echo hello > %t.good
; RUN: echo world >> %t.good

; RUN: echo hello > %t.err
; RUN: echo whirled >> %t.err

; RUN: echo 'CHECK: hello' > %t.check
; RUN: echo 'CHECK-NEXT: world' >> %t.check

;--------------------------------------------------
; Check -dump-input=<bad value>.
;--------------------------------------------------

; RUN: not FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
; RUN:               -match-full-lines -dump-input=foobar 2>&1 \
; RUN: | FileCheck %s -match-full-lines -check-prefix=BADVAL

; No positional arg.
; RUN: not FileCheck -dump-input=foobar 2>&1 \
; RUN: | FileCheck %s -match-full-lines -check-prefix=BADVAL

BADVAL: {{F|f}}ile{{C|c}}heck{{.*}}: for the --dump-input option: Cannot find option named 'foobar'!

;--------------------------------------------------
; Check -dump-input=help.
;--------------------------------------------------

; Appended to normal command line.
; RUN: FileCheck -input-file %t.err -color %t.check -dump-input=help \
; RUN: | FileCheck %s -check-prefix=HELP

; No positional arg.
; RUN: FileCheck -dump-input=help | FileCheck %s -check-prefix=HELP

HELP-NOT: {{.}}
HELP: The following description was requested by -dump-input=help
HELP: try{{.*}}-color
HELP-NOT: {{.}}

;--------------------------------------------------
; Check -dump-input=never.
;
; Include the case without -v, which isn't covered elsewhere.
;--------------------------------------------------

; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
; RUN:           -match-full-lines -dump-input=never 2>&1 \
; RUN: | FileCheck %s -match-full-lines -allow-empty \
; RUN:             -check-prefixes=NOTRACE,NODUMP

; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
; RUN:               -match-full-lines -dump-input=never 2>&1 \
; RUN: | FileCheck %s -match-full-lines -check-prefixes=NOTRACE,ERR,NODUMP

; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
; RUN:           -match-full-lines -dump-input=never -v 2>&1 \
; RUN: | FileCheck %s -match-full-lines -check-prefixes=TRACE,NODUMP

; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
; RUN:               -match-full-lines -dump-input=never -v 2>&1 \
; RUN: | FileCheck %s -match-full-lines -check-prefixes=TRACE,ERR,NODUMP

;--------------------------------------------------
; Check no -dump-input, which defaults to never.
;--------------------------------------------------

; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
; RUN:           -match-full-lines -v 2>&1 \
; RUN: | FileCheck %s -match-full-lines -check-prefixes=TRACE,NODUMP

; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
; RUN:               -match-full-lines -v 2>&1 \
; RUN: | FileCheck %s -match-full-lines -check-prefixes=TRACE,ERR,NODUMP

;--------------------------------------------------
; Check -dump-input=fail.
;
; Include the case without -v, which isn't covered elsewhere.
;--------------------------------------------------

; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
; RUN:           -match-full-lines -dump-input=fail 2>&1 \
; RUN: | FileCheck %s -match-full-lines -allow-empty \
; RUN:             -check-prefixes=NOTRACE,NODUMP

; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
; RUN:               -match-full-lines -dump-input=fail 2>&1 \
; RUN: | FileCheck %s -match-full-lines -check-prefixes=NOTRACE,ERR,DUMP-ERR

; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
; RUN:           -match-full-lines -dump-input=fail -v 2>&1 \
; RUN: | FileCheck %s -match-full-lines -allow-empty \
; RUN:             -check-prefixes=NOTRACE,NODUMP

; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
; RUN:               -match-full-lines -dump-input=fail -v 2>&1 \
; RUN: | FileCheck %s -match-full-lines \
; RUN:                -check-prefixes=NOTRACE,ERR,DUMP-ERR,DUMP-ERR-V

;--------------------------------------------------
; Check -dump-input-on-failure.
;--------------------------------------------------

; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
; RUN:           -match-full-lines -dump-input-on-failure -v 2>&1 \
; RUN: | FileCheck %s -match-full-lines -allow-empty \
; RUN:             -check-prefixes=NOTRACE,NODUMP

; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
; RUN:               -match-full-lines -dump-input-on-failure -v 2>&1 \
; RUN: | FileCheck %s -match-full-lines \
; RUN:                -check-prefixes=NOTRACE,ERR,DUMP-ERR,DUMP-ERR-V

; RUN: env FILECHECK_DUMP_INPUT_ON_FAILURE=1 \
; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
; RUN:           -match-full-lines -v 2>&1 \
; RUN: | FileCheck %s -match-full-lines -allow-empty \
; RUN:             -check-prefixes=NOTRACE,NODUMP

; RUN: env FILECHECK_DUMP_INPUT_ON_FAILURE=1 \
; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
; RUN:               -match-full-lines -v 2>&1 \
; RUN: | FileCheck %s -match-full-lines \
; RUN:                -check-prefixes=NOTRACE,ERR,DUMP-ERR,DUMP-ERR-V

;--------------------------------------------------
; Check -dump-input=always.
;--------------------------------------------------

; RUN: FileCheck -input-file %t.good %t.check -check-prefix=CHECK \
; RUN:           -match-full-lines -dump-input=always -v 2>&1 \
; RUN: | FileCheck %s -match-full-lines -check-prefixes=NOTRACE,DUMP-OK

; RUN: not FileCheck -input-file %t.err %t.check -check-prefix=CHECK \
; RUN:               -match-full-lines -dump-input=always -v 2>&1 \
; RUN: | FileCheck %s -match-full-lines \
; RUN:                -check-prefixes=NOTRACE,ERR,DUMP-ERR,DUMP-ERR-V

; END.

;--------------------------------------------------
; Check the output for all cases that actually process directives.
;--------------------------------------------------

; Trace is sometimes suppressed.
; TRACE:       {{.*}}remark:{{.*}}
; NOTRACE-NOT: remark:

; Error diagnostics are never suppressed.
; ERR: {{.*}}error:{{.*}}

; NODUMP-NOT: <<<<<<

; DUMP-OK:      Full input was:
; DUMP-OK-NEXT: <<<<<<
; DUMP-OK-NEXT:          1: hello
; DUMP-OK-NEXT: check:1     ^~~~~
; DUMP-OK-NEXT:          2: world
; DUMP-OK-NEXT: next:2      ^~~~~
; DUMP-OK-NEXT: >>>>>>

; DUMP-ERR:        Full input was:
; DUMP-ERR-NEXT:   <<<<<<
; DUMP-ERR-NEXT:            1: hello
; DUMP-ERR-V-NEXT: check:1     ^~~~~
; DUMP-ERR-NEXT:            2: whirled
; DUMP-ERR-NEXT:   next:2      X~~~~~~ error: no match found
; DUMP-ERR-NEXT:   >>>>>>
