1import lit.formats 2 3config.name = "shtest-define" 4config.suffixes = [".txt"] 5# Use lit's internal shell to avoid shell portability issues within RUN lines 6# (e.g., for 'echo' commands in Windows). Those issues should be orthogonal to 7# the substitution behavior we are trying to test. 8config.test_format = lit.formats.ShTest(execute_external=False) 9config.test_source_root = None 10config.test_exec_root = None 11 12# When config.recursiveExpansionLimit is not specified, it's important to 13# prepend substitutions before substitutions they might now or later (upon a 14# redefinition) depend upon. For example, %{global:greeting} and %{global:what} 15# act as parameters for %{global:echo}, so we make sure the latter expands 16# before the former. Moreover, some tests redefine %{global:greeting} in terms 17# of %{global:what}, so we make sure the former expands before the latter. 18# If we always insert at the beginning of the substitution list (as DEFINE 19# does), then the rule is simple: define a substitution before you refer to it. 20config.substitutions.insert(0, ("%{global:what}", "World")) 21config.substitutions.insert(0, ("%{global:greeting}", "")) 22config.substitutions.insert( 23 0, ("%{global:echo}", "echo GLOBAL: %{global:greeting} %{global:what}") 24) 25 26# This substitution includes an re.sub replacement string escape sequence, 27# which lit should treat as plain text. 28config.substitutions.insert(0, ("%{global:subst-with-escapes}", r"value-with-\g")) 29 30# The following substitution definitions are confusing and should be avoided. 31# We define them here so we can test that 'DEFINE:' and 'REDEFINE:' directives 32# guard against the confusion they cause. 33 34# Even though each of '%{global:inside}', '%{global:prefix}', and 35# '%{global:suffix}' is not already the exact pattern of a substitution, 36# 'DEFINE:' and 'REDEFINE:' will refuse to (re)define a substitution with that 37# pattern because it is a substring of one of the following substitution's 38# patterns. 39config.substitutions.insert(0, ("<%{global:inside}>", "<@>")) 40config.substitutions.insert(0, (r"%{global:prefix}\((.*)\)", r"@(\g<1>)")) 41config.substitutions.insert(0, ("@%{global:suffix}", "@@")) 42 43# These cannot be redefined by 'REDEFINE:', which doesn't know which one to 44# redefine. 45config.substitutions.insert(0, ("%{global:multiple-exact}", "first")) 46config.substitutions.insert(0, ("%{global:multiple-exact}", "second")) 47 48# Even though '%{global:multiple-once-exact}' is the exact pattern of only one 49# existing substitution, 'REDEFINE:' will refuse to redefine that substitution 50# because that string is a substring of another substitution's pattern. 51config.substitutions.insert(0, ("%{global:multiple-once-exact}", "@")) 52config.substitutions.insert(0, ("<%{global:multiple-once-exact}>", "<@>")) 53 54recur = lit_config.params.get("recur", None) 55if recur: 56 config.recursiveExpansionLimit = int(recur) 57