Browse Source

More SUnit tests

Nicolas Petton 12 years ago
parent
commit
64855b5dce
3 changed files with 297 additions and 17 deletions
  1. 94 0
      js/SUnit-Tests.deploy.js
  2. 136 6
      js/SUnit-Tests.js
  3. 67 11
      st/SUnit-Tests.st

+ 94 - 0
js/SUnit-Tests.deploy.js

@@ -1,4 +1,98 @@
 smalltalk.addPackage('SUnit-Tests', {});
+smalltalk.addClass('ExampleSetTest', smalltalk.TestCase, ['empty', 'full'], 'SUnit-Tests');
+smalltalk.addMethod(
+"_setUp",
+smalltalk.method({
+selector: "setUp",
+fn: function (){
+var self=this;
+self["@empty"]=smalltalk.send((smalltalk.Set || Set),"_new",[]);
+self["@full"]=smalltalk.send((smalltalk.Set || Set),"_with_with_",[(5),smalltalk.symbolFor("abc")]);
+return self}
+}),
+smalltalk.ExampleSetTest);
+
+smalltalk.addMethod(
+"_testAdd",
+smalltalk.method({
+selector: "testAdd",
+fn: function (){
+var self=this;
+smalltalk.send(self["@empty"],"_add_",[(5)]);
+smalltalk.send(self,"_assert_",[smalltalk.send(self["@empty"],"_includes_",[(5)])]);
+return self}
+}),
+smalltalk.ExampleSetTest);
+
+smalltalk.addMethod(
+"_testGrow",
+smalltalk.method({
+selector: "testGrow",
+fn: function (){
+var self=this;
+smalltalk.send(self["@empty"],"_addAll_",[smalltalk.send((1),"_to_",[(100)])]);
+smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@empty"],"_size",[]),"__eq",[(100)])]);
+return self}
+}),
+smalltalk.ExampleSetTest);
+
+smalltalk.addMethod(
+"_testIllegal",
+smalltalk.method({
+selector: "testIllegal",
+fn: function (){
+var self=this;
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send(self["@empty"],"_at_",[(5)]);
+}),(smalltalk.Error || Error)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send(self["@empty"],"_at_put_",[(5),smalltalk.symbolFor("abc")]);
+}),(smalltalk.Error || Error)]);
+return self}
+}),
+smalltalk.ExampleSetTest);
+
+smalltalk.addMethod(
+"_testIncludes",
+smalltalk.method({
+selector: "testIncludes",
+fn: function (){
+var self=this;
+smalltalk.send(self,"_assert_",[smalltalk.send(self["@full"],"_includes_",[(5)])]);
+smalltalk.send(self,"_assert_",[smalltalk.send(self["@full"],"_includes_",[smalltalk.symbolFor("abc")])]);
+return self}
+}),
+smalltalk.ExampleSetTest);
+
+smalltalk.addMethod(
+"_testOccurrences",
+smalltalk.method({
+selector: "testOccurrences",
+fn: function (){
+var self=this;
+smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@empty"],"_occurrencesOf_",[(0)]),"__eq",[(0)])]);
+smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@full"],"_occurrencesOf_",[(5)]),"__eq",[(1)])]);
+smalltalk.send(self["@full"],"_add_",[(5)]);
+smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@full"],"_occurrencesOf_",[(5)]),"__eq",[(1)])]);
+return self}
+}),
+smalltalk.ExampleSetTest);
+
+smalltalk.addMethod(
+"_testRemove",
+smalltalk.method({
+selector: "testRemove",
+fn: function (){
+var self=this;
+smalltalk.send(self["@full"],"_remove_",[(5)]);
+smalltalk.send(self,"_assert_",[smalltalk.send(self["@full"],"_includes_",[smalltalk.symbolFor("abc")])]);
+smalltalk.send(self,"_deny_",[smalltalk.send(self["@full"],"_includes_",[(5)])]);
+return self}
+}),
+smalltalk.ExampleSetTest);
+
+
+
 smalltalk.addClass('SUnitAsyncTest', smalltalk.TestCase, ['flag'], 'SUnit-Tests');
 smalltalk.addMethod(
 "_fakeError",

+ 136 - 6
js/SUnit-Tests.js

@@ -1,10 +1,140 @@
 smalltalk.addPackage('SUnit-Tests', {});
+smalltalk.addClass('ExampleSetTest', smalltalk.TestCase, ['empty', 'full'], 'SUnit-Tests');
+smalltalk.ExampleSetTest.comment="ExampleSetTest is taken from Pharo 1.4.\x0a\x0aTHe purpose of this class is to demonstrate a simple use case of the test framework."
+smalltalk.addMethod(
+"_setUp",
+smalltalk.method({
+selector: "setUp",
+category: 'running',
+fn: function (){
+var self=this;
+self["@empty"]=smalltalk.send((smalltalk.Set || Set),"_new",[]);
+self["@full"]=smalltalk.send((smalltalk.Set || Set),"_with_with_",[(5),smalltalk.symbolFor("abc")]);
+return self},
+args: [],
+source: "setUp\x0a\x09empty := Set new.\x0a\x09full := Set with: 5 with: #abc",
+messageSends: ["new", "with:with:"],
+referencedClasses: ["Set"]
+}),
+smalltalk.ExampleSetTest);
+
+smalltalk.addMethod(
+"_testAdd",
+smalltalk.method({
+selector: "testAdd",
+category: 'tests',
+fn: function (){
+var self=this;
+smalltalk.send(self["@empty"],"_add_",[(5)]);
+smalltalk.send(self,"_assert_",[smalltalk.send(self["@empty"],"_includes_",[(5)])]);
+return self},
+args: [],
+source: "testAdd\x0a\x09empty add: 5.\x0a\x09self assert: (empty includes: 5)",
+messageSends: ["add:", "assert:", "includes:"],
+referencedClasses: []
+}),
+smalltalk.ExampleSetTest);
+
+smalltalk.addMethod(
+"_testGrow",
+smalltalk.method({
+selector: "testGrow",
+category: 'tests',
+fn: function (){
+var self=this;
+smalltalk.send(self["@empty"],"_addAll_",[smalltalk.send((1),"_to_",[(100)])]);
+smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@empty"],"_size",[]),"__eq",[(100)])]);
+return self},
+args: [],
+source: "testGrow\x0a\x09empty addAll: (1 to: 100).\x0a\x09self assert: empty size = 100",
+messageSends: ["addAll:", "to:", "assert:", "=", "size"],
+referencedClasses: []
+}),
+smalltalk.ExampleSetTest);
+
+smalltalk.addMethod(
+"_testIllegal",
+smalltalk.method({
+selector: "testIllegal",
+category: 'tests',
+fn: function (){
+var self=this;
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send(self["@empty"],"_at_",[(5)]);
+}),(smalltalk.Error || Error)]);
+smalltalk.send(self,"_should_raise_",[(function(){
+return smalltalk.send(self["@empty"],"_at_put_",[(5),smalltalk.symbolFor("abc")]);
+}),(smalltalk.Error || Error)]);
+return self},
+args: [],
+source: "testIllegal\x0a\x09self \x0a\x09\x09should: [empty at: 5] \x0a\x09\x09raise: Error.\x0a\x09self \x0a\x09\x09should: [empty at: 5 put: #abc] \x0a\x09\x09raise: Error",
+messageSends: ["should:raise:", "at:", "at:put:"],
+referencedClasses: ["Error"]
+}),
+smalltalk.ExampleSetTest);
+
+smalltalk.addMethod(
+"_testIncludes",
+smalltalk.method({
+selector: "testIncludes",
+category: 'tests',
+fn: function (){
+var self=this;
+smalltalk.send(self,"_assert_",[smalltalk.send(self["@full"],"_includes_",[(5)])]);
+smalltalk.send(self,"_assert_",[smalltalk.send(self["@full"],"_includes_",[smalltalk.symbolFor("abc")])]);
+return self},
+args: [],
+source: "testIncludes\x0a\x09self assert: (full includes: 5).\x0a\x09self assert: (full includes: #abc)",
+messageSends: ["assert:", "includes:"],
+referencedClasses: []
+}),
+smalltalk.ExampleSetTest);
+
+smalltalk.addMethod(
+"_testOccurrences",
+smalltalk.method({
+selector: "testOccurrences",
+category: 'tests',
+fn: function (){
+var self=this;
+smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@empty"],"_occurrencesOf_",[(0)]),"__eq",[(0)])]);
+smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@full"],"_occurrencesOf_",[(5)]),"__eq",[(1)])]);
+smalltalk.send(self["@full"],"_add_",[(5)]);
+smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(self["@full"],"_occurrencesOf_",[(5)]),"__eq",[(1)])]);
+return self},
+args: [],
+source: "testOccurrences\x0a\x09self assert: (empty occurrencesOf: 0) = 0.\x0a\x09self assert: (full occurrencesOf: 5) = 1.\x0a\x09full add: 5.\x0a\x09self assert: (full occurrencesOf: 5) = 1",
+messageSends: ["assert:", "=", "occurrencesOf:", "add:"],
+referencedClasses: []
+}),
+smalltalk.ExampleSetTest);
+
+smalltalk.addMethod(
+"_testRemove",
+smalltalk.method({
+selector: "testRemove",
+category: 'tests',
+fn: function (){
+var self=this;
+smalltalk.send(self["@full"],"_remove_",[(5)]);
+smalltalk.send(self,"_assert_",[smalltalk.send(self["@full"],"_includes_",[smalltalk.symbolFor("abc")])]);
+smalltalk.send(self,"_deny_",[smalltalk.send(self["@full"],"_includes_",[(5)])]);
+return self},
+args: [],
+source: "testRemove\x0a\x09full remove: 5.\x0a\x09self assert: (full includes: #abc).\x0a\x09self deny: (full includes: 5)",
+messageSends: ["remove:", "assert:", "includes:", "deny:"],
+referencedClasses: []
+}),
+smalltalk.ExampleSetTest);
+
+
+
 smalltalk.addClass('SUnitAsyncTest', smalltalk.TestCase, ['flag'], 'SUnit-Tests');
 smalltalk.addMethod(
 "_fakeError",
 smalltalk.method({
 selector: "fakeError",
-category: 'tests',
+category: 'helpers',
 fn: function (){
 var self=this;
 self["@flag"]="bad";
@@ -26,7 +156,7 @@ smalltalk.addMethod(
 "_fakeErrorFailingInTearDown",
 smalltalk.method({
 selector: "fakeErrorFailingInTearDown",
-category: 'tests',
+category: 'helpers',
 fn: function (){
 var self=this;
 self["@flag"]="bad";
@@ -46,7 +176,7 @@ smalltalk.addMethod(
 "_fakeFailure",
 smalltalk.method({
 selector: "fakeFailure",
-category: 'tests',
+category: 'helpers',
 fn: function (){
 var self=this;
 self["@flag"]="bad";
@@ -68,7 +198,7 @@ smalltalk.addMethod(
 "_fakeMultipleGraceTimeFailing",
 smalltalk.method({
 selector: "fakeMultipleGraceTimeFailing",
-category: 'tests',
+category: 'helpers',
 fn: function (){
 var self=this;
 smalltalk.send(self,"_graceTime_",[(100)]);
@@ -90,7 +220,7 @@ smalltalk.addMethod(
 "_fakeMultipleGraceTimePassing",
 smalltalk.method({
 selector: "fakeMultipleGraceTimePassing",
-category: 'tests',
+category: 'helpers',
 fn: function (){
 var self=this;
 smalltalk.send(self,"_graceTime_",[(10)]);
@@ -112,7 +242,7 @@ smalltalk.addMethod(
 "_fakeTimeout",
 smalltalk.method({
 selector: "fakeTimeout",
-category: 'tests',
+category: 'helpers',
 fn: function (){
 var self=this;
 smalltalk.send(self,"_graceTime_",[(4)]);

+ 67 - 11
st/SUnit-Tests.st

@@ -1,25 +1,63 @@
 Smalltalk current createPackage: 'SUnit-Tests' properties: #{}!
-TestCase subclass: #SUnitAsyncTest
-	instanceVariableNames: 'flag'
+TestCase subclass: #ExampleSetTest
+	instanceVariableNames: 'empty full'
 	package: 'SUnit-Tests'!
+!ExampleSetTest commentStamp!
+ExampleSetTest is taken from Pharo 1.4.
 
-!SUnitAsyncTest methodsFor: 'private'!
+THe purpose of this class is to demonstrate a simple use case of the test framework.!
 
-sortedSelectors: aCollection
-	^(aCollection collect: [:each | each selector]) sorted
+!ExampleSetTest methodsFor: 'running'!
+
+setUp
+	empty := Set new.
+	full := Set with: 5 with: #abc
 ! !
 
-!SUnitAsyncTest methodsFor: 'running'!
+!ExampleSetTest methodsFor: 'tests'!
 
-setUp
-	flag := 'ok'
+testAdd
+	empty add: 5.
+	self assert: (empty includes: 5)
 !
 
-tearDown
-	self assert: 'ok' equals: flag
+testGrow
+	empty addAll: (1 to: 100).
+	self assert: empty size = 100
+!
+
+testIllegal
+	self 
+		should: [empty at: 5] 
+		raise: Error.
+	self 
+		should: [empty at: 5 put: #abc] 
+		raise: Error
+!
+
+testIncludes
+	self assert: (full includes: 5).
+	self assert: (full includes: #abc)
+!
+
+testOccurrences
+	self assert: (empty occurrencesOf: 0) = 0.
+	self assert: (full occurrencesOf: 5) = 1.
+	full add: 5.
+	self assert: (full occurrencesOf: 5) = 1
+!
+
+testRemove
+	full remove: 5.
+	self assert: (full includes: #abc).
+	self deny: (full includes: 5)
 ! !
 
-!SUnitAsyncTest methodsFor: 'tests'!
+TestCase subclass: #SUnitAsyncTest
+	instanceVariableNames: 'flag'
+	package: 'SUnit-Tests'!
+
+!SUnitAsyncTest methodsFor: 'helpers'!
 
 fakeError
 	flag := 'bad'.
@@ -58,8 +96,26 @@ fakeMultipleGraceTimePassing
 fakeTimeout
 	self graceTime: 4.
     (self async: [ self finished ]) valueWithTimeout: 5
+! !
+
+!SUnitAsyncTest methodsFor: 'private'!
+
+sortedSelectors: aCollection
+	^(aCollection collect: [:each | each selector]) sorted
+! !
+
+!SUnitAsyncTest methodsFor: 'running'!
+
+setUp
+	flag := 'ok'
 !
 
+tearDown
+	self assert: 'ok' equals: flag
+! !
+
+!SUnitAsyncTest methodsFor: 'tests'!
+
 testAsyncErrorsAndFailures
 	| suite runner result assertBlock |
 	suite := #('fakeError' 'fakeErrorFailingInTearDown' 'fakeFailure' 'testPass') collect: [ :each | self class selector: each ].