[squeak-dev] The Inbox: SUnit-ct.127.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Apr 9 12:22:51 UTC 2020


Christoph Thiede uploaded a new version of SUnit to project The Inbox:
http://source.squeak.org/inbox/SUnit-ct.127.mcz

==================== Summary ====================

Name: SUnit-ct.127
Author: ct
Time: 9 April 2020, 2:22:49.769949 pm
UUID: bf5be456-fbd7-e343-9158-da59c75fa05d
Ancestors: SUnit-ct.126

Adds support for string pattern assertions (#assert:matches:[description:] and #deny:matches:[description:]). Also tests these selectors in SUnitTest.

TestCase new assert: 'Sq*k' matches: 'Squeak'.
TestCase new assert: 'Sq\w+k' asRegex matches: 'Squeak'.
TestCase new deny: '.*\d' asRegex matches: 'Squeak123' description: 'This one will fail'.

Depends indeed on SUnit-ct.126.

=============== Diff against SUnit-ct.126 ===============

Item was added:
+ ----- Method: SUnitTest>>testAssertMatches (in category 'tests') -----
+ testAssertMatches
+ 
+ 	| pattern positive negative notAString |
+ 	pattern := 'f*'.
+ 	positive := 'foo'.
+ 	negative := 'bar'.
+ 	notAString := Object new.
+ 	
+ 	self shouldnt: [self assert: pattern matches: positive] raise: TestFailure.
+ 	
+ 	self should: [self assert: pattern matches: negative] raise: TestFailure.
+ 	[self assert: pattern matches: negative]
+ 		on: TestFailure do: [:ex |
+ 			| error |
+ 			error := ex messageText.
+ 			self
+ 				assert: (error includesSubstring: pattern)
+ 				description: 'Error message doesn''t include the expected pattern'.
+ 			self
+ 				assert: (error includesSubstring: negative)
+ 				description: 'Error message doesn''t include the actual value'].
+ 	
+ 	self should: [self assert: pattern matches: notAString] raise: TestFailure.
+ 	[self assert: pattern matches: notAString]
+ 		on: TestFailure do: [:ex |
+ 			| error |
+ 			error := ex messageText.
+ 			self
+ 				assert: (error includesSubstring: 'string')
+ 				description: 'Error message doesn''t say that we''re passing a non-string object here'.
+ 			self
+ 				assert: (error includesSubstring: pattern)
+ 				description: 'Error message doesn''t include the expected pattern'.
+ 			self
+ 				assert: (error includesSubstring: notAString asString)
+ 				description: 'Error message doesn''t include the actual value'].!

Item was added:
+ ----- Method: SUnitTest>>testAssertMatchesDescription (in category 'tests') -----
+ testAssertMatchesDescription
+ 
+ 	| pattern positive negative notAString |
+ 	pattern := 'f*'.
+ 	positive := 'foo'.
+ 	negative := 'bar'.
+ 	notAString := Object new.
+ 	
+ 	self shouldnt: [self assert: pattern matches: positive description: ['A description' , 42]] raise: TestFailure.
+ 	
+ 	self should: [self assert: pattern matches: negative description: ['A description' , 42]] raise: TestFailure.
+ 	[self assert: pattern matches: negative description: ['A description' , 42]]
+ 		on: TestFailure do: [:ex |
+ 			| error |
+ 			error := ex messageText.
+ 			self
+ 				assert: (error includesSubstring: 'A description' , 42)
+ 				description: 'Error message doesn''t give you the description'].
+ 	
+ 	self should: [self assert: pattern matches: notAString description: ['A description' , 42]] raise: TestFailure.
+ 	[self assert: pattern matches: notAString description: ['A description' , 42]]
+ 		on: TestFailure do: [:ex |
+ 			| error |
+ 			error := ex messageText.
+ 			self
+ 				assert: (error includesSubstring: 'string')
+ 				description: 'Error message doesn''t say that we''re passing a non-string object here'.
+ 			self
+ 				assert: (error includesSubstring: 'A description' , 42)
+ 				description: 'Error message doesn''t give you the description'].!

Item was added:
+ ----- Method: SUnitTest>>testAssertMatchesRegex (in category 'tests') -----
+ testAssertMatchesRegex
+ 
+ 	| pattern positive negative notAString |
+ 	pattern := 'fo+' asRegex.
+ 	positive := 'foo'.
+ 	negative := 'f'.
+ 	notAString := Object new.
+ 	
+ 	self shouldnt: [self assert: pattern matches: positive] raise: TestFailure.
+ 	
+ 	self should: [self assert: pattern matches: negative] raise: TestFailure.
+ 	[self assert: pattern matches: negative]
+ 		on: TestFailure do: [:ex |
+ 			| error |
+ 			error := ex messageText.
+ 			self
+ 				assert: (error includesSubstring: pattern asString)
+ 				description: 'Error message doesn''t include the expected regex pattern'.
+ 			self
+ 				assert: (error includesSubstring: negative)
+ 				description: 'Error message doesn''t include the actual value'].
+ 	
+ 	self should: [self assert: pattern matches: notAString] raise: TestFailure.
+ 	[self assert: pattern matches: notAString]
+ 		on: TestFailure do: [:ex |
+ 			| error |
+ 			error := ex messageText.
+ 			self
+ 				assert: (error includesSubstring: 'string')
+ 				description: 'Error message doesn''t say that we''re passing a non-string object here'.
+ 			self
+ 				assert: (error includesSubstring: pattern asString)
+ 				description: 'Error message doesn''t include the expected regex pattern'.
+ 			self
+ 				assert: (error includesSubstring: notAString asString)
+ 				description: 'Error message doesn''t include the actual value'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyMatches (in category 'tests') -----
+ testDenyMatches
+ 
+ 	| pattern positive negative notAString |
+ 	pattern := 'f*'.
+ 	positive := 'foo'.
+ 	negative := 'bar'.
+ 	notAString := Object new.
+ 	
+ 	self shouldnt: [self deny: pattern matches: negative] raise: TestFailure.
+ 	
+ 	self should: [self deny: pattern matches: positive] raise: TestFailure.
+ 	[self deny: pattern matches: positive]
+ 		on: TestFailure do: [:ex |
+ 			| error |
+ 			error := ex messageText.
+ 			self
+ 				assert: (error includesSubstring: pattern)
+ 				description: 'Error message doesn''t include the expected pattern'.
+ 			self
+ 				assert: (error includesSubstring: positive)
+ 				description: 'Error message doesn''t include the actual value'].
+ 	
+ 	self should: [self deny: pattern matches: notAString] raise: TestFailure.
+ 	[self deny: pattern matches: notAString]
+ 		on: TestFailure do: [:ex |
+ 			| error |
+ 			error := ex messageText.
+ 			self
+ 				assert: (error includesSubstring: 'string')
+ 				description: 'Error message doesn''t say that we''re passing a non-string object here'.
+ 			self
+ 				assert: (error includesSubstring: pattern)
+ 				description: 'Error message doesn''t include the expected pattern'.
+ 			self
+ 				assert: (error includesSubstring: notAString asString)
+ 				description: 'Error message doesn''t include the actual value'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyMatchesDescription (in category 'tests') -----
+ testDenyMatchesDescription
+ 
+ 	| pattern positive negative notAString |
+ 	pattern := 'f*'.
+ 	positive := 'foo'.
+ 	negative := 'bar'.
+ 	notAString := Object new.
+ 	
+ 	self shouldnt: [self deny: pattern matches: negative description: ['A description' , 42]] raise: TestFailure.
+ 	
+ 	self should: [self deny: pattern matches: positive description: ['A description' , 42]] raise: TestFailure.
+ 	[self deny: pattern matches: positive description: ['A description' , 42]]
+ 		on: TestFailure do: [:ex |
+ 			| error |
+ 			error := ex messageText.
+ 			self
+ 				assert: (error includesSubstring: 'A description' , 42)
+ 				description: 'Error message doesn''t give you the description'].
+ 	
+ 	self should: [self deny: pattern matches: notAString description: ['A description' , 42]] raise: TestFailure.
+ 	[self deny: pattern matches: notAString description: ['A description' , 42]]
+ 		on: TestFailure do: [:ex |
+ 			| error |
+ 			error := ex messageText.
+ 			self
+ 				assert: (error includesSubstring: 'string')
+ 				description: 'Error message doesn''t say that we''re passing a non-string object here'.
+ 			self
+ 				assert: (error includesSubstring: 'A description' , 42)
+ 				description: 'Error message doesn''t give you the description'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyMatchesRegex (in category 'tests') -----
+ testDenyMatchesRegex
+ 
+ 	| pattern positive negative notAString |
+ 	pattern := 'fo+' asRegex.
+ 	positive := 'foo'.
+ 	negative := 'f'.
+ 	notAString := Object new.
+ 	
+ 	self shouldnt: [self deny: pattern matches: negative] raise: TestFailure.
+ 	
+ 	self should: [self deny: pattern matches: positive] raise: TestFailure.
+ 	[self deny: pattern matches: positive]
+ 		on: TestFailure do: [:ex |
+ 			| error |
+ 			error := ex messageText.
+ 			self
+ 				assert: (error includesSubstring: pattern asString)
+ 				description: 'Error message doesn''t include the expected regex pattern'.
+ 			self
+ 				assert: (error includesSubstring: negative)
+ 				description: 'Error message doesn''t include the actual value'].
+ 	
+ 	self should: [self deny: pattern matches: notAString] raise: TestFailure.
+ 	[self deny: pattern matches: notAString]
+ 		on: TestFailure do: [:ex |
+ 			| error |
+ 			error := ex messageText.
+ 			self
+ 				assert: (error includesSubstring: 'string')
+ 				description: 'Error message doesn''t say that we''re passing a non-string object here'.
+ 			self
+ 				assert: (error includesSubstring: pattern asString)
+ 				description: 'Error message doesn''t include the expected regex pattern'.
+ 			self
+ 				assert: (error includesSubstring: notAString asString)
+ 				description: 'Error message doesn''t include the actual value'].!

Item was added:
+ ----- Method: TestCase>>assert:matches: (in category 'accessing') -----
+ assert: pattern matches: actual
+ 
+ 	^ self
+ 		assert: pattern
+ 		matches: actual
+ 		description: nil!

Item was added:
+ ----- Method: TestCase>>assert:matches:description: (in category 'accessing') -----
+ assert: pattern matches: actual description: aStringOrBlock
+ 
+ 	self
+ 		assert: [actual isString or: [actual isText]]
+ 		description: [self
+ 			description: aStringOrBlock
+ 			with: (self comparingStringBetweenPattern: pattern andNonTextual: actual)].
+ 	self
+ 		assert: [self doesPattern: pattern match: actual]
+ 		description: [self
+ 			description: aStringOrBlock
+ 			with: (self comparingStringBetweenPattern: pattern and: actual)].!

Item was added:
+ ----- Method: TestCase>>comparingStringBetweenPattern:and: (in category 'private') -----
+ comparingStringBetweenPattern: pattern and: actual
+ 
+ 	^ 'Expected pattern {1} does not match actual {2}.' translated
+ 		format: {
+ 			pattern.
+ 			actual }!

Item was added:
+ ----- Method: TestCase>>comparingStringBetweenPattern:andNonTextual: (in category 'private') -----
+ comparingStringBetweenPattern: pattern andNonTextual: actual
+ 
+ 	^ 'Expected something that matches {1} but actual {2} is neither string nor text.' translated
+ 		format: {
+ 			pattern.
+ 			actual }!

Item was added:
+ ----- Method: TestCase>>comparingStringBetweenUnexpectedPattern:and: (in category 'private') -----
+ comparingStringBetweenUnexpectedPattern: pattern and: actual
+ 
+ 	^ 'Unexpected pattern {1} does match actual {2}.' translated
+ 		format: {
+ 			pattern.
+ 			actual }!

Item was added:
+ ----- Method: TestCase>>comparingStringBetweenUnexpectedPattern:andNonTextual: (in category 'private') -----
+ comparingStringBetweenUnexpectedPattern: pattern andNonTextual: actual
+ 
+ 	^ 'Expected something that does not match {1} but actual {2} is neither string nor text.' translated
+ 		format: {
+ 			pattern.
+ 			actual }!

Item was added:
+ ----- Method: TestCase>>deny:matches: (in category 'accessing') -----
+ deny: pattern matches: actual
+ 
+ 	^ self
+ 		deny: pattern
+ 		matches: actual
+ 		description: nil!

Item was added:
+ ----- Method: TestCase>>deny:matches:description: (in category 'accessing') -----
+ deny: pattern matches: actual description: aStringOrBlock
+ 
+ 	self
+ 		assert: [actual isString or: [actual isText]]
+ 		description: [self
+ 			description: aStringOrBlock
+ 			with: (self comparingStringBetweenUnexpectedPattern: pattern andNonTextual: actual)].
+ 	self
+ 		deny: [self doesPattern: pattern match: actual]
+ 		description: [self
+ 			description: aStringOrBlock
+ 			with: (self comparingStringBetweenUnexpectedPattern: pattern and: actual)].!

Item was added:
+ ----- Method: TestCase>>doesPattern:match: (in category 'private') -----
+ doesPattern: pattern match: stringOrText
+ 
+ 	^ (pattern respondsTo: #matches:)
+ 		ifTrue: [pattern matches: stringOrText]
+ 		ifFalse: [pattern match: stringOrText]!



More information about the Squeak-dev mailing list