langtools/test/jdk/jshell/ReplToolTesting.java
changeset 41641 a628785b9dd9
parent 40767 c7908e8c786b
child 42265 b36ad5a64e75
equal deleted inserted replaced
41640:0c5bdda9ac56 41641:a628785b9dd9
    91     private Map<String, MethodInfo> methods;
    91     private Map<String, MethodInfo> methods;
    92     private Map<String, ClassInfo> classes;
    92     private Map<String, ClassInfo> classes;
    93     private Map<String, ImportInfo> imports;
    93     private Map<String, ImportInfo> imports;
    94     private boolean isDefaultStartUp = true;
    94     private boolean isDefaultStartUp = true;
    95     private Preferences prefs;
    95     private Preferences prefs;
       
    96     private Map<String, String> envvars;
    96 
    97 
    97     public JShellTool repl = null;
    98     public JShellTool repl = null;
    98 
    99 
    99     public interface ReplTest {
   100     public interface ReplTest {
   100         void run(boolean after);
   101         void run(boolean after);
   230     }
   231     }
   231 
   232 
   232     @BeforeMethod
   233     @BeforeMethod
   233     public void setUp() {
   234     public void setUp() {
   234         prefs = new MemoryPreferences();
   235         prefs = new MemoryPreferences();
       
   236         envvars = new HashMap<>();
       
   237     }
       
   238 
       
   239     protected void setEnvVar(String name, String value) {
       
   240         envvars.put(name, value);
   235     }
   241     }
   236 
   242 
   237     public void testRaw(Locale locale, String[] args, ReplTest... tests) {
   243     public void testRaw(Locale locale, String[] args, ReplTest... tests) {
   238         cmdin = new WaitingTestingInputStream();
   244         cmdin = new WaitingTestingInputStream();
   239         cmdout = new ByteArrayOutputStream();
   245         cmdout = new ByteArrayOutputStream();
   245         repl = new JShellTool(
   251         repl = new JShellTool(
   246                 cmdin,
   252                 cmdin,
   247                 new PrintStream(cmdout),
   253                 new PrintStream(cmdout),
   248                 new PrintStream(cmderr),
   254                 new PrintStream(cmderr),
   249                 new PrintStream(console),
   255                 new PrintStream(console),
       
   256                 userin,
   250                 new PrintStream(userout),
   257                 new PrintStream(userout),
   251                 new PrintStream(usererr),
   258                 new PrintStream(usererr),
   252                 prefs,
   259                 prefs,
       
   260                 envvars,
   253                 locale);
   261                 locale);
   254         repl.testPrompt = true;
   262         repl.testPrompt = true;
   255         try {
   263         try {
   256             repl.start(args);
   264             repl.start(args);
   257         } catch (Exception ex) {
   265         } catch (Exception ex) {
   460                 completions.toString());
   468                 completions.toString());
   461     }
   469     }
   462 
   470 
   463     private List<String> computeCompletions(String code, boolean isSmart) {
   471     private List<String> computeCompletions(String code, boolean isSmart) {
   464         JShellTool js = this.repl != null ? this.repl
   472         JShellTool js = this.repl != null ? this.repl
   465                                       : new JShellTool(null, null, null, null, null, null, prefs, Locale.ROOT);
   473                                       : new JShellTool(null, null, null, null, null, null, null,
       
   474                                               prefs, envvars, Locale.ROOT);
   466         int cursor =  code.indexOf('|');
   475         int cursor =  code.indexOf('|');
   467         code = code.replace("|", "");
   476         code = code.replace("|", "");
   468         assertTrue(cursor > -1, "'|' not found: " + code);
   477         assertTrue(cursor > -1, "'|' not found: " + code);
   469         List<Suggestion> completions =
   478         List<Suggestion> completions =
   470                 js.commandCompletionSuggestions(code, cursor, new int[1]); //XXX: ignoring anchor for now
   479                 js.commandCompletionSuggestions(code, cursor, new int[1]); //XXX: ignoring anchor for now