mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
test suite updates and additions for new capture semantics & suppression of error cascades
This commit is contained in:
parent
80f7d36582
commit
fd309676bd
13 changed files with 47 additions and 39 deletions
|
@ -2,26 +2,26 @@
|
||||||
hello :-)
|
hello :-)
|
||||||
peer added
|
peer added
|
||||||
receiver got ping: function 2
|
receiver got ping: function 2
|
||||||
inside: 1 | outside: 11 | global: 100
|
inside: 1 | outside: 12 | global: 100
|
||||||
77
|
77
|
||||||
receiver got ping: function 1
|
receiver got ping: function 1
|
||||||
begin: 100 | base_step: 2
|
begin: 100 | base_step: 2
|
||||||
begin: 100 | base_step: 2 | step: 76
|
begin: 100 | base_step: 2 | step: 76
|
||||||
178
|
178
|
||||||
receiver got ping: function 2
|
receiver got ping: function 2
|
||||||
inside: 3 | outside: 11 | global: 100
|
inside: 3 | outside: 12 | global: 100
|
||||||
79
|
79
|
||||||
receiver got ping: function 1
|
receiver got ping: function 1
|
||||||
begin: 100 | base_step: 4
|
begin: 100 | base_step: 4
|
||||||
begin: 100 | base_step: 4 | step: 76
|
begin: 100 | base_step: 4 | step: 76
|
||||||
180
|
180
|
||||||
receiver got ping: function 2
|
receiver got ping: function 2
|
||||||
inside: 5 | outside: 11 | global: 100
|
inside: 5 | outside: 12 | global: 100
|
||||||
81
|
81
|
||||||
receiver got ping: function 1
|
receiver got ping: function 1
|
||||||
begin: 100 | base_step: 6
|
begin: 100 | base_step: 6
|
||||||
begin: 100 | base_step: 6 | step: 76
|
begin: 100 | base_step: 6 | step: 76
|
||||||
182
|
182
|
||||||
receiver got ping: function 2
|
receiver got ping: function 2
|
||||||
inside: 7 | outside: 11 | global: 100
|
inside: 7 | outside: 12 | global: 100
|
||||||
83
|
83
|
||||||
|
|
|
@ -3,7 +3,7 @@ hello :)
|
||||||
peer added
|
peer added
|
||||||
begin: 100 | base_step: 50
|
begin: 100 | base_step: 50
|
||||||
sender got pong: function 2
|
sender got pong: function 2
|
||||||
inside: 1 | outside: 11 | global: 10
|
inside: 1 | outside: 12 | global: 10
|
||||||
77
|
77
|
||||||
begin: 100 | base_step: 50
|
begin: 100 | base_step: 50
|
||||||
sender got pong: function 1
|
sender got pong: function 1
|
||||||
|
@ -12,7 +12,7 @@ begin: 178 | base_step: 2 | step: 76
|
||||||
256
|
256
|
||||||
begin: 100 | base_step: 50
|
begin: 100 | base_step: 50
|
||||||
sender got pong: function 2
|
sender got pong: function 2
|
||||||
inside: 3 | outside: 11 | global: 10
|
inside: 3 | outside: 12 | global: 10
|
||||||
79
|
79
|
||||||
begin: 100 | base_step: 50
|
begin: 100 | base_step: 50
|
||||||
sender got pong: function 1
|
sender got pong: function 1
|
||||||
|
@ -21,7 +21,7 @@ begin: 180 | base_step: 4 | step: 76
|
||||||
260
|
260
|
||||||
begin: 100 | base_step: 50
|
begin: 100 | base_step: 50
|
||||||
sender got pong: function 2
|
sender got pong: function 2
|
||||||
inside: 5 | outside: 11 | global: 10
|
inside: 5 | outside: 12 | global: 10
|
||||||
81
|
81
|
||||||
begin: 100 | base_step: 50
|
begin: 100 | base_step: 50
|
||||||
sender got pong: function 1
|
sender got pong: function 1
|
||||||
|
|
|
@ -19,8 +19,8 @@ expect: 160
|
||||||
160
|
160
|
||||||
expect: 225
|
expect: 225
|
||||||
225
|
225
|
||||||
expect: 290
|
expect: 225
|
||||||
290
|
225
|
||||||
|
|
||||||
tables:
|
tables:
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
error in ./invalid.zeek, line 9: hook cannot be called directly, use hook operator (myhook)
|
error in ./invalid.zeek, line 9: hook cannot be called directly, use hook operator (myhook)
|
||||||
warning in ./invalid.zeek, line 9: expression value ignored (myhook(3))
|
|
||||||
error in ./invalid.zeek, line 10: hook cannot be called directly, use hook operator (myhook)
|
error in ./invalid.zeek, line 10: hook cannot be called directly, use hook operator (myhook)
|
||||||
error in ./invalid.zeek, line 11: hook cannot be called directly, use hook operator (myhook)
|
error in ./invalid.zeek, line 11: hook cannot be called directly, use hook operator (myhook)
|
||||||
error in ./invalid.zeek, line 12: not a valid hook call expression (2 + 2)
|
error in ./invalid.zeek, line 12: not a valid hook call expression (2 + 2)
|
||||||
warning in ./invalid.zeek, line 12: expression value ignored (2 + 2)
|
warning in ./invalid.zeek, line 12: expression value ignored (2 + 2)
|
||||||
error in ./invalid.zeek, line 13: not a valid hook call expression (2 + 2)
|
error in ./invalid.zeek, line 13: not a valid hook call expression (2 + 2)
|
||||||
error in ./invalid.zeek, line 15: hook cannot be called directly, use hook operator (h)
|
error in ./invalid.zeek, line 15: hook cannot be called directly, use hook operator (h)
|
||||||
warning in ./invalid.zeek, line 15: expression value ignored (h(3))
|
|
||||||
error in ./invalid.zeek, line 16: hook cannot be called directly, use hook operator (h)
|
error in ./invalid.zeek, line 16: hook cannot be called directly, use hook operator (h)
|
||||||
|
|
|
@ -33,7 +33,7 @@ function send_event()
|
||||||
local log : myfunctype = function(c: count) : function(d: count) : count
|
local log : myfunctype = function(c: count) : function(d: count) : count
|
||||||
{
|
{
|
||||||
# print fmt("inside: %s | outside: %s | global: %s", c, event_count, global_with_same_name);
|
# print fmt("inside: %s | outside: %s | global: %s", c, event_count, global_with_same_name);
|
||||||
return function(d: count) : count { return d + c; };
|
return function[c](d: count) : count { return d + c; };
|
||||||
};
|
};
|
||||||
|
|
||||||
local e2 = Broker::make_event(ping, "function 1", log);
|
local e2 = Broker::make_event(ping, "function 1", log);
|
||||||
|
@ -85,7 +85,7 @@ function my_funcs()
|
||||||
local l : myfunctype = function(c: count) : function(d: count) : count
|
local l : myfunctype = function(c: count) : function(d: count) : count
|
||||||
{
|
{
|
||||||
print fmt("dogs");
|
print fmt("dogs");
|
||||||
return function(d: count) : count { return d + c; };
|
return function[c](d: count) : count { return d + c; };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ function send_event()
|
||||||
local stepper = l(50);
|
local stepper = l(50);
|
||||||
|
|
||||||
++n;
|
++n;
|
||||||
|
++event_count;
|
||||||
if ( n % 2 == 0)
|
if ( n % 2 == 0)
|
||||||
{
|
{
|
||||||
local e2 = Broker::make_event(ping, "function 1", l);
|
local e2 = Broker::make_event(ping, "function 1", l);
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
|
|
||||||
global numberone : count = 1;
|
global numberone : count = 1;
|
||||||
|
|
||||||
|
type mutable_aggregate: record { x: count; };
|
||||||
|
|
||||||
function make_count_upper (start : count) : function(step : count) : count
|
function make_count_upper (start : count) : function(step : count) : count
|
||||||
{
|
{
|
||||||
return function(step : count) : count
|
return function[start](step : count) : count
|
||||||
{ return (start += (step + numberone)); };
|
{ return (start += (step + numberone)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +16,7 @@ function dog_maker(name: string, weight: count) : function (action: string)
|
||||||
local eat = function (lbs: count) { print fmt("eat i weigh %s", lbs); };
|
local eat = function (lbs: count) { print fmt("eat i weigh %s", lbs); };
|
||||||
local bark = function (who: string) { print fmt("bark i am %s", who); };
|
local bark = function (who: string) { print fmt("bark i am %s", who); };
|
||||||
|
|
||||||
local dog = function (action: string)
|
local dog = function [eat, bark, name, weight](action: string)
|
||||||
{
|
{
|
||||||
switch action
|
switch action
|
||||||
{
|
{
|
||||||
|
@ -72,14 +74,14 @@ event zeek_init()
|
||||||
print c(1) == two(3);
|
print c(1) == two(3);
|
||||||
|
|
||||||
# a little more complicated ...
|
# a little more complicated ...
|
||||||
local cat_dog = 100;
|
local cat_dog = mutable_aggregate($x=100);
|
||||||
local add_n_and_m = function(n: count) : function(m : count) : function(o : count) : count
|
local add_n_and_m = function[cat_dog](n: count) : function(m : count) : function(o : count) : count
|
||||||
{
|
{
|
||||||
cat_dog += 1;
|
cat_dog$x += 1;
|
||||||
local can_we_make_variables_inside = 11;
|
local can_we_make_variables_inside = 11;
|
||||||
return function(m : count) : function(o : count) : count
|
return function[can_we_make_variables_inside, cat_dog, n](m : count) : function(o : count) : count
|
||||||
{ return function(o : count) : count
|
{ return function[cat_dog, can_we_make_variables_inside, m, n](o : count) : count
|
||||||
{ return n + m + o + cat_dog + can_we_make_variables_inside; }; };
|
{ return n + m + o + cat_dog$x + can_we_make_variables_inside; }; };
|
||||||
};
|
};
|
||||||
|
|
||||||
local add_m = add_n_and_m(2);
|
local add_m = add_n_and_m(2);
|
||||||
|
@ -95,14 +97,14 @@ event zeek_init()
|
||||||
|
|
||||||
# can mutate closure:
|
# can mutate closure:
|
||||||
print "expect: 101";
|
print "expect: 101";
|
||||||
print cat_dog;
|
print cat_dog$x;
|
||||||
|
|
||||||
# complicated - has state across calls
|
# complicated - has state across calls
|
||||||
local two_part_adder_maker = function (begin : count) : function (base_step : count) : function ( step : count) : count
|
local two_part_adder_maker = function (begin : count) : function (base_step : count) : function ( step : count) : count
|
||||||
{
|
{
|
||||||
return function (base_step : count) : function (step : count) : count
|
return function [begin](base_step : count) : function (step : count) : count
|
||||||
{
|
{
|
||||||
return function (step : count) : count
|
return function [base_step, begin](step : count) : count
|
||||||
{
|
{
|
||||||
return (begin += base_step + step); }; }; };
|
return (begin += base_step + step); }; }; };
|
||||||
|
|
||||||
|
@ -115,10 +117,17 @@ event zeek_init()
|
||||||
print stepper(15);
|
print stepper(15);
|
||||||
|
|
||||||
# another copy check
|
# another copy check
|
||||||
print "expect: 290";
|
#
|
||||||
|
# under old reference capture semantics, this would print 290 because
|
||||||
|
# the twotwofive copy wouldn't have a copy of the "begin" variable but
|
||||||
|
# instead a reference to it; under copy capture semantics, though,
|
||||||
|
# those are separate values, so executing stepper() after the copy
|
||||||
|
# won't affect the copy
|
||||||
|
#
|
||||||
|
print "expect: 225";
|
||||||
print twotwofive(15);
|
print twotwofive(15);
|
||||||
|
|
||||||
local hamster : count = 3;
|
local hamster = mutable_aggregate($x=3);
|
||||||
|
|
||||||
print "";
|
print "";
|
||||||
print "tables:";
|
print "tables:";
|
||||||
|
@ -128,10 +137,10 @@ event zeek_init()
|
||||||
[1] = "symmetric active",
|
[1] = "symmetric active",
|
||||||
[2] = "symmetric passive",
|
[2] = "symmetric passive",
|
||||||
[3] = "client",
|
[3] = "client",
|
||||||
} &default = function(i: count):string { return fmt("unknown-%d. outside-%d", i, hamster += 1); } &redef;
|
} &default = function[hamster](i: count):string { return fmt("unknown-%d. outside-%d", i, hamster$x += 1); } &redef;
|
||||||
|
|
||||||
# changing the value here will show in the function.
|
# changing the value here will show in the function.
|
||||||
hamster += hamster;
|
hamster$x += hamster$x;
|
||||||
|
|
||||||
print "expect: unknown-11. outside-7";
|
print "expect: unknown-11. outside-7";
|
||||||
print modes[11];
|
print modes[11];
|
||||||
|
@ -156,7 +165,7 @@ event zeek_init()
|
||||||
[1] = "symmetric active",
|
[1] = "symmetric active",
|
||||||
[2] = "symmetric passive",
|
[2] = "symmetric passive",
|
||||||
[3] = "client"
|
[3] = "client"
|
||||||
)&default = function(i: count):string { return fmt("unknown-%d. outside-%d", i, hamster_also += 1); } &redef;
|
)&default = function[hamster_also](i: count):string { return fmt("unknown-%d. outside-%d", i, hamster_also += 1); } &redef;
|
||||||
|
|
||||||
print "expect: unknown-11. outside-4";
|
print "expect: unknown-11. outside-4";
|
||||||
print modes_also[11];
|
print modes_also[11];
|
||||||
|
|
|
@ -13,7 +13,7 @@ event zeek_init() &priority=+10
|
||||||
{
|
{
|
||||||
local outer = 101;
|
local outer = 101;
|
||||||
|
|
||||||
local lambda = function()
|
local lambda = function[outer]()
|
||||||
{ print outer; };
|
{ print outer; };
|
||||||
|
|
||||||
lambda();
|
lambda();
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
local outer = 100;
|
local outer = 100;
|
||||||
|
|
||||||
local lambda = function()
|
local lambda = function[outer]()
|
||||||
{
|
{
|
||||||
local inner = function(a: count, b: count, c: count, d: count, e: count, f: count)
|
local inner = function[outer](a: count, b: count, c: count, d: count, e: count, f: count)
|
||||||
{
|
{
|
||||||
print outer + f;
|
print outer + f;
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,6 @@ type myrec: record {
|
||||||
event zeek_init()
|
event zeek_init()
|
||||||
{
|
{
|
||||||
local w = "world";
|
local w = "world";
|
||||||
local mr = myrec($foo(a: string) = { print a + w; });
|
local mr = myrec($foo[w](a: string) = { print a + w; });
|
||||||
mr$foo("hello");
|
mr$foo("hello");
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ event zeek_init() &priority=+10
|
||||||
{
|
{
|
||||||
local outer = 101;
|
local outer = 101;
|
||||||
|
|
||||||
local lambda = function()
|
local lambda = function[outer]()
|
||||||
{ print outer + 2; };
|
{ print outer + 2; };
|
||||||
|
|
||||||
lambda();
|
lambda();
|
||||||
|
|
|
@ -17,7 +17,7 @@ function map_1 (f: function(a: count): count, v: vector of count) : vector of co
|
||||||
# stacks two functions
|
# stacks two functions
|
||||||
function stacker (one : function(a: count): count, two: function (b: count): count): function(c: count): count
|
function stacker (one : function(a: count): count, two: function (b: count): count): function(c: count): count
|
||||||
{
|
{
|
||||||
return function (c: count): count
|
return function [one,two](c: count): count
|
||||||
{
|
{
|
||||||
return one(two(c));
|
return one(two(c));
|
||||||
};
|
};
|
||||||
|
@ -25,7 +25,7 @@ function stacker (one : function(a: count): count, two: function (b: count): cou
|
||||||
|
|
||||||
function make_dog(name: string, weight: count) : function(i: string, item: string)
|
function make_dog(name: string, weight: count) : function(i: string, item: string)
|
||||||
{
|
{
|
||||||
return function(i: string, item: string)
|
return function[name, weight](i: string, item: string)
|
||||||
{
|
{
|
||||||
switch i
|
switch i
|
||||||
{
|
{
|
||||||
|
@ -69,7 +69,7 @@ event zeek_init()
|
||||||
|
|
||||||
local make_laster = function(start: count) : function(i: count): count
|
local make_laster = function(start: count) : function(i: count): count
|
||||||
{
|
{
|
||||||
return function(i: count): count
|
return function[start](i: count): count
|
||||||
{
|
{
|
||||||
local temp = i;
|
local temp = i;
|
||||||
i += start;
|
i += start;
|
||||||
|
@ -111,7 +111,7 @@ event zeek_init()
|
||||||
local vs = vector("dog", "cat", "fish");
|
local vs = vector("dog", "cat", "fish");
|
||||||
for (i in vs)
|
for (i in vs)
|
||||||
{
|
{
|
||||||
mfs += function() { print i, vs[i]; };
|
mfs += function[i, vs]() { print i, vs[i]; };
|
||||||
}
|
}
|
||||||
for ( i in mfs)
|
for ( i in mfs)
|
||||||
mfs[i]();
|
mfs[i]();
|
||||||
|
|
|
@ -9,7 +9,7 @@ function bar(b: string, c: string)
|
||||||
{
|
{
|
||||||
local f: Foo;
|
local f: Foo;
|
||||||
local d = 8;
|
local d = 8;
|
||||||
f = [$x=function(a: string) : string
|
f = [$x=function[b, c, d](a: string) : string
|
||||||
{
|
{
|
||||||
local x = 0;
|
local x = 0;
|
||||||
# Fail here: we've captured the closure.
|
# Fail here: we've captured the closure.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue