The Inbox: SUnit-ct.132.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: SUnit-ct.132.mcz

commits-2
A new version of SUnit was added to project The Inbox:
http://source.squeak.org/inbox/SUnit-ct.132.mcz

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

Name: SUnit-ct.132
Author: ct
Time: 6 March 2021, 12:35:33.710439 am
UUID: 98d667df-13be-d148-9117-0b214c9adb3f
Ancestors: SUnit-nice.124

Refactors and completes equality assertions

- Add #deny:equals:description:, #deny:identical:, and #deny:identical:description:
- Revise default description message for #deny:equals:, aligning it to #assert:equals: description
- Make equality assertions capable of lazy descriptions (aStringOrBlock), aligning them to
#assert:description: etc.
- Add multilingual support for default description messages
- Some internal refactoring
- Improve test coverage of these assertions in SUnitTest

Thanks to Marcel for pointing to the idea!

Uploaded again to resolve conflicts with SUnit-pre.122 (recategorization). Replaces SUnit-ct.126 which can be moved into the treated inbox. :-)

=============== Diff against SUnit-nice.124 ===============

Item was added:
+ ----- Method: SUnitTest>>testAssertEquals (in category 'tests') -----
+ testAssertEquals
+
+ | a b |
+ a := 'foo'.
+ b := 'bar'.
+
+ self shouldnt: [self assert: a equals: a copy] raise: TestFailure.
+
+ self should: [self assert: a equals: b] raise: TestFailure.
+
+ [self assert: a equals: b]
+ on: TestFailure do: [:ex |
+ | error |
+ error := ex messageText.
+ self
+ assert: (error includesSubstring: a)
+ description: 'Error message doesn''t include the expected value'.
+ self
+ assert: (error includesSubstring: b)
+ description: 'Error message doesn''t include the actual value'].!

Item was added:
+ ----- Method: SUnitTest>>testAssertEqualsDescription (in category 'tests') -----
+ testAssertEqualsDescription
+
+ | a b called |
+ a := 'foo'.
+ b := 'bar'.
+
+ self shouldnt: [self assert: a equals: a copy description: 'A description42'] raise: TestFailure.
+
+ self should: [self assert: a equals: b description: 'A description42'] raise: TestFailure.
+
+ [self assert: a equals: b description: 'A description42']
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A description42')
+ description: 'Error message doesn''t give you the description'].
+
+ called := false.
+ self shouldnt: [self assert: a equals: a description: [called := true]] raise: TestFailure.
+ self deny: called description: 'Description block was evaluated prematurely'.
+
+ [self assert: a equals: b description: ['A generated description' asUppercase]]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A generated description' asUppercase)
+ description: 'Error message doesn''t give you the generated description'].!

Item was changed:
  ----- Method: SUnitTest>>testAssertIdentical (in category 'tests') -----
  testAssertIdentical
+
  | a b |
  a := 'foo'.
  b := 'bar'.
+
+ self shouldnt: [self assert: a identical: a] raise: TestFailure.
+
  self should: [self assert: a identical: b] raise: TestFailure.
+
+ [self assert: a identical: b]
+ on: TestFailure do: [:ex |
+ | error |
+ error := ex messageText.
+ self
+ assert: (error includesSubstring: a)
+ description: 'Error message doesn''t include the expected value'.
+ self
+ assert: (error includesSubstring: b)
+ description: 'Error message doesn''t include the actual value'].!
- [self assert: a identical: b] on: TestFailure do: [:e | |error|
- error := e messageText.
- self assert: (error includesSubstring: a) description: 'Error message doesn''t include the expected value'.
- self assert: (error includesSubstring: b) description: 'Error message doesn''t include the expected value'].!

Item was changed:
  ----- Method: SUnitTest>>testAssertIdenticalDescription (in category 'tests') -----
  testAssertIdenticalDescription
+
+ | a b called |
- | a b |
  a := 'foo'.
  b := a copy.
+
+ self shouldnt: [self assert: a identical: a description: 'A description42'] raise: TestFailure.
+
+ self should: [self assert: a identical: b description: 'A description42'] raise: TestFailure.
+
+ [self assert: a identical: b description: 'A description42']
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A description42')
+ description: 'Error message doesn''t give you the description'].
+
+ called := false.
+ self shouldnt: [self assert: a identical: a description: [called := true]] raise: TestFailure.
+ self deny: called description: 'Description block was evaluated prematurely'.
+
+ [self assert: a identical: b description: ['A generated description' asUppercase]]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A generated description' asUppercase)
+ description: 'Error message doesn''t give you the generated description'].!
- self should: [self assert: a identical: b description: 'A desciption'] raise: TestFailure.
- [self assert: a identical: b description: 'A desciption'] on: TestFailure do: [:e | |error|
- error := e messageText.
- self assert: (error includesSubstring: 'A desciption') description: 'Error message doesn''t give you the description'].!

Item was changed:
  ----- Method: SUnitTest>>testAssertIdenticalWithEqualObjects (in category 'tests') -----
  testAssertIdenticalWithEqualObjects
+
  | a b |
  a := 'foo'.
  b := a copy.
+
  self should: [self assert: a identical: b] raise: TestFailure.
+
+ [self assert: a identical: b]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'not identical')
+ description: 'Error message doesn''t say the two things aren''t identical'].!
- [self assert: a identical: b] on: TestFailure do: [:e | |error|
- error := e messageText.
- self assert: (error includesSubstring: 'not identical') description: 'Error message doesn''t say the two things aren''t identical'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyEquals (in category 'tests') -----
+ testDenyEquals
+
+ | a b |
+ a := 'foo'.
+ b := 'bar'.
+
+ self shouldnt: [self deny: a equals: b] raise: TestFailure.
+
+ self should: [self deny: a equals: a copy] raise: TestFailure.
+
+ [self deny: a equals: a]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: a)
+ description: 'Error message doesn''t include the unexpected value'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyEqualsDescription (in category 'tests') -----
+ testDenyEqualsDescription
+
+ | a b called |
+ a := 'foo'.
+ b := 'bar'.
+
+ self shouldnt: [self deny: a equals: b description: 'A description42'] raise: TestFailure.
+
+ self should: [self deny: a equals: a copy description: 'A description42'] raise: TestFailure.
+
+ [self deny: a equals: a description: 'A description42']
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A description42')
+ description: 'Error message doesn''t give you the description'].
+
+ called := false.
+ self shouldnt: [self deny: a equals: b description: [called := true]] raise: TestFailure.
+ self deny: called description: 'Description block was evaluated prematurely'.
+
+ [self deny: a equals: a description: ['A generated description' asUppercase]]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A generated description' asUppercase)
+ description: 'Error message doesn''t give you the generated description'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyIdentical (in category 'tests') -----
+ testDenyIdentical
+
+ | a b |
+ a := 'foo'.
+ b := 'bar'.
+ self shouldnt: [self deny: a identical: b] raise: TestFailure.
+ self should: [self deny: a identical: a] raise: TestFailure.
+ [self deny: a identical: a]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: a)
+ description: 'Error message doesn''t include the unexpected value'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyIdenticalDescription (in category 'tests') -----
+ testDenyIdenticalDescription
+
+ | a b called |
+ a := 'foo'.
+ b := a copy.
+
+ self shouldnt: [self deny: a identical: b description: 'A description42'] raise: TestFailure.
+
+ self should: [self deny: a identical: a description: 'A description42'] raise: TestFailure.
+
+ [self deny: a identical: a description: 'A description42']
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A description42')
+ description: 'Error message doesn''t give you the description'].
+
+ called := false.
+ self shouldnt: [self deny: a identical: b description: [called := true]] raise: TestFailure.
+ self deny: called description: 'Description block was evaluated prematurely'.
+
+ [self deny: a identical: a description: ['A generated description' asUppercase]]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A generated description' asUppercase)
+ description: 'Error message doesn''t give you the description'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyIdenticalWithEqualObjects (in category 'tests') -----
+ testDenyIdenticalWithEqualObjects
+
+ | a b |
+ a := 'foo'.
+ b := a copy.
+ self should: [self deny: a identical: a] raise: TestFailure.
+ [self deny: a identical: a]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'identical')
+ description: 'Error message doesn''t say the two things are identical'].!

Item was changed:
  ----- Method: TestCase>>assert:equals: (in category 'asserting') -----
  assert: expected equals: actual
 
+ ^ self
+ assert: expected
+ equals: actual
+ description: nil
- ^self
- assert: expected = actual
- description: [ self comparingStringBetween: expected and: actual ]
  !

Item was changed:
  ----- Method: TestCase>>assert:equals:description: (in category 'asserting') -----
+ assert: expected equals: actual description: aStringOrBlock
- assert: expected equals: actual description: aString
 
+ ^ self
- ^self
  assert: expected = actual
+ description: [self
+ description: aStringOrBlock
+ with: (self comparingStringBetween: expected and: actual)]!
- description: [ aString , ': ', (self comparingStringBetween: expected and: actual) ]!

Item was changed:
  ----- Method: TestCase>>assert:identical: (in category 'asserting') -----
  assert: expected identical: actual
 
+ ^ self
+ assert: expected
+ identical: actual
+ description: nil!
- ^self
- assert: expected == actual
- description: [ self comparingStringBetweenIdentical: expected and: actual ]
- !

Item was changed:
  ----- Method: TestCase>>assert:identical:description: (in category 'asserting') -----
+ assert: expected identical: actual description: aStringOrBlock
- assert: expected identical: actual description: aString
 
+ ^ self
- ^self
  assert: expected == actual
+ description: [self
+ description: aStringOrBlock
+ with: (self comparingStringBetween: expected andIdentical: actual)]!
- description: [ aString , ': ', (self comparingStringBetweenIdentical: expected and: actual) ]!

Item was changed:
  ----- Method: TestCase>>comparingStringBetween:and: (in category 'private') -----
  comparingStringBetween: expected and: actual
+
+ ^ 'Expected {1} but was {2}.' translated
+ format: {
+ expected printStringLimitedTo: 10.
+ actual printStringLimitedTo: 10 }!
- ^ String streamContents: [:stream |
- stream
- nextPutAll: 'Expected ';
- nextPutAll: (expected printStringLimitedTo: 10);
- nextPutAll: ' but was ';
- nextPutAll: (actual printStringLimitedTo: 10);
- nextPutAll: '.'
- ]!

Item was added:
+ ----- Method: TestCase>>comparingStringBetween:andIdentical: (in category 'private') -----
+ comparingStringBetween: expected andIdentical: actual
+
+ ^ 'Expected {1} and actual {2} are not identical.' translated
+ format: {
+ expected printStringLimitedTo: 10.
+ actual printStringLimitedTo: 10 }!

Item was changed:
  ----- Method: TestCase>>comparingStringBetweenIdentical:and: (in category 'private') -----
  comparingStringBetweenIdentical: expected and: actual
+
+ self deprecated.
+ ^ self comparingStringBetween: expected andIdentical: actual!
- ^ 'Expected {1} and actual {2} are not identical.' format: {
- expected printStringLimitedTo: 10.
- actual printStringLimitedTo: 10.
- }!

Item was added:
+ ----- Method: TestCase>>comparingStringBetweenUnexpected:and: (in category 'private') -----
+ comparingStringBetweenUnexpected: unexpected and: actual
+
+ ^ 'Did not expect {1} but was {2}.' translated
+ format: {
+ unexpected printStringLimitedTo: 10.
+ actual printStringLimitedTo: 10 }!

Item was added:
+ ----- Method: TestCase>>comparingStringBetweenUnexpected:andIdentical: (in category 'private') -----
+ comparingStringBetweenUnexpected: expected andIdentical: actual
+
+ ^ 'Unexpected {1} and actual {2} are identical.' translated
+ format: {
+ expected printStringLimitedTo: 10.
+ actual printStringLimitedTo: 10 }!

Item was changed:
  ----- Method: TestCase>>deny:equals: (in category 'asserting') -----
  deny: unexpected equals: actual
 
+ ^ self
+ deny: unexpected
+ equals: actual
+ description: nil!
- ^self
- deny: unexpected = actual
- description: 'Actual equals unexpected'
- !

Item was added:
+ ----- Method: TestCase>>deny:equals:description: (in category 'asserting') -----
+ deny: unexpected equals: actual description: aStringOrBlock
+
+ ^ self
+ deny: unexpected = actual
+ description: [self
+ description: aStringOrBlock
+ with: (self comparingStringBetweenUnexpected: unexpected and: actual)]!

Item was added:
+ ----- Method: TestCase>>deny:identical: (in category 'asserting') -----
+ deny: unexpected identical: actual
+
+ ^ self
+ deny: unexpected
+ identical: actual
+ description: nil!

Item was added:
+ ----- Method: TestCase>>deny:identical:description: (in category 'asserting') -----
+ deny: unexpected identical: actual description: aStringOrBlock
+
+ ^ self
+ deny: unexpected == actual
+ description: [self
+ description: aStringOrBlock
+ with: (self comparingStringBetweenUnexpected: unexpected andIdentical: actual)]!

Item was added:
+ ----- Method: TestCase>>description:with: (in category 'private') -----
+ description: aStringOrBlock with: reason
+
+ | description |
+ description := aStringOrBlock value.
+ ^ description
+ ifNil: [reason]
+ ifNotNil: ['{1}: {2}' translated format: {description. reason}]!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: SUnit-ct.132.mcz

marcel.taeumel
Replaces SUnit-ct.126 which can be moved into the treated inbox.

And what about SUnit-ct.127?

Best,
Marcel

Am 06.03.2021 00:35:43 schrieb [hidden email] <[hidden email]>:

A new version of SUnit was added to project The Inbox:
http://source.squeak.org/inbox/SUnit-ct.132.mcz

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

Name: SUnit-ct.132
Author: ct
Time: 6 March 2021, 12:35:33.710439 am
UUID: 98d667df-13be-d148-9117-0b214c9adb3f
Ancestors: SUnit-nice.124

Refactors and completes equality assertions

- Add #deny:equals:description:, #deny:identical:, and #deny:identical:description:
- Revise default description message for #deny:equals:, aligning it to #assert:equals: description
- Make equality assertions capable of lazy descriptions (aStringOrBlock), aligning them to
#assert:description: etc.
- Add multilingual support for default description messages
- Some internal refactoring
- Improve test coverage of these assertions in SUnitTest

Thanks to Marcel for pointing to the idea!

Uploaded again to resolve conflicts with SUnit-pre.122 (recategorization). Replaces SUnit-ct.126 which can be moved into the treated inbox. :-)

=============== Diff against SUnit-nice.124 ===============

Item was added:
+ ----- Method: SUnitTest>>testAssertEquals (in category 'tests') -----
+ testAssertEquals
+
+ | a b |
+ a := 'foo'.
+ b := 'bar'.
+
+ self shouldnt: [self assert: a equals: a copy] raise: TestFailure.
+
+ self should: [self assert: a equals: b] raise: TestFailure.
+
+ [self assert: a equals: b]
+ on: TestFailure do: [:ex |
+ | error |
+ error := ex messageText.
+ self
+ assert: (error includesSubstring: a)
+ description: 'Error message doesn''t include the expected value'.
+ self
+ assert: (error includesSubstring: b)
+ description: 'Error message doesn''t include the actual value'].!

Item was added:
+ ----- Method: SUnitTest>>testAssertEqualsDescription (in category 'tests') -----
+ testAssertEqualsDescription
+
+ | a b called |
+ a := 'foo'.
+ b := 'bar'.
+
+ self shouldnt: [self assert: a equals: a copy description: 'A description42'] raise: TestFailure.
+
+ self should: [self assert: a equals: b description: 'A description42'] raise: TestFailure.
+
+ [self assert: a equals: b description: 'A description42']
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A description42')
+ description: 'Error message doesn''t give you the description'].
+
+ called := false.
+ self shouldnt: [self assert: a equals: a description: [called := true]] raise: TestFailure.
+ self deny: called description: 'Description block was evaluated prematurely'.
+
+ [self assert: a equals: b description: ['A generated description' asUppercase]]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A generated description' asUppercase)
+ description: 'Error message doesn''t give you the generated description'].!

Item was changed:
----- Method: SUnitTest>>testAssertIdentical (in category 'tests') -----
testAssertIdentical
+
| a b |
a := 'foo'.
b := 'bar'.
+
+ self shouldnt: [self assert: a identical: a] raise: TestFailure.
+
self should: [self assert: a identical: b] raise: TestFailure.
+
+ [self assert: a identical: b]
+ on: TestFailure do: [:ex |
+ | error |
+ error := ex messageText.
+ self
+ assert: (error includesSubstring: a)
+ description: 'Error message doesn''t include the expected value'.
+ self
+ assert: (error includesSubstring: b)
+ description: 'Error message doesn''t include the actual value'].!
- [self assert: a identical: b] on: TestFailure do: [:e | |error|
- error := e messageText.
- self assert: (error includesSubstring: a) description: 'Error message doesn''t include the expected value'.
- self assert: (error includesSubstring: b) description: 'Error message doesn''t include the expected value'].!

Item was changed:
----- Method: SUnitTest>>testAssertIdenticalDescription (in category 'tests') -----
testAssertIdenticalDescription
+
+ | a b called |
- | a b |
a := 'foo'.
b := a copy.
+
+ self shouldnt: [self assert: a identical: a description: 'A description42'] raise: TestFailure.
+
+ self should: [self assert: a identical: b description: 'A description42'] raise: TestFailure.
+
+ [self assert: a identical: b description: 'A description42']
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A description42')
+ description: 'Error message doesn''t give you the description'].
+
+ called := false.
+ self shouldnt: [self assert: a identical: a description: [called := true]] raise: TestFailure.
+ self deny: called description: 'Description block was evaluated prematurely'.
+
+ [self assert: a identical: b description: ['A generated description' asUppercase]]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A generated description' asUppercase)
+ description: 'Error message doesn''t give you the generated description'].!
- self should: [self assert: a identical: b description: 'A desciption'] raise: TestFailure.
- [self assert: a identical: b description: 'A desciption'] on: TestFailure do: [:e | |error|
- error := e messageText.
- self assert: (error includesSubstring: 'A desciption') description: 'Error message doesn''t give you the description'].!

Item was changed:
----- Method: SUnitTest>>testAssertIdenticalWithEqualObjects (in category 'tests') -----
testAssertIdenticalWithEqualObjects
+
| a b |
a := 'foo'.
b := a copy.
+
self should: [self assert: a identical: b] raise: TestFailure.
+
+ [self assert: a identical: b]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'not identical')
+ description: 'Error message doesn''t say the two things aren''t identical'].!
- [self assert: a identical: b] on: TestFailure do: [:e | |error|
- error := e messageText.
- self assert: (error includesSubstring: 'not identical') description: 'Error message doesn''t say the two things aren''t identical'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyEquals (in category 'tests') -----
+ testDenyEquals
+
+ | a b |
+ a := 'foo'.
+ b := 'bar'.
+
+ self shouldnt: [self deny: a equals: b] raise: TestFailure.
+
+ self should: [self deny: a equals: a copy] raise: TestFailure.
+
+ [self deny: a equals: a]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: a)
+ description: 'Error message doesn''t include the unexpected value'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyEqualsDescription (in category 'tests') -----
+ testDenyEqualsDescription
+
+ | a b called |
+ a := 'foo'.
+ b := 'bar'.
+
+ self shouldnt: [self deny: a equals: b description: 'A description42'] raise: TestFailure.
+
+ self should: [self deny: a equals: a copy description: 'A description42'] raise: TestFailure.
+
+ [self deny: a equals: a description: 'A description42']
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A description42')
+ description: 'Error message doesn''t give you the description'].
+
+ called := false.
+ self shouldnt: [self deny: a equals: b description: [called := true]] raise: TestFailure.
+ self deny: called description: 'Description block was evaluated prematurely'.
+
+ [self deny: a equals: a description: ['A generated description' asUppercase]]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A generated description' asUppercase)
+ description: 'Error message doesn''t give you the generated description'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyIdentical (in category 'tests') -----
+ testDenyIdentical
+
+ | a b |
+ a := 'foo'.
+ b := 'bar'.
+ self shouldnt: [self deny: a identical: b] raise: TestFailure.
+ self should: [self deny: a identical: a] raise: TestFailure.
+ [self deny: a identical: a]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: a)
+ description: 'Error message doesn''t include the unexpected value'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyIdenticalDescription (in category 'tests') -----
+ testDenyIdenticalDescription
+
+ | a b called |
+ a := 'foo'.
+ b := a copy.
+
+ self shouldnt: [self deny: a identical: b description: 'A description42'] raise: TestFailure.
+
+ self should: [self deny: a identical: a description: 'A description42'] raise: TestFailure.
+
+ [self deny: a identical: a description: 'A description42']
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A description42')
+ description: 'Error message doesn''t give you the description'].
+
+ called := false.
+ self shouldnt: [self deny: a identical: b description: [called := true]] raise: TestFailure.
+ self deny: called description: 'Description block was evaluated prematurely'.
+
+ [self deny: a identical: a description: ['A generated description' asUppercase]]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A generated description' asUppercase)
+ description: 'Error message doesn''t give you the description'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyIdenticalWithEqualObjects (in category 'tests') -----
+ testDenyIdenticalWithEqualObjects
+
+ | a b |
+ a := 'foo'.
+ b := a copy.
+ self should: [self deny: a identical: a] raise: TestFailure.
+ [self deny: a identical: a]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'identical')
+ description: 'Error message doesn''t say the two things are identical'].!

Item was changed:
----- Method: TestCase>>assert:equals: (in category 'asserting') -----
assert: expected equals: actual

+ ^ self
+ assert: expected
+ equals: actual
+ description: nil
- ^self
- assert: expected = actual
- description: [ self comparingStringBetween: expected and: actual ]
!

Item was changed:
----- Method: TestCase>>assert:equals:description: (in category 'asserting') -----
+ assert: expected equals: actual description: aStringOrBlock
- assert: expected equals: actual description: aString

+ ^ self
- ^self
assert: expected = actual
+ description: [self
+ description: aStringOrBlock
+ with: (self comparingStringBetween: expected and: actual)]!
- description: [ aString , ': ', (self comparingStringBetween: expected and: actual) ]!

Item was changed:
----- Method: TestCase>>assert:identical: (in category 'asserting') -----
assert: expected identical: actual

+ ^ self
+ assert: expected
+ identical: actual
+ description: nil!
- ^self
- assert: expected == actual
- description: [ self comparingStringBetweenIdentical: expected and: actual ]
- !

Item was changed:
----- Method: TestCase>>assert:identical:description: (in category 'asserting') -----
+ assert: expected identical: actual description: aStringOrBlock
- assert: expected identical: actual description: aString

+ ^ self
- ^self
assert: expected == actual
+ description: [self
+ description: aStringOrBlock
+ with: (self comparingStringBetween: expected andIdentical: actual)]!
- description: [ aString , ': ', (self comparingStringBetweenIdentical: expected and: actual) ]!

Item was changed:
----- Method: TestCase>>comparingStringBetween:and: (in category 'private') -----
comparingStringBetween: expected and: actual
+
+ ^ 'Expected {1} but was {2}.' translated
+ format: {
+ expected printStringLimitedTo: 10.
+ actual printStringLimitedTo: 10 }!
- ^ String streamContents: [:stream |
- stream
- nextPutAll: 'Expected ';
- nextPutAll: (expected printStringLimitedTo: 10);
- nextPutAll: ' but was ';
- nextPutAll: (actual printStringLimitedTo: 10);
- nextPutAll: '.'
- ]!

Item was added:
+ ----- Method: TestCase>>comparingStringBetween:andIdentical: (in category 'private') -----
+ comparingStringBetween: expected andIdentical: actual
+
+ ^ 'Expected {1} and actual {2} are not identical.' translated
+ format: {
+ expected printStringLimitedTo: 10.
+ actual printStringLimitedTo: 10 }!

Item was changed:
----- Method: TestCase>>comparingStringBetweenIdentical:and: (in category 'private') -----
comparingStringBetweenIdentical: expected and: actual
+
+ self deprecated.
+ ^ self comparingStringBetween: expected andIdentical: actual!
- ^ 'Expected {1} and actual {2} are not identical.' format: {
- expected printStringLimitedTo: 10.
- actual printStringLimitedTo: 10.
- }!

Item was added:
+ ----- Method: TestCase>>comparingStringBetweenUnexpected:and: (in category 'private') -----
+ comparingStringBetweenUnexpected: unexpected and: actual
+
+ ^ 'Did not expect {1} but was {2}.' translated
+ format: {
+ unexpected printStringLimitedTo: 10.
+ actual printStringLimitedTo: 10 }!

Item was added:
+ ----- Method: TestCase>>comparingStringBetweenUnexpected:andIdentical: (in category 'private') -----
+ comparingStringBetweenUnexpected: expected andIdentical: actual
+
+ ^ 'Unexpected {1} and actual {2} are identical.' translated
+ format: {
+ expected printStringLimitedTo: 10.
+ actual printStringLimitedTo: 10 }!

Item was changed:
----- Method: TestCase>>deny:equals: (in category 'asserting') -----
deny: unexpected equals: actual

+ ^ self
+ deny: unexpected
+ equals: actual
+ description: nil!
- ^self
- deny: unexpected = actual
- description: 'Actual equals unexpected'
- !

Item was added:
+ ----- Method: TestCase>>deny:equals:description: (in category 'asserting') -----
+ deny: unexpected equals: actual description: aStringOrBlock
+
+ ^ self
+ deny: unexpected = actual
+ description: [self
+ description: aStringOrBlock
+ with: (self comparingStringBetweenUnexpected: unexpected and: actual)]!

Item was added:
+ ----- Method: TestCase>>deny:identical: (in category 'asserting') -----
+ deny: unexpected identical: actual
+
+ ^ self
+ deny: unexpected
+ identical: actual
+ description: nil!

Item was added:
+ ----- Method: TestCase>>deny:identical:description: (in category 'asserting') -----
+ deny: unexpected identical: actual description: aStringOrBlock
+
+ ^ self
+ deny: unexpected == actual
+ description: [self
+ description: aStringOrBlock
+ with: (self comparingStringBetweenUnexpected: unexpected andIdentical: actual)]!

Item was added:
+ ----- Method: TestCase>>description:with: (in category 'private') -----
+ description: aStringOrBlock with: reason
+
+ | description |
+ description := aStringOrBlock value.
+ ^ description
+ ifNil: [reason]
+ ifNotNil: ['{1}: {2}' translated format: {description. reason}]!




Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: SUnit-ct.132.mcz

Christoph Thiede

And what about SUnit-ct.127?


Well, I think some people have mentioned good reasons against putting domain-specific things such as Regex into the central SUnit package, so it could go to the treated inbox, too, I guess.

But maybe we could support the regex assertion selectors as extension methods from the Regex package? Or would this be a bad idea because Regex would depend on SUnit then? Maybe a Regex-SUnit package, similar to ToolBuilder-SUnit? :-)

Best,
Christoph


Von: Squeak-dev <[hidden email]> im Auftrag von Taeumel, Marcel
Gesendet: Montag, 8. März 2021 11:09:08
An: squeak-dev
Betreff: Re: [squeak-dev] The Inbox: SUnit-ct.132.mcz
 
Replaces SUnit-ct.126 which can be moved into the treated inbox.

And what about SUnit-ct.127?

Best,
Marcel

Am 06.03.2021 00:35:43 schrieb [hidden email] <[hidden email]>:

A new version of SUnit was added to project The Inbox:
http://source.squeak.org/inbox/SUnit-ct.132.mcz

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

Name: SUnit-ct.132
Author: ct
Time: 6 March 2021, 12:35:33.710439 am
UUID: 98d667df-13be-d148-9117-0b214c9adb3f
Ancestors: SUnit-nice.124

Refactors and completes equality assertions

- Add #deny:equals:description:, #deny:identical:, and #deny:identical:description:
- Revise default description message for #deny:equals:, aligning it to #assert:equals: description
- Make equality assertions capable of lazy descriptions (aStringOrBlock), aligning them to
#assert:description: etc.
- Add multilingual support for default description messages
- Some internal refactoring
- Improve test coverage of these assertions in SUnitTest

Thanks to Marcel for pointing to the idea!

Uploaded again to resolve conflicts with SUnit-pre.122 (recategorization). Replaces SUnit-ct.126 which can be moved into the treated inbox. :-)

=============== Diff against SUnit-nice.124 ===============

Item was added:
+ ----- Method: SUnitTest>>testAssertEquals (in category 'tests') -----
+ testAssertEquals
+
+ | a b |
+ a := 'foo'.
+ b := 'bar'.
+
+ self shouldnt: [self assert: a equals: a copy] raise: TestFailure.
+
+ self should: [self assert: a equals: b] raise: TestFailure.
+
+ [self assert: a equals: b]
+ on: TestFailure do: [:ex |
+ | error |
+ error := ex messageText.
+ self
+ assert: (error includesSubstring: a)
+ description: 'Error message doesn''t include the expected value'.
+ self
+ assert: (error includesSubstring: b)
+ description: 'Error message doesn''t include the actual value'].!

Item was added:
+ ----- Method: SUnitTest>>testAssertEqualsDescription (in category 'tests') -----
+ testAssertEqualsDescription
+
+ | a b called |
+ a := 'foo'.
+ b := 'bar'.
+
+ self shouldnt: [self assert: a equals: a copy description: 'A description42'] raise: TestFailure.
+
+ self should: [self assert: a equals: b description: 'A description42'] raise: TestFailure.
+
+ [self assert: a equals: b description: 'A description42']
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A description42')
+ description: 'Error message doesn''t give you the description'].
+
+ called := false.
+ self shouldnt: [self assert: a equals: a description: [called := true]] raise: TestFailure.
+ self deny: called description: 'Description block was evaluated prematurely'.
+
+ [self assert: a equals: b description: ['A generated description' asUppercase]]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A generated description' asUppercase)
+ description: 'Error message doesn''t give you the generated description'].!

Item was changed:
----- Method: SUnitTest>>testAssertIdentical (in category 'tests') -----
testAssertIdentical
+
| a b |
a := 'foo'.
b := 'bar'.
+
+ self shouldnt: [self assert: a identical: a] raise: TestFailure.
+
self should: [self assert: a identical: b] raise: TestFailure.
+
+ [self assert: a identical: b]
+ on: TestFailure do: [:ex |
+ | error |
+ error := ex messageText.
+ self
+ assert: (error includesSubstring: a)
+ description: 'Error message doesn''t include the expected value'.
+ self
+ assert: (error includesSubstring: b)
+ description: 'Error message doesn''t include the actual value'].!
- [self assert: a identical: b] on: TestFailure do: [:e | |error|
- error := e messageText.
- self assert: (error includesSubstring: a) description: 'Error message doesn''t include the expected value'.
- self assert: (error includesSubstring: b) description: 'Error message doesn''t include the expected value'].!

Item was changed:
----- Method: SUnitTest>>testAssertIdenticalDescription (in category 'tests') -----
testAssertIdenticalDescription
+
+ | a b called |
- | a b |
a := 'foo'.
b := a copy.
+
+ self shouldnt: [self assert: a identical: a description: 'A description42'] raise: TestFailure.
+
+ self should: [self assert: a identical: b description: 'A description42'] raise: TestFailure.
+
+ [self assert: a identical: b description: 'A description42']
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A description42')
+ description: 'Error message doesn''t give you the description'].
+
+ called := false.
+ self shouldnt: [self assert: a identical: a description: [called := true]] raise: TestFailure.
+ self deny: called description: 'Description block was evaluated prematurely'.
+
+ [self assert: a identical: b description: ['A generated description' asUppercase]]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A generated description' asUppercase)
+ description: 'Error message doesn''t give you the generated description'].!
- self should: [self assert: a identical: b description: 'A desciption'] raise: TestFailure.
- [self assert: a identical: b description: 'A desciption'] on: TestFailure do: [:e | |error|
- error := e messageText.
- self assert: (error includesSubstring: 'A desciption') description: 'Error message doesn''t give you the description'].!

Item was changed:
----- Method: SUnitTest>>testAssertIdenticalWithEqualObjects (in category 'tests') -----
testAssertIdenticalWithEqualObjects
+
| a b |
a := 'foo'.
b := a copy.
+
self should: [self assert: a identical: b] raise: TestFailure.
+
+ [self assert: a identical: b]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'not identical')
+ description: 'Error message doesn''t say the two things aren''t identical'].!
- [self assert: a identical: b] on: TestFailure do: [:e | |error|
- error := e messageText.
- self assert: (error includesSubstring: 'not identical') description: 'Error message doesn''t say the two things aren''t identical'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyEquals (in category 'tests') -----
+ testDenyEquals
+
+ | a b |
+ a := 'foo'.
+ b := 'bar'.
+
+ self shouldnt: [self deny: a equals: b] raise: TestFailure.
+
+ self should: [self deny: a equals: a copy] raise: TestFailure.
+
+ [self deny: a equals: a]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: a)
+ description: 'Error message doesn''t include the unexpected value'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyEqualsDescription (in category 'tests') -----
+ testDenyEqualsDescription
+
+ | a b called |
+ a := 'foo'.
+ b := 'bar'.
+
+ self shouldnt: [self deny: a equals: b description: 'A description42'] raise: TestFailure.
+
+ self should: [self deny: a equals: a copy description: 'A description42'] raise: TestFailure.
+
+ [self deny: a equals: a description: 'A description42']
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A description42')
+ description: 'Error message doesn''t give you the description'].
+
+ called := false.
+ self shouldnt: [self deny: a equals: b description: [called := true]] raise: TestFailure.
+ self deny: called description: 'Description block was evaluated prematurely'.
+
+ [self deny: a equals: a description: ['A generated description' asUppercase]]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A generated description' asUppercase)
+ description: 'Error message doesn''t give you the generated description'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyIdentical (in category 'tests') -----
+ testDenyIdentical
+
+ | a b |
+ a := 'foo'.
+ b := 'bar'.
+ self shouldnt: [self deny: a identical: b] raise: TestFailure.
+ self should: [self deny: a identical: a] raise: TestFailure.
+ [self deny: a identical: a]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: a)
+ description: 'Error message doesn''t include the unexpected value'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyIdenticalDescription (in category 'tests') -----
+ testDenyIdenticalDescription
+
+ | a b called |
+ a := 'foo'.
+ b := a copy.
+
+ self shouldnt: [self deny: a identical: b description: 'A description42'] raise: TestFailure.
+
+ self should: [self deny: a identical: a description: 'A description42'] raise: TestFailure.
+
+ [self deny: a identical: a description: 'A description42']
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A description42')
+ description: 'Error message doesn''t give you the description'].
+
+ called := false.
+ self shouldnt: [self deny: a identical: b description: [called := true]] raise: TestFailure.
+ self deny: called description: 'Description block was evaluated prematurely'.
+
+ [self deny: a identical: a description: ['A generated description' asUppercase]]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'A generated description' asUppercase)
+ description: 'Error message doesn''t give you the description'].!

Item was added:
+ ----- Method: SUnitTest>>testDenyIdenticalWithEqualObjects (in category 'tests') -----
+ testDenyIdenticalWithEqualObjects
+
+ | a b |
+ a := 'foo'.
+ b := a copy.
+ self should: [self deny: a identical: a] raise: TestFailure.
+ [self deny: a identical: a]
+ on: TestFailure do: [:ex |
+ self
+ assert: (ex messageText includesSubstring: 'identical')
+ description: 'Error message doesn''t say the two things are identical'].!

Item was changed:
----- Method: TestCase>>assert:equals: (in category 'asserting') -----
assert: expected equals: actual

+ ^ self
+ assert: expected
+ equals: actual
+ description: nil
- ^self
- assert: expected = actual
- description: [ self comparingStringBetween: expected and: actual ]
!

Item was changed:
----- Method: TestCase>>assert:equals:description: (in category 'asserting') -----
+ assert: expected equals: actual description: aStringOrBlock
- assert: expected equals: actual description: aString

+ ^ self
- ^self
assert: expected = actual
+ description: [self
+ description: aStringOrBlock
+ with: (self comparingStringBetween: expected and: actual)]!
- description: [ aString , ': ', (self comparingStringBetween: expected and: actual) ]!

Item was changed:
----- Method: TestCase>>assert:identical: (in category 'asserting') -----
assert: expected identical: actual

+ ^ self
+ assert: expected
+ identical: actual
+ description: nil!
- ^self
- assert: expected == actual
- description: [ self comparingStringBetweenIdentical: expected and: actual ]
- !

Item was changed:
----- Method: TestCase>>assert:identical:description: (in category 'asserting') -----
+ assert: expected identical: actual description: aStringOrBlock
- assert: expected identical: actual description: aString

+ ^ self
- ^self
assert: expected == actual
+ description: [self
+ description: aStringOrBlock
+ with: (self comparingStringBetween: expected andIdentical: actual)]!
- description: [ aString , ': ', (self comparingStringBetweenIdentical: expected and: actual) ]!

Item was changed:
----- Method: TestCase>>comparingStringBetween:and: (in category 'private') -----
comparingStringBetween: expected and: actual
+
+ ^ 'Expected {1} but was {2}.' translated
+ format: {
+ expected printStringLimitedTo: 10.
+ actual printStringLimitedTo: 10 }!
- ^ String streamContents: [:stream |
- stream
- nextPutAll: 'Expected ';
- nextPutAll: (expected printStringLimitedTo: 10);
- nextPutAll: ' but was ';
- nextPutAll: (actual printStringLimitedTo: 10);
- nextPutAll: '.'
- ]!

Item was added:
+ ----- Method: TestCase>>comparingStringBetween:andIdentical: (in category 'private') -----
+ comparingStringBetween: expected andIdentical: actual
+
+ ^ 'Expected {1} and actual {2} are not identical.' translated
+ format: {
+ expected printStringLimitedTo: 10.
+ actual printStringLimitedTo: 10 }!

Item was changed:
----- Method: TestCase>>comparingStringBetweenIdentical:and: (in category 'private') -----
comparingStringBetweenIdentical: expected and: actual
+
+ self deprecated.
+ ^ self comparingStringBetween: expected andIdentical: actual!
- ^ 'Expected {1} and actual {2} are not identical.' format: {
- expected printStringLimitedTo: 10.
- actual printStringLimitedTo: 10.
- }!

Item was added:
+ ----- Method: TestCase>>comparingStringBetweenUnexpected:and: (in category 'private') -----
+ comparingStringBetweenUnexpected: unexpected and: actual
+
+ ^ 'Did not expect {1} but was {2}.' translated
+ format: {
+ unexpected printStringLimitedTo: 10.
+ actual printStringLimitedTo: 10 }!

Item was added:
+ ----- Method: TestCase>>comparingStringBetweenUnexpected:andIdentical: (in category 'private') -----
+ comparingStringBetweenUnexpected: expected andIdentical: actual
+
+ ^ 'Unexpected {1} and actual {2} are identical.' translated
+ format: {
+ expected printStringLimitedTo: 10.
+ actual printStringLimitedTo: 10 }!

Item was changed:
----- Method: TestCase>>deny:equals: (in category 'asserting') -----
deny: unexpected equals: actual

+ ^ self
+ deny: unexpected
+ equals: actual
+ description: nil!
- ^self
- deny: unexpected = actual
- description: 'Actual equals unexpected'
- !

Item was added:
+ ----- Method: TestCase>>deny:equals:description: (in category 'asserting') -----
+ deny: unexpected equals: actual description: aStringOrBlock
+
+ ^ self
+ deny: unexpected = actual
+ description: [self
+ description: aStringOrBlock
+ with: (self comparingStringBetweenUnexpected: unexpected and: actual)]!

Item was added:
+ ----- Method: TestCase>>deny:identical: (in category 'asserting') -----
+ deny: unexpected identical: actual
+
+ ^ self
+ deny: unexpected
+ identical: actual
+ description: nil!

Item was added:
+ ----- Method: TestCase>>deny:identical:description: (in category 'asserting') -----
+ deny: unexpected identical: actual description: aStringOrBlock
+
+ ^ self
+ deny: unexpected == actual
+ description: [self
+ description: aStringOrBlock
+ with: (self comparingStringBetweenUnexpected: unexpected andIdentical: actual)]!

Item was added:
+ ----- Method: TestCase>>description:with: (in category 'private') -----
+ description: aStringOrBlock with: reason
+
+ | description |
+ description := aStringOrBlock value.
+ ^ description
+ ifNil: [reason]
+ ifNotNil: ['{1}: {2}' translated format: {description. reason}]!




Carpe Squeak!