33 #superclass : ' TestCase' ,
44 #instVars : [
55 ' presenter' ,
6- ' imageDir' ,
76 ' process' ,
8- ' runCommand' ,
9- ' image' ,
10- ' recreateCommand' ,
11- ' application'
7+ ' image'
128 ],
139 #category : ' PharoLauncher-Tests-Commands' ,
1410 #package : ' PharoLauncher-Tests-Commands'
@@ -22,6 +18,7 @@ PhLLaunchImageCommandTest class >> resources [
2218
2319{ #category : ' helper' }
2420PhLLaunchImageCommandTest >> addInitializationScriptToImage [
21+
2522 image initializationScript: self initScript
2623]
2724
@@ -41,7 +38,10 @@ PhLLaunchImageCommandTest >> initScript [
4138PhLLaunchImageCommandTest >> launchImage [
4239
4340 process ifNotNil: [ self error: ' Currently one execution of image per test case.' ].
44- process := runCommand execute
41+
42+ process := PhLLaunchImageCommand new
43+ context: presenter;
44+ execute
4545]
4646
4747{ #category : ' private' }
@@ -52,7 +52,9 @@ PhLLaunchImageCommandTest >> performTest [
5252
5353{ #category : ' helper' }
5454PhLLaunchImageCommandTest >> recreateImage [
55- recreateCommand execute.
55+ PhLRecreateImageCommand new
56+ context: presenter;
57+ execute.
5658 self selectImage.
5759 ^ presenter selectedImages anyOne
5860]
@@ -64,37 +66,29 @@ PhLLaunchImageCommandTest >> selectImage [
6466 selectImageAt: 1
6567]
6668
69+ { #category : ' running' }
70+ PhLLaunchImageCommandTest >> setImageOriginTemplateAndLaunchConfiguration [
71+ image
72+ originTemplate:
73+ (presenter application templateRepository createLocalTemplateNamed: ' testTemplate' );
74+ launchConfigurations:
75+ { (PhLTestLaunchConfiguration withImage: image) }
76+ ]
77+
6778{ #category : ' running' }
6879PhLLaunchImageCommandTest >> setUp [
6980
7081 super setUp.
7182
7283 presenter := PhLTestImagesPresenter new .
73- imageDir := FileLocator temp
74- / ' pharo-launcher-tests-launch-image-command'
75- , UUID new asString.
76- imageDir ensureCreateDirectory.
77-
78- runCommand := PhLLaunchImageCommand new .
79- runCommand context: presenter.
80- recreateCommand := PhLRecreateImageCommand new .
81- recreateCommand context: presenter.
82-
8384 image := presenter singleImage.
84- image versionFile writeStreamDo: [ :stream |
85- SystemVersion current major asString putOn: stream.
86- SystemVersion current minor asString putOn: stream ].
87- image
88- originTemplate:
89- (presenter application templateRepository createLocalTemplateNamed: ' testTemplate' );
90- launchConfigurations:
91- { (PhLTestLaunchConfiguration withImage: image) }
85+ self setImageOriginTemplateAndLaunchConfiguration.
86+ presenter updateImageDetails.
9287]
9388
9489{ #category : ' running' }
9590PhLLaunchImageCommandTest >> tearDown [
9691
97- imageDir ifNotNil: [ imageDir ensureDeleteAll ].
9892 (process isNotNil and : [ process isRunning ])
9993 ifTrue: [ process terminate ].
10094 super tearDown
@@ -121,13 +115,13 @@ PhLLaunchImageCommandTest >> testCanLaunchImage [
121115 self timeLimit: 30 seconds.
122116
123117 self useNewStableImageAndSetItAsSelectedImageInImagesPresenter.
124- image addLaunchConfiguration:
125- ( image defaultLaunchConfiguration asLaunchConfiguration
118+ image launchConfigurations:
119+ { image defaultLaunchConfiguration asLaunchConfiguration
126120 vmArguments: #('--headless') ; " be able to run test without X session"
127121 imageArguments: #('--no-quit') ;
128- yourself ) .
122+ yourself } .
129123
130- process := runCommand execute .
124+ self launchImage .
131125 2 seconds wait. " let time to the image to be opened by the VM"
132126
133127 self assert: process isRunning.
@@ -136,8 +130,8 @@ PhLLaunchImageCommandTest >> testCanLaunchImage [
136130{ #category : ' tests' }
137131PhLLaunchImageCommandTest >> testExecutingImageWithScriptShouldSetFlagToShouldNotRun [
138132
139- self useNewStableImageAndSetItAsSelectedImageInImagesPresenter.
140133 self addInitializationScriptToImage.
134+ presenter selectLaunchConfiguration: image launchConfigurations first.
141135 self launchImage.
142136
143137 self denyApplicationHasError.
@@ -148,9 +142,6 @@ PhLLaunchImageCommandTest >> testExecutingImageWithScriptShouldSetFlagToShouldNo
148142PhLLaunchImageCommandTest >> testLaunchImageShouldRaiseExceptionWhenNoPharoVersionFile [
149143
150144 image versionFile ensureDelete.
151- presenter
152- unselectAll;
153- selection: { image }.
154145
155146 self
156147 should: [ image launch ]
@@ -161,7 +152,9 @@ PhLLaunchImageCommandTest >> testLaunchImageShouldRaiseExceptionWhenNoPharoVersi
161152PhLLaunchImageCommandTest >> testRecreateAnImageWithoutOpeningItShouldStillExecuteScript [
162153
163154 | recreatedImage |
155+
164156 self addInitializationScriptToImage.
157+
165158 recreatedImage := self recreateImage.
166159
167160 self assert: recreatedImage shouldRunInitializationScript.
@@ -171,15 +164,36 @@ PhLLaunchImageCommandTest >> testRecreateAnImageWithoutOpeningItShouldStillExecu
171164PhLLaunchImageCommandTest >> testRecreateAnOpenedImageShouldStillExecuteScript [
172165
173166 | recreatedImage |
167+
174168 self addInitializationScriptToImage.
175169 self launchImage.
176170 recreatedImage := self recreateImage.
177-
171+
178172 self assert: recreatedImage shouldRunInitializationScript
179173]
180174
181175{ #category : ' tests' }
182- PhLLaunchImageCommandTest >> testRunningAnImageRemovesTheInitializationScript [
176+ PhLLaunchImageCommandTest >> testRecreatingAnImageKeepsTheInitializationScript [
177+
178+ self addInitializationScriptToImage.
179+
180+ image := self recreateImage.
181+
182+ self assert: image initializationScript path equals: self initScript path
183+ ]
184+
185+ { #category : ' tests' }
186+ PhLLaunchImageCommandTest >> testRecreatingAnImageKeepsTheInitializationScriptOk [
187+
188+ image := PhLPharoStableImageResource current newRepositoryWithImage.
189+ image
190+ originTemplate:
191+ (presenter application templateRepository createLocalTemplateNamed: ' testTemplate' ).
192+ presenter model: (PhLDirectoryBasedImageRepository forDirectory: image file parent parent).
193+ presenter refresh.
194+ presenter selectImage: image.
195+ image := presenter selectedImages first.
196+
183197 self addInitializationScriptToImage.
184198 image := self recreateImage.
185199
0 commit comments