mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 12:38:20 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/const'
* origin/topic/jsiwek/const: Make const variables actually constant. Addresses #922. Closes #922.
This commit is contained in:
commit
ea6b62f586
11 changed files with 128 additions and 11 deletions
13
testing/btest/Baseline/language.const/invalid.stderr
Normal file
13
testing/btest/Baseline/language.const/invalid.stderr
Normal file
|
@ -0,0 +1,13 @@
|
|||
error in ./invalid.bro, line 15: const is not a modifiable lvalue (foo)
|
||||
error in ./invalid.bro, line 16: const is not a modifiable lvalue (foo)
|
||||
error in ./invalid.bro, line 17: const is not a modifiable lvalue (bar)
|
||||
error in ./invalid.bro, line 17: const is not a modifiable lvalue (foo)
|
||||
error in ./invalid.bro, line 18: const is not a modifiable lvalue (foo)
|
||||
error in ./invalid.bro, line 19: const is not a modifiable lvalue (foo)
|
||||
error in ./invalid.bro, line 20: const is not a modifiable lvalue (foo)
|
||||
error in ./invalid.bro, line 22: const is not a modifiable lvalue (foo)
|
||||
error in ./invalid.bro, line 25: const is not a modifiable lvalue (bar)
|
||||
error in ./invalid.bro, line 26: const is not a modifiable lvalue (baz)
|
||||
error in ./invalid.bro, line 27: const is not a modifiable lvalue (bar)
|
||||
error in ./invalid.bro, line 28: const is not a modifiable lvalue (baz)
|
||||
error in ./invalid.bro, line 33: const is not a modifiable lvalue (foo)
|
0
testing/btest/Baseline/language.const/invalid.stdout
Normal file
0
testing/btest/Baseline/language.const/invalid.stdout
Normal file
0
testing/btest/Baseline/language.const/valid.stderr
Normal file
0
testing/btest/Baseline/language.const/valid.stderr
Normal file
10
testing/btest/Baseline/language.const/valid.stdout
Normal file
10
testing/btest/Baseline/language.const/valid.stdout
Normal file
|
@ -0,0 +1,10 @@
|
|||
40
|
||||
enter f, 10
|
||||
exit f, 110
|
||||
enter f, 9
|
||||
exit f, 109
|
||||
enter f, 7
|
||||
exit f, 107
|
||||
foo, 10
|
||||
bar, 9
|
||||
baz, 7
|
79
testing/btest/language/const.bro
Normal file
79
testing/btest/language/const.bro
Normal file
|
@ -0,0 +1,79 @@
|
|||
# @TEST-EXEC: bro -b valid.bro 2>valid.stderr 1>valid.stdout
|
||||
# @TEST-EXEC: btest-diff valid.stderr
|
||||
# @TEST-EXEC: btest-diff valid.stdout
|
||||
|
||||
# @TEST-EXEC-FAIL: bro -b invalid.bro 2>invalid.stderr 1>invalid.stdout
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff invalid.stderr
|
||||
# @TEST-EXEC: btest-diff invalid.stdout
|
||||
|
||||
@TEST-START-FILE valid.bro
|
||||
# First some simple code that should be valid and error-free.
|
||||
|
||||
function f(c: count)
|
||||
{
|
||||
print "enter f", c;
|
||||
c = c + 100;
|
||||
print "exit f", c;
|
||||
}
|
||||
|
||||
const foo = 0 &redef;
|
||||
redef foo = 10;
|
||||
|
||||
const bar = 9;
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
const baz = 7;
|
||||
local i = foo;
|
||||
i = i + bar + 2;
|
||||
i = i + baz + 11;
|
||||
++i;
|
||||
print i;
|
||||
--i;
|
||||
f(foo);
|
||||
f(bar);
|
||||
f(baz);
|
||||
print "foo", foo;
|
||||
print "bar", bar;
|
||||
print "baz", baz;
|
||||
}
|
||||
|
||||
@TEST-END-FILE
|
||||
|
||||
@TEST-START-FILE invalid.bro
|
||||
# Now some const assignments that should generate errors at parse-time.
|
||||
|
||||
const foo = 0 &redef;
|
||||
redef foo = 10;
|
||||
|
||||
const bar = 9;
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
const baz = 7;
|
||||
local s = 0;
|
||||
|
||||
print "nope";
|
||||
|
||||
foo = 100;
|
||||
foo = bar;
|
||||
foo = bar = baz;
|
||||
foo = s;
|
||||
++foo;
|
||||
s = foo = bar;
|
||||
|
||||
if ( foo = 0 )
|
||||
print "nope";
|
||||
|
||||
bar = 1 + 1;
|
||||
baz = s;
|
||||
++bar;
|
||||
--baz;
|
||||
|
||||
print "foo", foo;
|
||||
print "bar", bar;
|
||||
print "baz", baz;
|
||||
print "foo=foo", foo = foo;
|
||||
}
|
||||
|
||||
@TEST-END-FILE
|
Loading…
Add table
Add a link
Reference in a new issue