Blame testing/058_bracket_recursion.tcl

Packit Service 50c9f2
#// objective: tests processing of commands inside brackets [], only references/referencedby relations are relevant
Packit Service 50c9f2
#// check: 058__bracket__recursion_8tcl.xml
Packit Service 50c9f2
#// config: REFERENCED_BY_RELATION = yes
Packit Service 50c9f2
#// config: REFERENCES_RELATION = yes
Packit Service 50c9f2
#// config: EXTRACT_ALL = yes
Packit Service 50c9f2
#// config: INLINE_SOURCES = yes
Packit Service 50c9f2
Packit Service 50c9f2
##
Packit Service 50c9f2
# \brief should be reference by every proc below
Packit Service 50c9f2
proc Invoked args {
Packit Service 50c9f2
    puts "Procedure \"Invoked\" is invoked indeed. Ok."
Packit Service 50c9f2
    return $args
Packit Service 50c9f2
}
Packit Service 50c9f2
##
Packit Service 50c9f2
# \brief must not be reference by every proc below
Packit Service 50c9f2
proc NotInvoked args {
Packit Service 50c9f2
    puts "Procedure \"NotInvoked\" is invoked. Not Ok!"
Packit Service 50c9f2
    return $args
Packit Service 50c9f2
}
Packit Service 50c9f2
#
Packit Service 50c9f2
# check if call references work at all
Packit Service 50c9f2
proc a args {
Packit Service 50c9f2
    Invoked NotInvoked
Packit Service 50c9f2
    return
Packit Service 50c9f2
}
Packit Service 50c9f2
#
Packit Service 50c9f2
# check brackets with various quoting, bracing
Packit Service 50c9f2
proc b args {
Packit Service 50c9f2
    set r [Invoked]
Packit Service 50c9f2
    set r [list \[NotInvoked \]]
Packit Service 50c9f2
    return
Packit Service 50c9f2
}
Packit Service 50c9f2
proc c args {
Packit Service 50c9f2
    set r \{[Invoked]\}
Packit Service 50c9f2
    set r {[NotInvoked]}
Packit Service 50c9f2
    return
Packit Service 50c9f2
}
Packit Service 50c9f2
proc d args {
Packit Service 50c9f2
    set r "[Invoked]"
Packit Service 50c9f2
    set r "\[NotInvoked \]"
Packit Service 50c9f2
    return
Packit Service 50c9f2
}
Packit Service 50c9f2
proc e args {
Packit Service 50c9f2
    set r [list \[NotInvoked [Invoked]\]]
Packit Service 50c9f2
    return
Packit Service 50c9f2
}
Packit Service 50c9f2
proc f args {
Packit Service 50c9f2
    set r [list [Invoked \[NotInvoked \]]]
Packit Service 50c9f2
    return
Packit Service 50c9f2
}
Packit Service 50c9f2
proc g args {
Packit Service 50c9f2
    set r "{[Invoked]}"
Packit Service 50c9f2
    set r "{\[NotInvoked \]}"
Packit Service 50c9f2
    return
Packit Service 50c9f2
}
Packit Service 50c9f2
proc h args {
Packit Service 50c9f2
    [Invoked set] r {[NotInvoked]}
Packit Service 50c9f2
    return
Packit Service 50c9f2
}
Packit Service 50c9f2
# check brackets in tcl commands containing script arguments
Packit Service 50c9f2
#
Packit Service 50c9f2
# example generated according to
Packit Service 50c9f2
# https://groups.google.com/d/msg/comp.lang.tcl/G5-mc3GiIyY/e-AVD9t7xMkJ
Packit Service 50c9f2
proc i args {
Packit Service 50c9f2
    foreach item [Invoked] {
Packit Service 50c9f2
    return
Packit Service 50c9f2
    }
Packit Service 50c9f2
}
Packit Service 50c9f2
proc j args {
Packit Service 50c9f2
    foreach [Invoked item] [list one two three] {
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return
Packit Service 50c9f2
}
Packit Service 50c9f2
proc k args {
Packit Service 50c9f2
    while {[Invoked 0]} {
Packit Service 50c9f2
    }
Packit Service 50c9f2
}
Packit Service 50c9f2
proc l args {
Packit Service 50c9f2
    for {} {[Invoked 0]} {} {
Packit Service 50c9f2
    }
Packit Service 50c9f2
}
Packit Service 50c9f2
proc m args {
Packit Service 50c9f2
    if {[Invoked 1]} {
Packit Service 50c9f2
    }
Packit Service 50c9f2
}
Packit Service 50c9f2
proc n args {
Packit Service 50c9f2
    if [Invoked 1] {
Packit Service 50c9f2
    }
Packit Service 50c9f2
}
Packit Service 50c9f2
proc o args {
Packit Service 50c9f2
    if {0} {
Packit Service 50c9f2
    } elseif {[Invoked 0]} {
Packit Service 50c9f2
    }
Packit Service 50c9f2
}
Packit Service 50c9f2
# these are really nasty examples
Packit Service 50c9f2
# they shows, that the condition argument may not be parsed as a script
Packit Service 50c9f2
set NotInvoked \$NotInvoked
Packit Service 50c9f2
proc $NotInvoked args {
Packit Service 50c9f2
    puts "Procedure \"\$NotInvoked\" is invoked. Not Ok!"
Packit Service 50c9f2
    return $args
Packit Service 50c9f2
}
Packit Service 50c9f2
proc p args {
Packit Service 50c9f2
    set NotInvoked \$NotInvoked
Packit Service 50c9f2
    if {$NotInvoked eq [Invoked 1]} {
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return
Packit Service 50c9f2
}
Packit Service 50c9f2
proc q args {
Packit Service 50c9f2
    set NotInvoked \$NotInvoked
Packit Service 50c9f2
    if {0} {
Packit Service 50c9f2
    } elseif {$NotInvoked eq [Invoked 1]} {
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return
Packit Service 50c9f2
}
Packit Service 50c9f2
proc r args {
Packit Service 50c9f2
    set NotInvoked \$NotInvoked
Packit Service 50c9f2
    while {$NotInvoked eq [Invoked 1]} {
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return
Packit Service 50c9f2
}
Packit Service 50c9f2
proc s args {
Packit Service 50c9f2
    set NotInvoked \$NotInvoked
Packit Service 50c9f2
    for {} {$NotInvoked eq [Invoked 1]} {} {
Packit Service 50c9f2
    }
Packit Service 50c9f2
    return
Packit Service 50c9f2
}
Packit Service 50c9f2
# dangling open brackets should not confuse the scanner
Packit Service 50c9f2
proc t args {
Packit Service 50c9f2
    set foo ]]]][Invoked]
Packit Service 50c9f2
    return
Packit Service 50c9f2
}
Packit Service 50c9f2
# Example according to
Packit Service 50c9f2
# https://bugzilla.gnome.org/show_bug.cgi?id=729135
Packit Service 50c9f2
#                                       |
Packit Service 50c9f2
# Note the subtle difference in this    | whitespace
Packit Service 50c9f2
#                                       V
Packit Service 50c9f2
proc y {} {
Packit Service 50c9f2
    set classifier_state {{bphy} }
Packit Service 50c9f2
    if { ($classifier_state == {{bphy} }) } {
Packit Service 50c9f2
        Invoked
Packit Service 50c9f2
    }
Packit Service 50c9f2
}
Packit Service 50c9f2
proc z {} {
Packit Service 50c9f2
    set classifier_state {{bphy} }
Packit Service 50c9f2
    if { ($classifier_state == {{bphy} } ) } {
Packit Service 50c9f2
        Invoked
Packit Service 50c9f2
    }
Packit Service 50c9f2
}
Packit Service 50c9f2
#
Packit Service 50c9f2
# call all single letter procs
Packit Service 50c9f2
# let tcl check what is called and what is not called
Packit Service 50c9f2
foreach p [info procs ?] {
Packit Service 50c9f2
    puts "Check procedure \"$p\""
Packit Service 50c9f2
    $p
Packit Service 50c9f2
}
Packit Service 50c9f2
exit
Packit Service 50c9f2