-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCommandLineTestingStrategy.ns
112 lines (106 loc) · 4.46 KB
/
CommandLineTestingStrategy.ns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Newspeak3
'Newspeak'
class CommandLineTestingStrategy platform: platform newShell: newShell appPackager: appPkgr path: cmdPath options: options = (
(* A compiler testing strategy that compiles classes to be tested to a Dart/JS source file and then runs the Dart VM/node.js on the file.
Derived from InImageNSCompilerTestingStrategy
Copyright 2011 Vassili Bykov
Copyright 2012 Google Inc.
Copyright 2013 Ryan Macnak
Licensed under the Apache License, Version 2.0 (the ''License''); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 *)
|
private FileDirectory = platform squeak FileDirectory.
private CommandError = newShell CommandError.
protected cmd = newShell perform: cmdPath.
protected options = options.
protected namespace = platform squeak NewspeakGlobalState ide namespacing Root.
protected appPackager = appPkgr.
|assert: [platform squeak FileDirectory default fileExists: cmdPath]
message: 'Cannot find ', cmdPath) (
assertionFailedClassSource ^<String> = (
^'class AssertionFailed description: d = Error description: d () () : (
public signal: message = ( ^(self description: message) signal ) )'
)
assertionMethodsSource ^<String> = (
^'
assert: aBlockOrValue = (
aBlockOrValue isClosure
ifTrue: [aBlockOrValue value ifFalse: [AssertionFailed signal: ''Assertion failed'']]
ifFalse: [aBlockOrValue ifFalse: [AssertionFailed signal: ''Assertion failed'']]
)
assert: aBlockOrValue description: descriptionText = (
aBlockOrValue isClosure
ifTrue: [aBlockOrValue value ifFalse: [AssertionFailed signal: ''Assertion failed: '', descriptionText]]
ifFalse: [aBlockOrValue ifFalse: [AssertionFailed signal: ''Assertion failed: '', descriptionText]]
)
assert: aBlockOrValue descriptionBlock: descriptionBlock = (
aBlockOrValue isClosure
ifTrue: [aBlockOrValue value ifFalse: [AssertionFailed signal: descriptionBlock value]]
ifFalse: [aBlockOrValue ifFalse: [AssertionFailed signal: descriptionBlock value]]
)
assert: anObject equals: expectedObject = (
assert: anObject = expectedObject descriptionBlock:
[''Equality assertion failed; expected: '',
expectedObject printString,
'', was: '',
anObject printString]
)
assertList: anObject equals: expectedObject = (
assert: anObject size equals: expectedObject size.
1 to: expectedObject size do:
[:index | assert: (anObject at: index) equals: (expectedObject at: index)].
)
assert: aBlock signals: errorClass = (
assert: aBlock signals: errorClass description: ''Exception expected but not signaled''
)
assert: aBlock signals: errorClass description: descriptionText = (
aBlock on: errorClass do: [:ex | ^self].
AssertionFailed signal: descriptionText
)'
)
runMethodSource ^<String> = (
^'
public run = (
(*[*)(SampleTest test: Sample) test. print: ''Success''(*]
on: Error do: [:ex |
(ex class = AssertionFailed)
ifTrue: [print: ''Failure: '', ex description]
ifFalse: [print: ''Error: '', ex description]]*)
)'
)
sourceOfModuleWithSample: sampleClassSource <String> test: testerClassSource <String> ^<String> = (
| source |
source:: (String new: 400) writeStream.
source
nextPutAll: 'Newspeak3'; cr;
nextPutAll: 'class Test packageUsing: ns = ( |
| ) ('; cr;
nextPutAll: assertionFailedClassSource; cr;
nextPutAll: sampleClassSource; cr;
nextPutAll: testerClassSource; cr;
nextPutAll: assertionMethodsSource; cr;
nextPutAll: runMethodSource; cr;
nextPutAll: 'public main: p args: argv = (self run) '; cr;
nextPutAll: '):( main = (self new run) )'.
^source contents
)
public test: sampleClassSource <String> with: testClassSource <String> ifFailure: failureBlock <[:String]> ifError: errorBlock <[:String]> = (
|
testSource = sourceOfModuleWithSample: sampleClassSource test: testClassSource.
fn = 'test', testSource hash printString.
stm
result
|
appPackager outDirectory: FileDirectory root / 'tmp'.
appPackager outDirectory assureExistence.
[stm:: appPackager outDirectory forceNewFileNamed: fn.
stm lineEndConvention: #lf.
stm nextPutAll: (String streamContents: [:bufferStream |
appPackager compileSource: testSource usingNamespace: namespace to: bufferStream])]
ensure: [ stm ifNotNil: [ stm flush; close ] ].
result:: (cmd with: options, {(appPackager outDirectory / fn) fullName}) asString.
(result includesSubString: 'Success') ifTrue: [^self].
(result includesSubString: 'Failure') ifTrue: [^failureBlock value: result].
^errorBlock value: result
)
) : (
)