/* Ċ Ġ* ĠCopyright Ġ 2 0 0 0 - 2 0 1 9 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ Ġ*/ Ċ Ċ package Ġorg . jetbrains . r . console Ċ Ċ import Ġcom . intellij . openapi . action System . Action Manager Ċ import Ġcom . intellij . openapi . action System . Toggle Action Ċ import Ġcom . intellij . test Framework . Platform TestUtil Ċ import Ġcom . intellij . x debugger . X Debugger Manager Ċ import Ġcom . intellij . x debugger . breakpoints . Suspend Policy Ċ import Ġcom . intellij . x debugger . impl . breakpoints . X Breakpoint ManagerImpl Ċ import Ġcom . intellij . x debugger . impl . breakpoints . X Expression Impl Ċ import Ġjunit . framework . TestCase Ċ Ċ class ĠR Console Debugger Test Ġ: ĠR Console Base TestCase () Ġ{ ĊĠ Ġfun Ġtest Log Message () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġload File With Break points FromText (""" ĊĠĠĠĠĠĠ 1 ĊĠĠĠĠĠĠ 2 ĊĠĠĠĠĠĠ 3 Ġ# ĠBRE AK POINT ( suspend Ġ= ĠFALSE , ĠlogMessage Ġ= ĠTRUE ) ĊĠĠĠĠĠĠ 4 ĊĠĠĠĠĠĠ 5 ĊĠĠĠ Ġ""" . trim Indent (), Ġ" abc . R ") ĊĠĠĠ Ġval Ġhelper Ġ= ĠR Console Debugger TestHelper ( console ) ĊĠĠĠ Ġhelper . invoke And Wait ( false ) Ġ{ ĊĠĠĠĠĠ Ġr Interop . repl SourceFile ( file , Ġdebug Ġ= Ġtrue ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġcheck Console Text (" Breakpoint Ġhit Ġ( abc . R : 3 )") ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Log Stack () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġload File With Break points FromText (""" ĊĠĠĠĠĠ Ġfoo Ġ<- Ġfunction () Ġ{ ĊĠĠĠĠĠĠĠĠ 2 Ġ# ĠBRE AK POINT ( suspend Ġ= ĠFALSE , Ġlog Stack Ġ= ĠTRUE ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġbar Ġ<- Ġfunction () Ġ{ ĊĠĠĠĠĠĠĠ Ġfoo () ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġcat ( bar ()) ĊĠĠĠ Ġ""" . trim Indent (), Ġ" def . R ") ĊĠĠĠ Ġval Ġhelper Ġ= ĠR Console Debugger TestHelper ( console ) ĊĠĠĠ Ġhelper . invoke And Wait ( false ) Ġ{ ĊĠĠĠĠĠ Ġr Interop . repl SourceFile ( file , Ġdebug Ġ= Ġtrue ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġcheck Console Text (" 1 : Ġfoo Ġ( def . R : 2 )") ĊĠĠĠ Ġcheck Console Text (" 2 : Ġbar Ġ( def . R : 5 )") ĊĠĠĠ Ġcheck Console Text (" 3 : Ġcat ") ĊĠĠĠ Ġcheck Console Text (" 4 : Ġ[ global ] Ġ( def . R : 7 )") ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Slave Breakpoint () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġmy Fixture . configure By Text (" a . R ", Ġ""" ĊĠĠĠĠĠ Ġfor Ġ( i Ġin Ġ 1 : 5 ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( i Ġ%% Ġ 2 Ġ== Ġ 0 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠ 3 ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠ 5 ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ""" . trim Indent ()). virtual File ĊĠĠĠ Ġval Ġmaster Ġ= Ġadd Breakpoint ( file , Ġ 2 ) ĊĠĠĠ Ġval Ġslave Ġ= Ġadd Breakpoint ( file , Ġ 4 ) ĊĠĠĠ Ġval Ġdependent Breakpoint Manager Ġ= ĊĠĠĠĠĠ Ġ( X Debugger Manager . getInstance ( project ). breakpoint Manager Ġas ĠX Breakpoint ManagerImpl ). dependent Breakpoint Manager ĊĠĠĠ Ġdependent Breakpoint Manager . set Master Breakpoint ( slave , Ġmaster , Ġfalse ) ĊĠĠĠ Ġmaster . suspend Policy Ġ= ĠS uspend Policy . NONE ĊĊĠĠĠ Ġval Ġhelper Ġ= ĠR Console Debugger TestHelper ( console ) ĊĠĠĠ Ġhelper . invoke And Wait ( true ) Ġ{ Ġr Interop . repl SourceFile ( file , Ġdebug Ġ= Ġtrue ) Ġ} ĊĠĠĠ ĠTestCase . assertEquals (" 2 ", Ġr Interop . execute Code (" cat ( i ) "). stdout ) ĊĠĠĠ ĠTestCase . assertEquals ( 4 , Ġr Interop . debug Stack . last OrNull ()?. position ?. line ) ĊĠĠĠ Ġhelper . invoke And Wait ( true ) Ġ{ Ġr Interop . debug Command Continue () Ġ} ĊĠĠĠ ĠTestCase . assertEquals (" 4 ", Ġr Interop . execute Code (" cat ( i ) "). stdout ) ĊĠĠĠ ĠTestCase . assertEquals ( 4 , Ġr Interop . debug Stack . last OrNull ()?. position ?. line ) ĊĠĠĠ Ġhelper . invoke And Wait ( false ) Ġ{ Ġr Interop . debug Command Continue () Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Slave Breakpoint Leave Enabled () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġmy Fixture . configure By Text (" a . R ", Ġ""" ĊĠĠĠĠĠ Ġfor Ġ( i Ġin Ġ 1 : 5 ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( i Ġ== Ġ 4 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠ 3 ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠ 5 ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ""" . trim Indent ()). virtual File ĊĠĠĠ Ġval Ġmaster Ġ= Ġadd Breakpoint ( file , Ġ 2 ) ĊĠĠĠ Ġval Ġslave Ġ= Ġadd Breakpoint ( file , Ġ 4 ) ĊĠĠĠ Ġval Ġdependent Breakpoint Manager Ġ= ĊĠĠĠĠĠ Ġ( X Debugger Manager . getInstance ( project ). breakpoint Manager Ġas ĠX Breakpoint ManagerImpl ). dependent Breakpoint Manager ĊĠĠĠ Ġdependent Breakpoint Manager . set Master Breakpoint ( slave , Ġmaster , Ġtrue ) ĊĠĠĠ Ġmaster . suspend Policy Ġ= ĠS uspend Policy . NONE ĊĊĠĠĠ Ġval Ġhelper Ġ= ĠR Console Debugger TestHelper ( console ) ĊĠĠĠ Ġhelper . invoke And Wait ( true ) Ġ{ Ġr Interop . repl SourceFile ( file , Ġdebug Ġ= Ġtrue ) Ġ} ĊĠĠĠ ĠTestCase . assertEquals (" 4 ", Ġr Interop . execute Code (" cat ( i ) "). stdout ) ĊĠĠĠ ĠTestCase . assertEquals ( 4 , Ġr Interop . debug Stack . last OrNull ()?. position ?. line ) ĊĠĠĠ Ġhelper . invoke And Wait ( true ) Ġ{ Ġr Interop . debug Command Continue () Ġ} ĊĠĠĠ ĠTestCase . assertEquals (" 5 ", Ġr Interop . execute Code (" cat ( i ) "). stdout ) ĊĠĠĠ ĠTestCase . assertEquals ( 4 , Ġr Interop . debug Stack . last OrNull ()?. position ?. line ) ĊĠĠĠ Ġhelper . invoke And Wait ( false ) Ġ{ Ġr Interop . debug Command Continue () Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Slave Breakpoint Condition And Log () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġmy Fixture . configure By Text (" a . R ", Ġ""" ĊĠĠĠĠĠ Ġfor Ġ( i Ġin Ġ 1 : 5 ) Ġ{ ĊĠĠĠĠĠĠĠĠ 2 ĊĠĠĠĠĠĠĠĠ 3 ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ""" . trim Indent ()). virtual File ĊĠĠĠ Ġval Ġmaster Ġ= Ġadd Breakpoint ( file , Ġ 1 ) ĊĠĠĠ Ġval Ġslave Ġ= Ġadd Breakpoint ( file , Ġ 2 ) ĊĠĠĠ Ġval Ġdependent Breakpoint Manager Ġ= ĊĠĠĠĠĠ Ġ( X Debugger Manager . getInstance ( project ). breakpoint Manager Ġas ĠX Breakpoint ManagerImpl ). dependent Breakpoint Manager ĊĠĠĠ Ġdependent Breakpoint Manager . set Master Breakpoint ( slave , Ġmaster , Ġfalse ) ĊĠĠĠ Ġmaster . suspend Policy Ġ= ĠS uspend Policy . NONE ĊĠĠĠ Ġmaster . condition Expression Ġ= ĠX Expression Impl . from Text (" i Ġ%% Ġ 2 Ġ== Ġ 0 ") ĊĠĠĠ Ġslave . suspend Policy Ġ= ĠS uspend Policy . NONE ĊĠĠĠ Ġslave . log Expression Object Ġ= ĠX Expression Impl . from Text (" paste 0 (' << ', Ġi , Ġ' >> ') ") ĊĊĠĠĠ Ġval Ġhelper Ġ= ĠR Console Debugger TestHelper ( console ) ĊĠĠĠ Ġhelper . invoke And Wait ( false ) Ġ{ Ġr Interop . repl SourceFile ( file , Ġdebug Ġ= Ġtrue ) Ġ} ĊĠĠĠ Ġcheck Console Text (" << 1 >> ", Ġexclude Ġ= Ġtrue ) ĊĠĠĠ Ġcheck Console Text (" << 2 >> ") ĊĠĠĠ Ġcheck Console Text (" << 3 >> ", Ġexclude Ġ= Ġtrue ) ĊĠĠĠ Ġcheck Console Text (" << 4 >> ") ĊĠĠĠ Ġcheck Console Text (" << 5 >> ", Ġexclude Ġ= Ġtrue ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Temporary Breakpoint () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġload File With Break points FromText (""" ĊĠĠĠĠĠ Ġfor Ġ( i Ġin Ġ 1 : 5 ) Ġ{ ĊĠĠĠĠĠĠĠĠ 2 ĊĠĠĠĠĠĠĠĠ 3 Ġ# ĠBRE AK POINT ( temporary Ġ= ĠTRUE ) ĊĠĠĠĠĠĠĠĠ 4 ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ""" . trim Indent ()) ĊĠĠĠ Ġval Ġhelper Ġ= ĠR Console Debugger TestHelper ( console ) ĊĠĠĠ Ġhelper . invoke And Wait ( true ) Ġ{ Ġr Interop . repl SourceFile ( file , Ġdebug Ġ= Ġtrue ) Ġ} ĊĠĠĠ ĠTestCase . assertEquals (" 1 ", Ġr Interop . execute Code (" cat ( i ) "). stdout ) ĊĠĠĠ ĠTestCase . assertEquals ( 2 , Ġr Interop . debug Stack . last (). position ?. line ) ĊĠĠĠ Ġhelper . invoke And Wait ( false ) Ġ{ Ġr Interop . debug Command Continue () Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Temporary Breakpoint No Suspend () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġload File With Break points FromText (""" ĊĠĠĠĠĠ Ġfor Ġ( i Ġin Ġ 1 : 3 ) Ġ{ ĊĠĠĠĠĠĠĠĠ 2 ĊĠĠĠĠĠĠĠĠ 3 Ġ# ĠBRE AK POINT ( suspend Ġ= ĠFALSE , Ġtemporary Ġ= ĠTRUE , Ġevaluate Ġ= Ġpaste 0 (' << ', Ġi , Ġ' >> ')) ĊĠĠĠĠĠĠĠĠ 4 ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ""" . trim Indent ()) ĊĠĠĠ Ġval Ġhelper Ġ= ĠR Console Debugger TestHelper ( console ) ĊĠĠĠ Ġhelper . invoke And Wait ( false ) Ġ{ Ġr Interop . repl SourceFile ( file , Ġdebug Ġ= Ġtrue ) Ġ} ĊĠĠĠ Ġcheck Console Text (" << 1 >> ") ĊĠĠĠ Ġcheck Console Text (" << 2 >> ", Ġtrue ) ĊĠĠĠ Ġcheck Console Text (" << 3 >> ", Ġtrue ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Global Mute Break points Action () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġload File With Break points FromText (""" ĊĠĠĠĠĠĠ 1 ĊĠĠĠĠĠĠ 2 Ġ# ĠBRE AK POINT ĊĠĠĠĠĠĠ 3 ĊĠĠĠ Ġ""" . trim Indent ()) ĊĠĠĠ Ġval Ġaction Ġ= ĠAction Manager . getInstance (). getAction (" X Debugger . Mute Break points ") Ġas ĠToggle Action ĊĠĠĠ Ġval Ġhelper Ġ= ĠR Console Debugger TestHelper ( console ) ĊĊĠĠĠ Ġaction . setSelected ( create An ActionEvent (), Ġtrue ) ĊĠĠĠ ĠTestCase . assertTrue ( console . debugger Panel !!. breakpoints Mut ed ) ĊĠĠĠ Ġhelper . invoke And Wait ( false ) Ġ{ Ġr Interop . repl SourceFile ( file , Ġdebug Ġ= Ġtrue ) Ġ} ĊĊĠĠĠ Ġaction . setSelected ( create An ActionEvent (), Ġfalse ) ĊĠĠĠ ĠTestCase . assertFalse ( console . debugger Panel !!. breakpoints Mut ed ) ĊĠĠĠ Ġhelper . invoke And Wait ( true ) Ġ{ Ġr Interop . repl SourceFile ( file , Ġdebug Ġ= Ġtrue ) Ġ} ĊĠĠĠ Ġhelper . invoke And Wait ( false ) Ġ{ Ġr Interop . debug Command Continue () Ġ} ĊĊĠĠĠ ĠTestCase . assertFalse ( action . isSelected ( create An ActionEvent ())) ĊĠĠĠ Ġconsole . debugger Panel !!. breakpoints Mut ed Ġ= Ġtrue ĊĠĠĠ ĠTestCase . assertTrue ( action . isSelected ( create An ActionEvent ())) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcheck Console Text ( s : ĠString , Ġexclude : ĠBoolean Ġ= Ġfalse ) Ġ{ ĊĠĠĠ ĠPlatform TestUtil . dispatch All Events In Ide EventQueue () ĊĠĠĠ Ġconsole . flush Deferred Text () ĊĠĠĠ Ġval Ġtext Ġ= Ġconsole . editor . document . text ĊĠĠĠ Ġif Ġ( exclude ) Ġ{ ĊĠĠĠĠĠ ĠTestCase . assertTrue (" Console Ġcontents :\ n $ text ", Ġs Ġ! in Ġtext ) ĊĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠ ĠTestCase . assertTrue (" Console Ġcontents :\ n $ text ", Ġs Ġin Ġtext ) ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ }