73 (a) -> assertCommand(a, "/classpath " + classpath, 74 String.format("| Path '%s' added to classpath", classpath)), 75 (a) -> assertMethod(a, "String foo() { return (new pkg.A()).toString(); }", 76 "()String", "foo"), 77 (a) -> assertVariable(a, "String", "v", "foo()", "\"A\""), 78 (a) -> { 79 if (!a) compiler.compile(outDir, prog.apply("Aprime")); 80 assertCommand(a, "/reload", 81 "| Restarting and restoring state.\n" + 82 "-: /classpath " + classpath + "\n" + 83 "-: String foo() { return (new pkg.A()).toString(); }\n" + 84 "-: String v = foo();\n"); 85 }, 86 (a) -> assertCommand(a, "v", "v ==> \"Aprime\""), 87 (a) -> evaluateExpression(a, "String", "foo()", "\"Aprime\""), 88 (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "Aprime") 89 ); 90 } 91 92 public void testReloadDrop() { 93 test(false, new String[]{"-nostartup"}, 94 a -> assertVariable(a, "int", "a"), 95 a -> dropVariable(a, "/dr 1", "int a = 0", "| dropped variable a"), 96 a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), 97 a -> dropMethod(a, "/drop b", "b ()I", "| dropped method b()"), 98 a -> assertClass(a, "class A {}", "class", "A"), 99 a -> dropClass(a, "/dr A", "class A", "| dropped class A"), 100 a -> assertCommand(a, "/reload", 101 "| Restarting and restoring state.\n" + 102 "-: int a;\n" + 103 "-: /drop 1\n" + 104 "-: int b() { return 0; }\n" + 105 "-: /drop b\n" + 106 "-: class A {}\n" + 107 "-: /drop A\n"), 108 a -> assertCommandCheckOutput(a, "/vars", assertVariables()), 109 a -> assertCommandCheckOutput(a, "/methods", assertMethods()), 110 a -> assertCommandCheckOutput(a, "/types", assertClasses()), 111 a -> assertCommandCheckOutput(a, "/imports", assertImports()) 112 ); 113 } 114 115 public void testReloadQuiet() { 116 test(false, new String[]{"-nostartup"}, 117 a -> assertVariable(a, "int", "a"), 118 a -> dropVariable(a, "/dr 1", "int a = 0", "| dropped variable a"), 119 a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), 120 a -> dropMethod(a, "/drop b", "b ()I", "| dropped method b()"), 121 a -> assertClass(a, "class A {}", "class", "A"), 122 a -> dropClass(a, "/dr A", "class A", "| dropped class A"), 123 a -> assertCommand(a, "/reload -quiet", 124 "| Restarting and restoring state."), 125 a -> assertCommandCheckOutput(a, "/vars", assertVariables()), 126 a -> assertCommandCheckOutput(a, "/methods", assertMethods()), 127 a -> assertCommandCheckOutput(a, "/types", assertClasses()), 128 a -> assertCommandCheckOutput(a, "/imports", assertImports()) 129 ); 130 } 131 132 public void testReloadRepeat() { 133 test(false, new String[]{"-nostartup"}, 134 (a) -> assertVariable(a, "int", "c", "7", "7"), 135 (a) -> assertCommand(a, "++c", null), 136 (a) -> assertCommand(a, "/!", null), 137 (a) -> assertCommand(a, "/2", null), 138 (a) -> assertCommand(a, "/-1", null), 139 (a) -> assertCommand(a, "/reload", 140 "| Restarting and restoring state.\n" + 141 "-: int c = 7;\n" + 142 "-: ++c\n" + 143 "-: ++c\n" + 144 "-: ++c\n" + 145 "-: ++c\n" 146 ), 147 (a) -> assertCommand(a, "c", "c ==> 11"), 148 (a) -> assertCommand(a, "$4", "$4 ==> 10") 149 ); 150 } 151 152 public void testReloadIgnore() { 153 test(false, new String[]{"-nostartup"}, 154 (a) -> assertCommand(a, "(-)", null), 155 (a) -> assertCommand(a, "/list", null), 156 (a) -> assertCommand(a, "/history", null), 157 (a) -> assertCommand(a, "/help", null), 158 (a) -> assertCommand(a, "/vars", null), 159 (a) -> assertCommand(a, "/save abcd", null), 160 (a) -> assertCommand(a, "/reload", 161 "| Restarting and restoring state.") 162 ); 163 } 164 165 public void testReloadResetRestore() { 166 test( 167 (a) -> assertVariable(a, "int", "x", "5", "5"), 168 (a) -> assertMethod(a, "int m(int z) { return z * z; }", 169 "(int)int", "m"), 170 (a) -> evaluateExpression(a, "int", "m(x)", "25"), 171 (a) -> assertCommand(a, "/reset", "| Resetting state."), 172 (a) -> assertCommand(a, "/reload -restore", 173 "| Restarting and restoring from previous state.\n" + 184 test( 185 (a) -> assertVariable(a, "int", "x", "5", "5"), 186 (a) -> assertMethod(a, "int m(int z) { return z * z; }", 187 "(int)int", "m"), 188 (a) -> evaluateExpression(a, "int", "m(x)", "25"), 189 (a) -> assertCommand(a, "System.exit(1);", 190 "| State engine terminated.\n" + 191 "| Restore definitions with: /reload -restore"), 192 (a) -> assertCommand(a, "/reload -restore", 193 "| Restarting and restoring from previous state.\n" + 194 "-: int x = 5;\n" + 195 "-: int m(int z) { return z * z; }\n" + 196 "-: m(x)\n"), 197 (a) -> evaluateExpression(a, "int", "m(x)", "25"), 198 (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), 199 (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()) 200 ); 201 } 202 203 public void testReloadExitRestore() { 204 test(false, new String[]{"-nostartup"}, 205 (a) -> assertVariable(a, "int", "x", "5", "5"), 206 (a) -> assertMethod(a, "int m(int z) { return z * z; }", 207 "(int)int", "m"), 208 (a) -> evaluateExpression(a, "int", "m(x)", "25") 209 ); 210 test(false, new String[]{"-nostartup"}, 211 (a) -> assertCommand(a, "/reload -restore", 212 "| Restarting and restoring from previous state.\n" + 213 "-: int x = 5;\n" + 214 "-: int m(int z) { return z * z; }\n" + 215 "-: m(x)\n"), 216 (a) -> evaluateExpression(a, "int", "m(x)", "25") 217 ); 218 } 219 } | 73 (a) -> assertCommand(a, "/classpath " + classpath, 74 String.format("| Path '%s' added to classpath", classpath)), 75 (a) -> assertMethod(a, "String foo() { return (new pkg.A()).toString(); }", 76 "()String", "foo"), 77 (a) -> assertVariable(a, "String", "v", "foo()", "\"A\""), 78 (a) -> { 79 if (!a) compiler.compile(outDir, prog.apply("Aprime")); 80 assertCommand(a, "/reload", 81 "| Restarting and restoring state.\n" + 82 "-: /classpath " + classpath + "\n" + 83 "-: String foo() { return (new pkg.A()).toString(); }\n" + 84 "-: String v = foo();\n"); 85 }, 86 (a) -> assertCommand(a, "v", "v ==> \"Aprime\""), 87 (a) -> evaluateExpression(a, "String", "foo()", "\"Aprime\""), 88 (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "Aprime") 89 ); 90 } 91 92 public void testReloadDrop() { 93 test(false, new String[]{"--no-startup"}, 94 a -> assertVariable(a, "int", "a"), 95 a -> dropVariable(a, "/dr 1", "int a = 0", "| dropped variable a"), 96 a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), 97 a -> dropMethod(a, "/drop b", "b ()I", "| dropped method b()"), 98 a -> assertClass(a, "class A {}", "class", "A"), 99 a -> dropClass(a, "/dr A", "class A", "| dropped class A"), 100 a -> assertCommand(a, "/reload", 101 "| Restarting and restoring state.\n" + 102 "-: int a;\n" + 103 "-: /drop 1\n" + 104 "-: int b() { return 0; }\n" + 105 "-: /drop b\n" + 106 "-: class A {}\n" + 107 "-: /drop A\n"), 108 a -> assertCommandCheckOutput(a, "/vars", assertVariables()), 109 a -> assertCommandCheckOutput(a, "/methods", assertMethods()), 110 a -> assertCommandCheckOutput(a, "/types", assertClasses()), 111 a -> assertCommandCheckOutput(a, "/imports", assertImports()) 112 ); 113 } 114 115 public void testReloadQuiet() { 116 test(false, new String[]{"--no-startup"}, 117 a -> assertVariable(a, "int", "a"), 118 a -> dropVariable(a, "/dr 1", "int a = 0", "| dropped variable a"), 119 a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), 120 a -> dropMethod(a, "/drop b", "b ()I", "| dropped method b()"), 121 a -> assertClass(a, "class A {}", "class", "A"), 122 a -> dropClass(a, "/dr A", "class A", "| dropped class A"), 123 a -> assertCommand(a, "/reload -quiet", 124 "| Restarting and restoring state."), 125 a -> assertCommandCheckOutput(a, "/vars", assertVariables()), 126 a -> assertCommandCheckOutput(a, "/methods", assertMethods()), 127 a -> assertCommandCheckOutput(a, "/types", assertClasses()), 128 a -> assertCommandCheckOutput(a, "/imports", assertImports()) 129 ); 130 } 131 132 public void testReloadRepeat() { 133 test(false, new String[]{"--no-startup"}, 134 (a) -> assertVariable(a, "int", "c", "7", "7"), 135 (a) -> assertCommand(a, "++c", null), 136 (a) -> assertCommand(a, "/!", null), 137 (a) -> assertCommand(a, "/2", null), 138 (a) -> assertCommand(a, "/-1", null), 139 (a) -> assertCommand(a, "/reload", 140 "| Restarting and restoring state.\n" + 141 "-: int c = 7;\n" + 142 "-: ++c\n" + 143 "-: ++c\n" + 144 "-: ++c\n" + 145 "-: ++c\n" 146 ), 147 (a) -> assertCommand(a, "c", "c ==> 11"), 148 (a) -> assertCommand(a, "$4", "$4 ==> 10") 149 ); 150 } 151 152 public void testReloadIgnore() { 153 test(false, new String[]{"--no-startup"}, 154 (a) -> assertCommand(a, "(-)", null), 155 (a) -> assertCommand(a, "/list", null), 156 (a) -> assertCommand(a, "/history", null), 157 (a) -> assertCommand(a, "/help", null), 158 (a) -> assertCommand(a, "/vars", null), 159 (a) -> assertCommand(a, "/save abcd", null), 160 (a) -> assertCommand(a, "/reload", 161 "| Restarting and restoring state.") 162 ); 163 } 164 165 public void testReloadResetRestore() { 166 test( 167 (a) -> assertVariable(a, "int", "x", "5", "5"), 168 (a) -> assertMethod(a, "int m(int z) { return z * z; }", 169 "(int)int", "m"), 170 (a) -> evaluateExpression(a, "int", "m(x)", "25"), 171 (a) -> assertCommand(a, "/reset", "| Resetting state."), 172 (a) -> assertCommand(a, "/reload -restore", 173 "| Restarting and restoring from previous state.\n" + 184 test( 185 (a) -> assertVariable(a, "int", "x", "5", "5"), 186 (a) -> assertMethod(a, "int m(int z) { return z * z; }", 187 "(int)int", "m"), 188 (a) -> evaluateExpression(a, "int", "m(x)", "25"), 189 (a) -> assertCommand(a, "System.exit(1);", 190 "| State engine terminated.\n" + 191 "| Restore definitions with: /reload -restore"), 192 (a) -> assertCommand(a, "/reload -restore", 193 "| Restarting and restoring from previous state.\n" + 194 "-: int x = 5;\n" + 195 "-: int m(int z) { return z * z; }\n" + 196 "-: m(x)\n"), 197 (a) -> evaluateExpression(a, "int", "m(x)", "25"), 198 (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), 199 (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()) 200 ); 201 } 202 203 public void testReloadExitRestore() { 204 test(false, new String[]{"--no-startup"}, 205 (a) -> assertVariable(a, "int", "x", "5", "5"), 206 (a) -> assertMethod(a, "int m(int z) { return z * z; }", 207 "(int)int", "m"), 208 (a) -> evaluateExpression(a, "int", "m(x)", "25") 209 ); 210 test(false, new String[]{"--no-startup"}, 211 (a) -> assertCommand(a, "/reload -restore", 212 "| Restarting and restoring from previous state.\n" + 213 "-: int x = 5;\n" + 214 "-: int m(int z) { return z * z; }\n" + 215 "-: m(x)\n"), 216 (a) -> evaluateExpression(a, "int", "m(x)", "25") 217 ); 218 } 219 } |