File: strictj.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 (46 lines) | stat: -rw-r--r-- 1,099 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
source("TestHarness.bsh");
import bsh.Interpreter;

// Various commands aren't strictJava safe yet, so this has some trouble.
// Everything was working when tested.
/*
setStrictJava( false );
strictx=5;

setStrictJava( true );
int stricty1=5;
assert( isEvalError("stricty2=5;") );

setStrictJava( false );
stricty2=5;
*/

// loose
Interpreter loosei=new Interpreter();

// strict java
Interpreter stricti=new Interpreter();
stricti.setStrictJava(true);

loosei.set("a",5);
// strictjava still allows untyped external set
stricti.set("a",5);

loosei.eval("a=6");
// we can assign to pre-existing untype vars even in strict java mode
stricti.eval("a=6");

loosei.eval("int q2=5");
loosei.eval("q=5");

stricti.eval("int q2=5");
// error, untyped assignment
assert( isEvalError("stricti.eval(\"q=5\")") );
// error, untyped method arg
assert( isEvalError("stricti.eval(\"int foo(a) {} \")") );
// error, untyped return
assert( isEvalError("stricti.eval(\"foo(int a) {} \")") );
// error, untyped catch block
assert( isEvalError("stricti.eval(\"try{throw new Exception();}catch(e){}\")"));

complete();