diff --git a/idea/testData/scratch/custom/test_scratch.kts b/idea/testData/scratch/custom/test_scratch.kts new file mode 100644 index 00000000000..5b8c1264e56 --- /dev/null +++ b/idea/testData/scratch/custom/test_scratch.kts @@ -0,0 +1,3 @@ +// REPL_MODE: ~REPL_MODE~ +// INTERACTIVE_MODE: ~INTERACTIVE_MODE~ +1 diff --git a/idea/testData/scratch/for.comp.after b/idea/testData/scratch/for.comp.after index 0a7a6928b84..3fb4955cb35 100644 --- a/idea/testData/scratch/for.comp.after +++ b/idea/testData/scratch/for.comp.after @@ -1,3 +1,5 @@ +// REPL_MODE: false + for (i in 0..5) { // OUTPUT: 0; 1; 2; 3; 4; 5 println(i) } diff --git a/idea/testData/scratch/for.kts b/idea/testData/scratch/for.kts index afc542c82dc..c6ad52f6271 100644 --- a/idea/testData/scratch/for.kts +++ b/idea/testData/scratch/for.kts @@ -1,3 +1,5 @@ +// REPL_MODE: ~REPL_MODE~ + for (i in 0..5) { println(i) } diff --git a/idea/testData/scratch/for.repl.after b/idea/testData/scratch/for.repl.after index 0a7a6928b84..670618548e8 100644 --- a/idea/testData/scratch/for.repl.after +++ b/idea/testData/scratch/for.repl.after @@ -1,3 +1,5 @@ +// REPL_MODE: true + for (i in 0..5) { // OUTPUT: 0; 1; 2; 3; 4; 5 println(i) } diff --git a/idea/testData/scratch/generics.comp.after b/idea/testData/scratch/generics.comp.after index ece0a3efe34..b9de5580ab3 100644 --- a/idea/testData/scratch/generics.comp.after +++ b/idea/testData/scratch/generics.comp.after @@ -1,3 +1,5 @@ +// REPL_MODE: false + class GClass { // RESULT: class GClass fun foo(t: T): T { return t diff --git a/idea/testData/scratch/generics.kts b/idea/testData/scratch/generics.kts index 417bc24a399..f146f6f367c 100644 --- a/idea/testData/scratch/generics.kts +++ b/idea/testData/scratch/generics.kts @@ -1,3 +1,5 @@ +// REPL_MODE: ~REPL_MODE~ + class GClass { fun foo(t: T): T { return t diff --git a/idea/testData/scratch/generics.repl.after b/idea/testData/scratch/generics.repl.after index a9a019c85f3..b7ed8cb8882 100644 --- a/idea/testData/scratch/generics.repl.after +++ b/idea/testData/scratch/generics.repl.after @@ -1,3 +1,5 @@ +// REPL_MODE: true + class GClass { fun foo(t: T): T { return t diff --git a/idea/testData/scratch/klass.comp.after b/idea/testData/scratch/klass.comp.after index 7fbd0a5e799..5959244701e 100644 --- a/idea/testData/scratch/klass.comp.after +++ b/idea/testData/scratch/klass.comp.after @@ -1,3 +1,5 @@ +// REPL_MODE: false + class MyClass { // RESULT: class MyClass fun foo() = 1 } diff --git a/idea/testData/scratch/klass.kts b/idea/testData/scratch/klass.kts index 01ddaa3a871..437b1d7cdc8 100644 --- a/idea/testData/scratch/klass.kts +++ b/idea/testData/scratch/klass.kts @@ -1,3 +1,5 @@ +// REPL_MODE: ~REPL_MODE~ + class MyClass { fun foo() = 1 } diff --git a/idea/testData/scratch/klass.repl.after b/idea/testData/scratch/klass.repl.after index c1459c67aa4..62026b570d9 100644 --- a/idea/testData/scratch/klass.repl.after +++ b/idea/testData/scratch/klass.repl.after @@ -1,3 +1,5 @@ +// REPL_MODE: true + class MyClass { fun foo() = 1 } diff --git a/idea/testData/scratch/libraryDepWithKotlinTest.comp.after b/idea/testData/scratch/libraryDepWithKotlinTest.comp.after index 1dccf80eb6d..600426142ab 100644 --- a/idea/testData/scratch/libraryDepWithKotlinTest.comp.after +++ b/idea/testData/scratch/libraryDepWithKotlinTest.comp.after @@ -1,2 +1,4 @@ +// REPL_MODE: false + val a: Int? = 1 // RESULT: val a: Int? kotlin.test.assertNotNull(1) // RESULT: 1 \ No newline at end of file diff --git a/idea/testData/scratch/libraryDepWithKotlinTest.kts b/idea/testData/scratch/libraryDepWithKotlinTest.kts index 766071b1ec6..864eb3d5ac5 100644 --- a/idea/testData/scratch/libraryDepWithKotlinTest.kts +++ b/idea/testData/scratch/libraryDepWithKotlinTest.kts @@ -1,2 +1,4 @@ +// REPL_MODE: ~REPL_MODE~ + val a: Int? = 1 kotlin.test.assertNotNull(1) \ No newline at end of file diff --git a/idea/testData/scratch/libraryDepWithKotlinTest.repl.after b/idea/testData/scratch/libraryDepWithKotlinTest.repl.after index ce401f63778..f790edafb40 100644 --- a/idea/testData/scratch/libraryDepWithKotlinTest.repl.after +++ b/idea/testData/scratch/libraryDepWithKotlinTest.repl.after @@ -1,2 +1,4 @@ +// REPL_MODE: true + val a: Int? = 1 kotlin.test.assertNotNull(1) // RESULT: res1: kotlin.Int = 1 \ No newline at end of file diff --git a/idea/testData/scratch/multiFile/inlineFun/inlineFun.comp.after b/idea/testData/scratch/multiFile/inlineFun/inlineFun.comp.after index 453b26566b7..e2aff3384ac 100644 --- a/idea/testData/scratch/multiFile/inlineFun/inlineFun.comp.after +++ b/idea/testData/scratch/multiFile/inlineFun/inlineFun.comp.after @@ -1,3 +1,5 @@ +// REPL_MODE: false + import inlineFun.* foo { 1 + 3 } // RESULT: 4 \ No newline at end of file diff --git a/idea/testData/scratch/multiFile/inlineFun/inlineFun.kts b/idea/testData/scratch/multiFile/inlineFun/inlineFun.kts index 6b957dd293e..e303c22ec0d 100644 --- a/idea/testData/scratch/multiFile/inlineFun/inlineFun.kts +++ b/idea/testData/scratch/multiFile/inlineFun/inlineFun.kts @@ -1,3 +1,5 @@ +// REPL_MODE: ~REPL_MODE~ + import inlineFun.* foo { 1 + 3 } \ No newline at end of file diff --git a/idea/testData/scratch/multiFile/inlineFun/inlineFun.repl.after b/idea/testData/scratch/multiFile/inlineFun/inlineFun.repl.after index d5a3451b8f6..78931de5843 100644 --- a/idea/testData/scratch/multiFile/inlineFun/inlineFun.repl.after +++ b/idea/testData/scratch/multiFile/inlineFun/inlineFun.repl.after @@ -1,3 +1,5 @@ +// REPL_MODE: true + import inlineFun.* foo { 1 + 3 } // RESULT: res1: kotlin.Int = 4 \ No newline at end of file diff --git a/idea/testData/scratch/multiFile/javaDep/javaDep.comp.after b/idea/testData/scratch/multiFile/javaDep/javaDep.comp.after index 0f224476ec7..e62496b23f6 100644 --- a/idea/testData/scratch/multiFile/javaDep/javaDep.comp.after +++ b/idea/testData/scratch/multiFile/javaDep/javaDep.comp.after @@ -1,3 +1,5 @@ +// REPL_MODE: false + import myTest.MyJavaClass MyJavaClass().test() // RESULT: 1 \ No newline at end of file diff --git a/idea/testData/scratch/multiFile/javaDep/javaDep.kts b/idea/testData/scratch/multiFile/javaDep/javaDep.kts index bb1c8939884..e1e1d26caca 100644 --- a/idea/testData/scratch/multiFile/javaDep/javaDep.kts +++ b/idea/testData/scratch/multiFile/javaDep/javaDep.kts @@ -1,3 +1,5 @@ +// REPL_MODE: ~REPL_MODE~ + import myTest.MyJavaClass MyJavaClass().test() \ No newline at end of file diff --git a/idea/testData/scratch/multiFile/javaDep/javaDep.repl.after b/idea/testData/scratch/multiFile/javaDep/javaDep.repl.after index 26c5636c243..930472a70f2 100644 --- a/idea/testData/scratch/multiFile/javaDep/javaDep.repl.after +++ b/idea/testData/scratch/multiFile/javaDep/javaDep.repl.after @@ -1,3 +1,5 @@ +// REPL_MODE: true + import myTest.MyJavaClass MyJavaClass().test() // RESULT: res1: kotlin.Int = 1 \ No newline at end of file diff --git a/idea/testData/scratch/simple.comp.after b/idea/testData/scratch/simple.comp.after index 08fccb10480..ca1d7653de0 100644 --- a/idea/testData/scratch/simple.comp.after +++ b/idea/testData/scratch/simple.comp.after @@ -1,2 +1,4 @@ +// REPL_MODE: false + val a = 1 // RESULT: val a: Int a // RESULT: 1 \ No newline at end of file diff --git a/idea/testData/scratch/simple.kts b/idea/testData/scratch/simple.kts index c49c0a3cb30..335e61f7ded 100644 --- a/idea/testData/scratch/simple.kts +++ b/idea/testData/scratch/simple.kts @@ -1,2 +1,4 @@ +// REPL_MODE: ~REPL_MODE~ + val a = 1 a \ No newline at end of file diff --git a/idea/testData/scratch/simple.repl.after b/idea/testData/scratch/simple.repl.after index ca0b9807d18..a143f492580 100644 --- a/idea/testData/scratch/simple.repl.after +++ b/idea/testData/scratch/simple.repl.after @@ -1,2 +1,4 @@ +// REPL_MODE: true + val a = 1 a // RESULT: res1: kotlin.Int = 1 \ No newline at end of file diff --git a/idea/testData/scratch/simpleFun.comp.after b/idea/testData/scratch/simpleFun.comp.after index 80c0e4381d7..c78c806d1af 100644 --- a/idea/testData/scratch/simpleFun.comp.after +++ b/idea/testData/scratch/simpleFun.comp.after @@ -1,3 +1,5 @@ +// REPL_MODE: false + fun foo(): Int { // RESULT: fun foo(): Int return 1 } diff --git a/idea/testData/scratch/simpleFun.kts b/idea/testData/scratch/simpleFun.kts index 70ff7f93dac..27a9a0c19d2 100644 --- a/idea/testData/scratch/simpleFun.kts +++ b/idea/testData/scratch/simpleFun.kts @@ -1,3 +1,5 @@ +// REPL_MODE: ~REPL_MODE~ + fun foo(): Int { return 1 } diff --git a/idea/testData/scratch/simpleFun.repl.after b/idea/testData/scratch/simpleFun.repl.after index 13e025b93aa..4262313ac64 100644 --- a/idea/testData/scratch/simpleFun.repl.after +++ b/idea/testData/scratch/simpleFun.repl.after @@ -1,3 +1,5 @@ +// REPL_MODE: true + fun foo(): Int { return 1 } diff --git a/idea/testData/scratch/simpleNoRuntime.comp.after b/idea/testData/scratch/simpleNoRuntime.comp.after index 1b2688f68a9..d55799a903a 100644 --- a/idea/testData/scratch/simpleNoRuntime.comp.after +++ b/idea/testData/scratch/simpleNoRuntime.comp.after @@ -1,3 +1,4 @@ -arrayListOf(1, 2).size // RESULT: 2 +// REPL_MODE: false +// NO_MODULE -//NO_MODULE \ No newline at end of file +arrayListOf(1, 2).size // RESULT: 2 \ No newline at end of file diff --git a/idea/testData/scratch/simpleNoRuntime.kts b/idea/testData/scratch/simpleNoRuntime.kts index f39820c5a5d..3a8b2ce8186 100644 --- a/idea/testData/scratch/simpleNoRuntime.kts +++ b/idea/testData/scratch/simpleNoRuntime.kts @@ -1,3 +1,4 @@ -arrayListOf(1, 2).size +// REPL_MODE: ~REPL_MODE~ +// NO_MODULE -//NO_MODULE \ No newline at end of file +arrayListOf(1, 2).size \ No newline at end of file diff --git a/idea/testData/scratch/simpleNoRuntime.repl.after b/idea/testData/scratch/simpleNoRuntime.repl.after index 027127cf60c..487de8bc092 100644 --- a/idea/testData/scratch/simpleNoRuntime.repl.after +++ b/idea/testData/scratch/simpleNoRuntime.repl.after @@ -1,3 +1,4 @@ -arrayListOf(1, 2).size // RESULT: res0: kotlin.Int = 2 +// REPL_MODE: true +// NO_MODULE -//NO_MODULE \ No newline at end of file +arrayListOf(1, 2).size // RESULT: res0: kotlin.Int = 2 \ No newline at end of file diff --git a/idea/testData/scratch/spacesAtLineStart.comp.after b/idea/testData/scratch/spacesAtLineStart.comp.after index 905e34d87cb..4a77f0cced5 100644 --- a/idea/testData/scratch/spacesAtLineStart.comp.after +++ b/idea/testData/scratch/spacesAtLineStart.comp.after @@ -1,3 +1,5 @@ +// REPL_MODE: false + val a = 1 // RESULT: val a: Int a // RESULT: 1 a // RESULT: 1 diff --git a/idea/testData/scratch/spacesAtLineStart.kts b/idea/testData/scratch/spacesAtLineStart.kts index d3d7538a385..98d3d33fdf5 100644 --- a/idea/testData/scratch/spacesAtLineStart.kts +++ b/idea/testData/scratch/spacesAtLineStart.kts @@ -1,3 +1,5 @@ +// REPL_MODE: ~REPL_MODE~ + val a = 1 a a \ No newline at end of file diff --git a/idea/testData/scratch/spacesAtLineStart.repl.after b/idea/testData/scratch/spacesAtLineStart.repl.after index 5eb2cc128ed..78bbd269ff3 100644 --- a/idea/testData/scratch/spacesAtLineStart.repl.after +++ b/idea/testData/scratch/spacesAtLineStart.repl.after @@ -1,3 +1,5 @@ +// REPL_MODE: true + val a = 1 a // RESULT: res1: kotlin.Int = 1 a // RESULT: res2: kotlin.Int = 1 diff --git a/idea/testData/scratch/stdlibFun.comp.after b/idea/testData/scratch/stdlibFun.comp.after index 556ab826a4c..af54755710f 100644 --- a/idea/testData/scratch/stdlibFun.comp.after +++ b/idea/testData/scratch/stdlibFun.comp.after @@ -1,3 +1,5 @@ +// REPL_MODE: false + arrayListOf(1, 5, 7).map { it * 2 } // RESULT: 2 .filter { it < 10 } .find { it == 2 } diff --git a/idea/testData/scratch/stdlibFun.kts b/idea/testData/scratch/stdlibFun.kts index c7a1f9d966d..19528117dd2 100644 --- a/idea/testData/scratch/stdlibFun.kts +++ b/idea/testData/scratch/stdlibFun.kts @@ -1,3 +1,5 @@ +// REPL_MODE: ~REPL_MODE~ + arrayListOf(1, 5, 7).map { it * 2 } .filter { it < 10 } .find { it == 2 } \ No newline at end of file diff --git a/idea/testData/scratch/stdlibFun.repl.after b/idea/testData/scratch/stdlibFun.repl.after index c68521274dd..800e4e6df55 100644 --- a/idea/testData/scratch/stdlibFun.repl.after +++ b/idea/testData/scratch/stdlibFun.repl.after @@ -1,3 +1,5 @@ +// REPL_MODE: true + arrayListOf(1, 5, 7).map { it * 2 } // RESULT: res0: kotlin.Int? = 2 .filter { it < 10 } .find { it == 2 } diff --git a/idea/testData/scratch/unresolved.comp.after b/idea/testData/scratch/unresolved.comp.after index 94155b2605c..2ced4812c9a 100644 --- a/idea/testData/scratch/unresolved.comp.after +++ b/idea/testData/scratch/unresolved.comp.after @@ -1,2 +1,4 @@ +// REPL_MODE: false + foo() // ERROR: Unresolved reference: foo -/** unresolved.kts:1 Unresolved reference: foo */ \ No newline at end of file +/** unresolved.kts:3 Unresolved reference: foo */ \ No newline at end of file diff --git a/idea/testData/scratch/unresolved.kts b/idea/testData/scratch/unresolved.kts index eb28ef4401b..a203cbe05a8 100644 --- a/idea/testData/scratch/unresolved.kts +++ b/idea/testData/scratch/unresolved.kts @@ -1 +1,3 @@ +// REPL_MODE: ~REPL_MODE~ + foo() diff --git a/idea/testData/scratch/unresolved.repl.after b/idea/testData/scratch/unresolved.repl.after index cc0156fa90f..0c16206dd18 100644 --- a/idea/testData/scratch/unresolved.repl.after +++ b/idea/testData/scratch/unresolved.repl.after @@ -1,4 +1,6 @@ +// REPL_MODE: true + foo() // ERROR: error: unresolved reference: foo... -/** unresolved.kts:1 error: unresolved reference: foo +/** unresolved.kts:3 error: unresolved reference: foo foo() ^ */ \ No newline at end of file diff --git a/idea/testData/scratch/unresolvedMultiline.comp.after b/idea/testData/scratch/unresolvedMultiline.comp.after index 420b70f5d09..c38f4140c67 100644 --- a/idea/testData/scratch/unresolvedMultiline.comp.after +++ b/idea/testData/scratch/unresolvedMultiline.comp.after @@ -1,3 +1,5 @@ +// REPL_MODE: false + foo.forEach { // ERROR: Unresolved reference: foo; Cannot choose among the following candidates without completing ty... 1 + 1 } @@ -5,8 +7,8 @@ foo.forEach { // ERROR: Unresolved reference: foo; Cannot choose among fun goo(a: String) { // ERROR: Unresolved reference: goo super.goo(a) } -/** unresolvedMultiline.kts:1 Unresolved reference: foo */ -/** unresolvedMultiline.kts:1 Cannot choose among the following candidates without completing type inference: +/** unresolvedMultiline.kts:3 Unresolved reference: foo */ +/** unresolvedMultiline.kts:3 Cannot choose among the following candidates without completing type inference: @HidesMembers public inline fun Iterable.forEach(action: (???) -> Unit): Unit defined in kotlin.collections @HidesMembers public inline fun Map.forEach(action: (Map.Entry) -> Unit): Unit defined in kotlin.collections */ -/** unresolvedMultiline.kts:5 Unresolved reference: goo */ \ No newline at end of file +/** unresolvedMultiline.kts:7 Unresolved reference: goo */ \ No newline at end of file diff --git a/idea/testData/scratch/unresolvedMultiline.kts b/idea/testData/scratch/unresolvedMultiline.kts index a9de95ee983..25a71282632 100644 --- a/idea/testData/scratch/unresolvedMultiline.kts +++ b/idea/testData/scratch/unresolvedMultiline.kts @@ -1,3 +1,5 @@ +// REPL_MODE: ~REPL_MODE~ + foo.forEach { 1 + 1 } diff --git a/idea/testData/scratch/unresolvedMultiline.repl.after b/idea/testData/scratch/unresolvedMultiline.repl.after index 9697f4b6107..826169acb24 100644 --- a/idea/testData/scratch/unresolvedMultiline.repl.after +++ b/idea/testData/scratch/unresolvedMultiline.repl.after @@ -1,3 +1,5 @@ +// REPL_MODE: true + foo.forEach { // ERROR: error: unresolved reference: foo... 1 + 1 } @@ -5,7 +7,7 @@ foo.forEach { // ERROR: error: unresolved reference: foo... fun goo(a: String) { // ERROR: error: unresolved reference: goo... super.goo(a) } -/** unresolvedMultiline.kts:1 error: unresolved reference: foo +/** unresolvedMultiline.kts:3 error: unresolved reference: foo foo.forEach { ^ error: cannot choose among the following candidates without completing type inference: @@ -13,6 +15,6 @@ error: cannot choose among the following candidates without completing type infe @HidesMembers public inline fun Map.forEach(action: (Map.Entry) -> Unit): Unit defined in kotlin.collections foo.forEach { ^ */ -/** unresolvedMultiline.kts:5 error: unresolved reference: goo +/** unresolvedMultiline.kts:7 error: unresolved reference: goo super.goo(a) ^ */ \ No newline at end of file diff --git a/idea/testData/scratch/userOutput.comp.after b/idea/testData/scratch/userOutput.comp.after index b6091122aec..ff57f903c4e 100644 --- a/idea/testData/scratch/userOutput.comp.after +++ b/idea/testData/scratch/userOutput.comp.after @@ -1 +1,3 @@ +// REPL_MODE: false + println("hello") // OUTPUT: hello \ No newline at end of file diff --git a/idea/testData/scratch/userOutput.kts b/idea/testData/scratch/userOutput.kts index ae973bcd537..e3cb908aadd 100644 --- a/idea/testData/scratch/userOutput.kts +++ b/idea/testData/scratch/userOutput.kts @@ -1 +1,3 @@ +// REPL_MODE: ~REPL_MODE~ + println("hello") \ No newline at end of file diff --git a/idea/testData/scratch/userOutput.repl.after b/idea/testData/scratch/userOutput.repl.after index ce696ae6bfb..ca2f2717849 100644 --- a/idea/testData/scratch/userOutput.repl.after +++ b/idea/testData/scratch/userOutput.repl.after @@ -1 +1,3 @@ +// REPL_MODE: true + println("hello") // OUTPUT: hello diff --git a/idea/testData/scratch/var.comp.after b/idea/testData/scratch/var.comp.after index f76592d687f..1d6455da4eb 100644 --- a/idea/testData/scratch/var.comp.after +++ b/idea/testData/scratch/var.comp.after @@ -1,3 +1,5 @@ +// REPL_MODE: false + var a = 1 // RESULT: var a: Int a++ // RESULT: 1 a // RESULT: 2 \ No newline at end of file diff --git a/idea/testData/scratch/var.kts b/idea/testData/scratch/var.kts index 8da9de9c877..af07eff037e 100644 --- a/idea/testData/scratch/var.kts +++ b/idea/testData/scratch/var.kts @@ -1,3 +1,5 @@ +// REPL_MODE: ~REPL_MODE~ + var a = 1 a++ a \ No newline at end of file diff --git a/idea/testData/scratch/var.repl.after b/idea/testData/scratch/var.repl.after index 96cd3bc17ee..156ded3f636 100644 --- a/idea/testData/scratch/var.repl.after +++ b/idea/testData/scratch/var.repl.after @@ -1,3 +1,5 @@ +// REPL_MODE: true + var a = 1 a++ // RESULT: res1: kotlin.Int = 1 a // RESULT: res2: kotlin.Int = 2 \ No newline at end of file diff --git a/idea/testData/scratch/veryLongOutput.comp.after b/idea/testData/scratch/veryLongOutput.comp.after index 101e7d6ba94..80a3fbf4edf 100644 --- a/idea/testData/scratch/veryLongOutput.comp.after +++ b/idea/testData/scratch/veryLongOutput.comp.after @@ -1,12 +1,14 @@ +// REPL_MODE: false + val a = "a".repeat(100) // RESULT: val a: String a // RESULT: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... val b = "0123456789\n".repeat(10) // RESULT: val b: String b // RESULT: 0123456789; 0123456789; 0123456789; 0123456789; 012345678... println("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789") // OUTPUT: 01... -/** veryLongOutput.kts:2 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */ -/** veryLongOutput.kts:4 0123456789 */ -/** veryLongOutput.kts:4 0123456789 */ -/** veryLongOutput.kts:4 0123456789 */ -/** veryLongOutput.kts:4 0123456789 */ -/** veryLongOutput.kts:4 0123456789 */ -/** veryLongOutput.kts:5 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 */ \ No newline at end of file +/** veryLongOutput.kts:4 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */ +/** veryLongOutput.kts:6 0123456789 */ +/** veryLongOutput.kts:6 0123456789 */ +/** veryLongOutput.kts:6 0123456789 */ +/** veryLongOutput.kts:6 0123456789 */ +/** veryLongOutput.kts:6 0123456789 */ +/** veryLongOutput.kts:7 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 */ \ No newline at end of file diff --git a/idea/testData/scratch/veryLongOutput.kts b/idea/testData/scratch/veryLongOutput.kts index 6fd3ab0679a..463185e3c30 100644 --- a/idea/testData/scratch/veryLongOutput.kts +++ b/idea/testData/scratch/veryLongOutput.kts @@ -1,3 +1,5 @@ +// REPL_MODE: ~REPL_MODE~ + val a = "a".repeat(100) a val b = "0123456789\n".repeat(10) diff --git a/idea/testData/scratch/veryLongOutput.repl.after b/idea/testData/scratch/veryLongOutput.repl.after index 0cd06916af0..5e7011e309b 100644 --- a/idea/testData/scratch/veryLongOutput.repl.after +++ b/idea/testData/scratch/veryLongOutput.repl.after @@ -1,10 +1,12 @@ +// REPL_MODE: true + val a = "a".repeat(100) a // RESULT: res1: kotlin.String = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... val b = "0123456789\n".repeat(10) b // RESULT: res3: kotlin.String = 0123456789... println("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789") // OUTPUT: 01... -/** veryLongOutput.kts:2 res1: kotlin.String = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */ -/** veryLongOutput.kts:4 res3: kotlin.String = 0123456789 +/** veryLongOutput.kts:4 res1: kotlin.String = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */ +/** veryLongOutput.kts:6 res3: kotlin.String = 0123456789 0123456789 0123456789 0123456789 @@ -14,4 +16,4 @@ println("01234567890123456789012345678901234567890123456789012345678901234567890 0123456789 0123456789 0123456789 */ -/** veryLongOutput.kts:5 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 */ \ No newline at end of file +/** veryLongOutput.kts:7 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 */ \ No newline at end of file diff --git a/idea/testData/scratch/when.comp.after b/idea/testData/scratch/when.comp.after index 5c79a6637d7..a2630e0eee4 100644 --- a/idea/testData/scratch/when.comp.after +++ b/idea/testData/scratch/when.comp.after @@ -1,3 +1,5 @@ +// REPL_MODE: false + val a = 1 // RESULT: val a: Int when(a) { // OUTPUT: 1 1 -> println("1") diff --git a/idea/testData/scratch/when.kts b/idea/testData/scratch/when.kts index 4a71c00159a..8d4d3cc256b 100644 --- a/idea/testData/scratch/when.kts +++ b/idea/testData/scratch/when.kts @@ -1,3 +1,5 @@ +// REPL_MODE: ~REPL_MODE~ + val a = 1 when(a) { 1 -> println("1") diff --git a/idea/testData/scratch/when.repl.after b/idea/testData/scratch/when.repl.after index 14c64c81c2a..3ba175d3bcc 100644 --- a/idea/testData/scratch/when.repl.after +++ b/idea/testData/scratch/when.repl.after @@ -1,3 +1,5 @@ +// REPL_MODE: true + val a = 1 when(a) { // OUTPUT: 1 1 -> println("1") diff --git a/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt index 5b1820e6657..74465570e58 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt @@ -15,8 +15,6 @@ import com.intellij.openapi.roots.ModuleRootModificationUtil import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess -import com.intellij.psi.PsiDocumentManager -import com.intellij.psi.PsiManager import com.intellij.testFramework.FileEditorManagerTestCase import com.intellij.testFramework.MapDataContext import com.intellij.testFramework.PsiTestUtil @@ -26,9 +24,11 @@ import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime import org.jetbrains.kotlin.idea.KotlinLanguage import org.jetbrains.kotlin.idea.core.script.ScriptDependenciesManager import org.jetbrains.kotlin.idea.highlighter.KotlinHighlightingUtil +import org.jetbrains.kotlin.idea.scratch.actions.ClearScratchAction import org.jetbrains.kotlin.idea.scratch.actions.RunScratchAction import org.jetbrains.kotlin.idea.scratch.actions.ScratchCompilationSupport import org.jetbrains.kotlin.idea.scratch.output.InlayScratchFileRenderer +import org.jetbrains.kotlin.idea.scratch.ui.ScratchTopPanel import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor import org.jetbrains.kotlin.idea.test.PluginTestCaseBase @@ -78,6 +78,9 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() { val mainFileName = "$dirName/${getTestName(true)}.kts" doCompilingTest(mainFileName) + + launchAction(ClearScratchAction()) + doReplTest(mainFileName) ModuleRootModificationUtil.updateModel(module) { model -> @@ -87,44 +90,16 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() { fun doTest(fileName: String, isRepl: Boolean) { val sourceFile = File(testDataPath, fileName) - val fileText = sourceFile.readText() + val fileText = sourceFile.readText().inlinePropertiesValues(isRepl) - val scratchFile = createScratchFile(sourceFile.name, fileText) + configureScratchByText(sourceFile.name, fileText) - ScriptDependenciesManager.updateScriptDependenciesSynchronously(scratchFile, project) + if (!KotlinHighlightingUtil.shouldHighlight(myFixture.file)) error("Highlighting for scratch file is switched off") - val psiFile = PsiManager.getInstance(project).findFile(scratchFile) ?: error("Couldn't find psi file ${sourceFile.path}") + launchScratch() + waitUntilScratchFinishes() - if (!KotlinHighlightingUtil.shouldHighlight(psiFile)) error("Highlighting for scratch file is switched off") - - val (editor, scratchPanel) = getEditorWithScratchPanel(myManager, scratchFile) ?: error("Couldn't find scratch panel") - scratchPanel.scratchFile.saveOptions { - copy(isRepl = isRepl, isInteractiveMode = false) - } - - if (!InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_MODULE")) { - scratchPanel.setModule(myFixture.module) - } - - launchScratch(scratchFile) - - val doc = PsiDocumentManager.getInstance(project).getDocument(psiFile) ?: error("Document for ${psiFile.name} is null") - - val actualOutput = StringBuilder(psiFile.text) - for (line in doc.lineCount - 1 downTo 0) { - editor.editor.inlayModel.getInlineElementsInRange( - doc.getLineStartOffset(line), - doc.getLineEndOffset(line) - ).map { it.renderer } - .filterIsInstance() - .forEach { - val str = it.toString() - val offset = doc.getLineEndOffset(line); actualOutput.insert( - offset, - "${str.takeWhile { it.isWhitespace() }}// ${str.trim()}" - ) - } - } + val actualOutput = getFileTextWithInlays() val expectedFileName = if (isRepl) { fileName.replace(".kts", ".repl.after") @@ -135,7 +110,59 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() { KotlinTestUtils.assertEqualsToFile(expectedFile, actualOutput.toString()) } - protected fun createScratchFile(name: String, text: String): VirtualFile { + protected fun String.inlinePropertiesValues( + isRepl: Boolean = false, + isInteractiveMode: Boolean = false + ): String { + return replace("~REPL_MODE~", isRepl.toString()).replace("~INTERACTIVE_MODE~", isInteractiveMode.toString()) + } + + private fun getFileTextWithInlays(): StringBuilder { + val doc = myFixture.getDocument(myFixture.file) ?: error("Document for ${myFixture.file.name} is null") + val actualOutput = StringBuilder(myFixture.file.text) + for (line in doc.lineCount - 1 downTo 0) { + getInlays(doc.getLineStartOffset(line), doc.getLineEndOffset(line)) + .forEach { inlay -> + val str = inlay.toString() + val offset = doc.getLineEndOffset(line) + actualOutput.insert( + offset, + "${str.takeWhile { it.isWhitespace() }}// ${str.trim()}" + ) + } + } + return actualOutput + } + + protected fun getInlays(start: Int = 0, end: Int = myFixture.file.textLength): List { + val inlineElementsInRange = myFixture.editor.inlayModel.getInlineElementsInRange(start, end) + return inlineElementsInRange + .map { it.renderer } + .filterIsInstance() + } + + private fun configureOptions( + scratchPanel: ScratchTopPanel, + fileText: String + ) { + if (InTextDirectivesUtils.getPrefixedBoolean(fileText, "// INTERACTIVE_MODE: ") != true) { + scratchPanel.scratchFile.saveOptions { + copy(isInteractiveMode = false) + } + } + + if (InTextDirectivesUtils.getPrefixedBoolean(fileText, "// REPL_MODE: ") == true) { + scratchPanel.scratchFile.saveOptions { + copy(isRepl = true) + } + } + + if (!InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_MODULE")) { + scratchPanel.setModule(myFixture.module) + } + } + + protected fun configureScratchByText(name: String, text: String): ScratchTopPanel { val scratchFile = ScratchRootType.getInstance().createScratchFile( project, name, @@ -145,17 +172,30 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() { ) ?: error("Couldn't create scratch file") myFixture.openFileInEditor(scratchFile) - return scratchFile + + ScriptDependenciesManager.updateScriptDependenciesSynchronously(scratchFile, project) + + val (_, scratchPanel) = getEditorWithScratchPanel(myManager, myFixture.file.virtualFile) + ?: error("Couldn't find scratch panel") + + configureOptions(scratchPanel, text) + + return scratchPanel } - protected fun launchScratch(scratchFile: VirtualFile) { + protected fun launchScratch() { val action = RunScratchAction() - val e = getActionEvent(scratchFile, action) + launchAction(action) + } + protected fun launchAction(action: AnAction) { + val e = getActionEvent(myFixture.file.virtualFile, action) action.beforeActionPerformedUpdate(e) Assert.assertTrue(e.presentation.isEnabled && e.presentation.isVisible) action.actionPerformed(e) + } + protected fun waitUntilScratchFinishes() { UIUtil.dispatchAllInvocationEvents() val start = System.currentTimeMillis() @@ -175,6 +215,10 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() { return TestActionEvent(context, action) } + protected fun testScratchText(): String { + return File(testDataPath, "idea/testData/scratch/custom/test_scratch.kts").readText() + } + override fun getTestDataPath() = KotlinTestUtils.getHomeDirectory() diff --git a/idea/tests/org/jetbrains/kotlin/idea/scratch/CustomScratchRunActionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/scratch/CustomScratchRunActionTest.kt index 5076501c521..9a1e76f8f30 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/scratch/CustomScratchRunActionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/scratch/CustomScratchRunActionTest.kt @@ -9,7 +9,6 @@ import com.intellij.openapi.roots.ModuleRootModificationUtil import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable import com.intellij.openapi.roots.libraries.Library import org.jetbrains.kotlin.idea.run.createLibraryWithLongPaths -import org.jetbrains.kotlin.idea.scratch.output.InlayScratchFileRenderer import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner import org.junit.runner.RunWith @@ -26,22 +25,13 @@ class CustomScratchRunActionTest : AbstractScratchRunActionTest() { } private fun getOutput(isRepl: Boolean): String { - val fileText = "1" - val scratchFile = createScratchFile("scratch_1.kts", fileText) + val fileText = testScratchText().inlinePropertiesValues(isRepl) + configureScratchByText("scratch_1.kts", fileText) - val (editor, scratchPanel) = getEditorWithScratchPanel(myManager, scratchFile) ?: error("Couldn't find scratch panel") - scratchPanel.scratchFile.saveOptions { - copy(isRepl = isRepl, isInteractiveMode = false) - } + launchScratch() + waitUntilScratchFinishes() - scratchPanel.setModule(myFixture.module) - - launchScratch(scratchFile) - - return editor.editor.inlayModel.getInlineElementsInRange(0, fileText.length) - .map { it.renderer } - .filterIsInstance() - .joinToString().trim() + return getInlays().joinToString().trim() } private val library: Library by lazy { diff --git a/idea/tests/org/jetbrains/kotlin/idea/scratch/ScratchOptionsSaveTest.kt b/idea/tests/org/jetbrains/kotlin/idea/scratch/ScratchOptionsSaveTest.kt index 9e956713ffc..808b8f1c4c4 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/scratch/ScratchOptionsSaveTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/scratch/ScratchOptionsSaveTest.kt @@ -17,8 +17,7 @@ import kotlin.reflect.full.declaredMemberProperties class ScratchOptionsSaveTest : AbstractScratchRunActionTest() { fun testOptionsSaveOnClosingFile() { - val scratchFile = createScratchFile("scratch_1.kts", "val a = 1") - val (_, scratchPanelBeforeClosingFile) = getEditorWithScratchPanel(myManager, scratchFile) ?: error("Couldn't find scratch panel") + val scratchPanelBeforeClosingFile = configureScratchByText("scratch_1.kts", testScratchText()) Assert.assertEquals( "This test checks that checkbox options are restored after file closing. Not all checkboxes are checked in this test", @@ -34,10 +33,10 @@ class ScratchOptionsSaveTest : AbstractScratchRunActionTest() { scratchPanelBeforeClosingFile.setMakeBeforeRun(newIsMakeBeforeRunValue) scratchPanelBeforeClosingFile.setInteractiveMode(newIsInteractiveModeValue) - myManager.closeFile(scratchFile) - myManager.openFile(scratchFile, true) + myManager.closeFile(myFixture.file.virtualFile) + myManager.openFile(myFixture.file.virtualFile, true) - val (_, scratchPanelAfterClosingFile) = getEditorWithScratchPanel(myManager, scratchFile) ?: error("Couldn't find scratch panel") + val (_, scratchPanelAfterClosingFile) = getEditorWithScratchPanel(myManager, myFixture.file.virtualFile) ?: error("Couldn't find scratch panel") Assert.assertEquals("Wrong value for isRepl checkbox", newIsReplValue, scratchPanelAfterClosingFile.scratchFile.options.isRepl) Assert.assertEquals(