File: eval.bsh

package info (click to toggle)
bsh 2.0b4-20
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 4,224 kB
  • sloc: java: 23,431; xml: 4,500; sh: 139; makefile: 24
file content (57 lines) | stat: -rw-r--r-- 753 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/java bsh.Interpreter

source("TestHarness.bsh");

eval("b=2");
assert(b==2);

foo() {
	return 42;
}

a=eval("foo()");
assert(a==42);

try {
	b=eval("bogus()");
} catch ( bsh.EvalError e ) {
	flag();
}

assert( flag() == 1 );

/**
	Make sure eval's side effects happen in the correct namespace
*/
if ( Interpreter.LOCALSCOPING )
{
a=6;
b=6; // sanity check
scope() {
	eval("a=5");
	b=5; // sanity check
	return this;
}
s=scope();
assert(s.b==5); // sanity check
assert(b==6); // sanity check
assert(s.a==5);
assert(a==6);
}
else
{
a=6;
b=6; // sanity check
scope() {
	eval("this.a=5");
	this.b=5; // sanity check
	return this;
}
s=scope();
assert(s.b==5); // sanity check
assert(b==6); // sanity check
assert(s.a==5);
assert(a==6);
}

complete();