'From Squeak6.0alpha of 15 September 2020 [latest update: #19851] on 29 September 2020 at 12:28:24 am'!
Object subclass: #TestCase
	instanceVariableNames: 'testSelector timeout resumable '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'SUnit-Kernel'!
TestCase subclass: #ResumableTestFailureTestCase
	instanceVariableNames: ''
	classVariableNames: 'State '
	poolDictionaries: ''
	category: 'SUnit-Tests'!

!TestCase methodsFor: 'accessing' stamp: 'ct 9/28/2020 23:45'!
beResumableDuring: aBlock

	self resumable: true.
	^ aBlock ensure: [
		self resumable: false]! !

!TestCase methodsFor: 'accessing' stamp: 'ct 9/28/2020 23:50'!
isResumable

	^ resumable ifNil: [
		| method |
		method := self class lookupSelector: testSelector asSymbol.
		(method pragmaAt: #resumable) ifNotNil: [
			resumable := true].
		resumable ifNil: [
			(method pragmaAt: #resumable:) ifNotNil: [:tag | resumable := tag arguments first]].
		resumable ifNil: [
			resumable := false]]! !

!TestCase methodsFor: 'accessing' stamp: 'ct 9/28/2020 23:45'!
resumable: aBoolean

	resumable := aBoolean! !

!TestCase methodsFor: 'private' stamp: 'ct 9/28/2020 23:45'!
signalFailure: aString

	^ self
		signalFailure: aString
		resumable: self isResumable! !

!TestCase methodsFor: 'private' stamp: 'ct 9/28/2020 23:42'!
signalFailure: aString resumable: aBoolean

	^ (aBoolean
		ifTrue: [TestResult resumableFailure]
		ifFalse: [TestResult failure])
			signal: aString! !

!TestCase methodsFor: 'asserting' stamp: 'ct 9/28/2020 23:42'!
assert: aBooleanOrBlock description: aStringOrBlock

	aBooleanOrBlock value ifFalse: [
		| description |
		description := aStringOrBlock value.
		self logFailure: description.
		self signalFailure: description].! !

!TestCase methodsFor: 'asserting' stamp: 'ct 9/28/2020 23:43'!
assert: aBooleanOrBlock description: aString resumable: resumableBoolean 

	aBooleanOrBlock value ifFalse: [
		self logFailure: aString.
		self signalFailure: aString resumable: resumableBoolean].! !


!ResumableTestFailureTestCase methodsFor: 'data' stamp: 'ct 9/29/2020 00:16'!
resumableTestFailureTest

	State := 1.
	self assert: false description: 'You should see me' resumable: true.
	State := 2.
	self assert: false description: 'You should see me too' resumable: true.
	State := 3.
	self assert: false description: 'You should see me last' resumable: false.
	State := 4.
	self assert: false description: 'You should not see me' resumable: true.! !

!ResumableTestFailureTestCase methodsFor: 'data' stamp: 'ct 9/29/2020 00:19'!
resumableTestManualTest

	State := 1.
	self beResumableDuring: [
		self fail].
	State := 2.
	self fail.
	State := 3.! !

!ResumableTestFailureTestCase methodsFor: 'data' stamp: 'ct 9/29/2020 00:18'!
resumableTestPragma0Test
	<resumable>

	State := 1.
	self fail.
	State := 2.! !

!ResumableTestFailureTestCase methodsFor: 'data' stamp: 'ct 9/29/2020 00:18'!
resumableTestPragma1FalseTest
	<resumable: false>

	State := 1.
	self fail.
	State := 2.! !

!ResumableTestFailureTestCase methodsFor: 'data' stamp: 'ct 9/29/2020 00:18'!
resumableTestPragma1TrueTest
	<resumable: true>

	State := 1.
	self fail.
	State := 2.! !

!ResumableTestFailureTestCase methodsFor: 'tests' stamp: 'ct 9/29/2020 00:23'!
testResumablePragma
	<resumable>

	#((resumableTestPragma0Test 2) (resumableTestPragma1TrueTest 2) (resumableTestPragma1FalseTest 1) (resumableTestManualTest 2)) do: [:spec |
		| suite result |
		suite := TestSuite new.
		suite addTest: (self class selector: spec first).
		State := 0.
		
		result := suite run.
		
		self
			assert: 1 equals: result failures size;
			assert: spec second equals: State].! !

!ResumableTestFailureTestCase methodsFor: 'tests' stamp: 'ct 9/29/2020 00:08'!
testResumableResult

	| suite result |
	suite := TestSuite new.
	suite addTest: (self class selector: #errorTest).
	suite addTest: (self class selector: #regularTestFailureTest).
	suite addTest: (self class selector: #resumableTestFailureTest).
	suite addTest: (self class selector: #okTest).
	
	result := suite run.
	
	self
		assert: 2 equals: result failures size;
		assert: 1 equals: result errors size.! !

!ResumableTestFailureTestCase methodsFor: 'tests' stamp: 'ct 9/29/2020 00:12'!
testResumption

	| suite result |
	suite := TestSuite new.
	suite addTest: (self class selector: #resumableTestFailureTest).
	State := 0.
	
	result := suite run.
	
	self
		assert: 1 equals: result failures size;
		assert: 3 equals: State.! !


!TestResult methodsFor: 'running' stamp: 'ct 9/29/2020 00:04'!
runCase: aTestCase
	
	| testCasePassed timeToRun |
	testCasePassed := true.

	[timeToRun := [aTestCase runCase] timeToRunWithoutGC] 
		on: self class failure
		do: [:signal | 
				failures add: aTestCase.
				testCasePassed := false.
				signal isResumable
					ifFalse: [signal return: false]
					ifTrue: [signal resume]]
		on: self class error
		do: [:signal |
				errors add: aTestCase.
				testCasePassed := false.
				signal return: false].
			
	testCasePassed ifTrue: [passed add: aTestCase].
	self durations at: aTestCase put: timeToRun.! !

ResumableTestFailureTestCase class removeSelector: #lastStoredRun!
ResumableTestFailureTestCase removeSelector: #failureTest!
ResumableTestFailureTestCase removeSelector: #testResumable!
TestCase subclass: #ResumableTestFailureTestCase
	instanceVariableNames: ''
	classVariableNames: 'State'
	poolDictionaries: ''
	category: 'SUnit-Tests'!
Object subclass: #TestCase
	instanceVariableNames: 'testSelector timeout resumable'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'SUnit-Kernel'!
