zeek/testing/btest/core/command-line-option-redefs.zeek
Jon Siwek 8c90ef4459 Fix several issues with command-line option redefs
* Variables of `string` type can now be set to an empty string

* Trying to set a variable with non-`string` type to an empty value
  now emits an error instead of silently doing nothing

* Providing an invalid identifier now emits an "unknown identifier"
  error instead of silently doing nothing
2020-06-18 20:07:47 -07:00

27 lines
739 B
Text

# @TEST-EXEC: zeek -b %INPUT mynum=0 mytable='{["one"] = "1"}' mystr="" MyMod::str="Good" >1.out
# @TEST-EXEC: zeek -b %INPUT mynum=0 mytable+='{["one"] = "1"}' >2.out
# @TEST-EXEC-FAIL: zeek -b %INPUT no_such_var=13 >3.out 2>&1
# @TEST-EXEC-FAIL: zeek -b %INPUT mynum="" mytable="" >4.out 2>&1
# @TEST-EXEC: btest-diff 1.out
# @TEST-EXEC: btest-diff 2.out
# @TEST-EXEC: btest-diff 3.out
# @TEST-EXEC: btest-diff 4.out
const mynum: count &redef;
const mytable: table[string] of string = {["zero"] = "0"} &redef;
option mystr="default";
module MyMod;
export { option str="def"; }
module GLOBAL;
event zeek_init()
{
print "mystr", mystr;
print "mynum", mynum;
print "mytable", to_json(mytable);
print "MyMod::str", MyMod::str;
}