﻿'From Squeak6.0alpha of 11 May 2022 [latest update: #21739] on 22 May 2022 at 9:46:23 am'!

!DebuggerTests methodsFor: 'tests' stamp: 'jar 5/22/2022 09:43'!
test19Abandon
	"When the debugger is abandoned, the interrupted process is terminated aggressively, i.e., all not yet started unwind contexts are executed. Further errors that occur during unwinding lead to another debugger showing up. This is the acceptance test equivalent for ProcessTest >> #testTerminateNestedUnwindAggressively."

	| x y z userProcess |
	process := Process
		forBlock:
			[[x := 1] ensure: 
				[[y := 1.
				self error: #first.
				y := 2] ensure:
					[z := 1.
					self error: #second.
					z := 2]].
			x := 2]
		runUntil: [:ctx | y = 1].
	self should: {x. y. z} = {1. 1. nil}.
	debugger := process debug.
	
	userProcess := [debugger proceed] forkAt: Processor activePriority + 1.
	Processor yield.
	self findDebugger.
	
	self deny: process isTerminated.
	self assert: userProcess isTerminated.
	self deny: debugger isNil.
	self assert: {1. 1. nil} equals: {x. y. z}.
	self assert: (debugger containingWindow label includesSubstring: #first).
	
	userProcess := [debugger abandon] forkAt: Processor activePriority + 1.
	Processor yield.
	self findDebugger.
	
	self deny: process isTerminated.
	self assert: userProcess isTerminated.
	self deny: debugger isNil.
	self assert: {1. 1. 1} equals: {x. y. z}.
	self assert: (debugger containingWindow label includesSubstring: #second).
	
	userProcess := [debugger proceed] forkAt: Processor activePriority + 1.
	Processor yield.
	self findDebugger.
	
	self assert: process isTerminated.
	self assert: userProcess isTerminated.
	self assert: debugger isNil.
	self assert: {1. 1. 2} equals: {x. y. z}.! !

!DebuggerTests methodsFor: 'tests' stamp: 'jar 5/22/2022 09:39'!
test20TerminateProcess
	"When the debugger's process is terminated, all unwind contexts, including already entered ones, are executed. Further errors that occur during unwinding lead to another debugger showing up. This is the acceptance test equivalent for ProcessTest >> #testTerminateNestedUnwind."

	| x y z userProcess |
	process := Process
		forBlock:
			[[x := 1] ensure: 
				[[y := 1.
				self error: #first.
				y := 2] ensure:
					[z := 1.
					self error: #second.
					z := 2]].
			x := 2]
		runUntil: [:ctx | y = 1].
	self should: {x. y. z} = {1. 1. nil}.
	debugger := process debug.
	
	userProcess := [debugger proceed] forkAt: Processor activePriority + 1.
	Processor yield.
	self findDebugger.
	
	self deny: process isTerminated.
	self assert: userProcess isTerminated.
	self deny: debugger isNil.
	self assert: {1. 1. nil} equals: {x. y. z}.
	self assert: (debugger containingWindow label includesSubstring: #first).
	
	userProcess := [debugger terminateProcess] forkAt: Processor activePriority + 1.
	Processor yield.
	self findDebugger.
	
	self deny: process isTerminated.
	self assert: userProcess isTerminated.
	self deny: debugger isNil.
	self assert: {1. 2. 1} equals: {x. y. z}.
	self assert: (debugger containingWindow label includesSubstring: #second).
	
	userProcess := [debugger proceed] forkAt: Processor activePriority + 1.
	Processor yield.
	self findDebugger.
	
	self assert: process isTerminated.
	self assert: userProcess isTerminated.
	self assert: debugger isNil.
	self assert: {1. 2. 2} equals: {x. y. z}.! !

