@@ -25,17 +25,6 @@ from wake import _
2525# If tests/ is used externally, the topic is empty and the invoking wake is tested instead.
2626export topic wakeTestBinary: Unit => Result (Pair String (List Path)) Error
2727
28- # We need to handle the fact that sometimes tests are invoked from within /tests
29- # and sometimes they're invoked from outside of /tests. Additionally only when
30- # we have access to build_wake in our test environment can we figure out how
31- # to build the wake unit tests that we want to run. Since test_wake cannot depend
32- # on build_wake we instead make a topic that build_wake can publish to. This topic
33- # will be empty if your workspace starts in /tests but have the proper function
34- # in it if you start from one directory out. This means we can just have this test
35- # fail if it isn't run from the proper place. It's hacky but it works around
36- # the way we test currently.
37- export topic wakeUnitTestBinary: (variant: Pair String String) => Result (List Path) Error
38-
3928def wakeToTestDir Unit = match (subscribe wakeTestBinary)
4029 buildTestWake, Nil ->
4130 require Pass (Pair path visible) = buildTestWake Unit
@@ -44,17 +33,6 @@ def wakeToTestDir Unit = match (subscribe wakeTestBinary)
4433 Nil -> Pass (Pair "{wakePath}" Nil)
4534 _ -> Fail (makeError "Two wake binaries declared for testing!")
4635
47- def wakeUnitToTest Unit =
48- require buildWakeUnit, Nil = subscribe wakeUnitTestBinary
49- else failWithError "wake-unit binary not found"
50-
51- require Pass wakeUnitLst = buildWakeUnit (Pair "native-cpp14-release" "native-c11-release")
52-
53- require Some result = head wakeUnitLst
54- else failWithError "wake-unit binary not found"
55-
56- Pass result
57-
5836def showDiff (expect: String) (actual: String): Result Unit Error =
5937 require Pass expectFile = writeTempFile "diff.expect" expect
6038 else failWithError "Unable to write expect file"
@@ -135,82 +113,6 @@ export def runTests (cmdline: List String): Result String Error =
135113
136114 Pass "All {len tests | str} tests completed successfully."
137115
138- export def runUnitTests _: Result Unit Error =
139- def testDirectory = "{@here}/wake-unit"
140-
141- require Pass testScript = source "{testDirectory}/unit-test.sh"
142-
143- def testName =
144- testDirectory
145- | replace `^${quote @here}/` ""
146-
147- def readFile list = match list
148- Some file ->
149- require Pass content = read file
150-
151- Pass (Some content)
152- None -> Pass None
153-
154- require Pass expectedStdout =
155- source "{testDirectory}/stdout"
156- | getPass
157- | readFile
158-
159- require Pass expectedStderr =
160- source "{testDirectory}/stderr"
161- | getPass
162- | readFile
163-
164- require Pass visibleFiles = sources testDirectory `.*`
165-
166- def inTestDir path = relative testDirectory path
167-
168- require Pass wakeUnitBin = wakeUnitToTest Unit
169-
170- def testJob =
171- makeExecPlan
172- ("./{testScript.getPathName.inTestDir}", wakeUnitBin.getPathName.inTestDir, Nil)
173- (wakeUnitBin, visibleFiles)
174- | setPlanDirectory testDirectory
175- | setPlanLabel "testing: {testName}"
176- | setPlanStdout logNever
177- | setPlanStderr logNever
178- | setPlanShare False
179- | runJobWith localRunner
180-
181- def removeCarriageReturns = replace `\r` ""
182-
183- require Pass jobStdout =
184- testJob.getJobFailedStdout
185- | rmap removeCarriageReturns
186-
187- require Pass jobStderr =
188- testJob.getJobFailedStderr
189- | rmap removeCarriageReturns
190-
191- require Pass _ = match testJob.isJobOk
192- True -> Pass Unit
193- False ->
194- def _ = println jobStderr
195-
196- Fail (makeError "Test failed ({format testJob.getJobStatus}). See above for details")
197-
198- require Pass _ = match expectedStderr
199- Some x if x ==* jobStderr -> Pass Unit
200- None -> Pass Unit
201- Some _ ->
202- def _ = println jobStderr
203-
204- Fail (makeError "Unexpected standard error. See above for details")
205-
206- match expectedStdout
207- Some x if x ==* jobStdout -> Pass Unit
208- None -> Pass Unit
209- _ ->
210- def _ = println jobStdout
211-
212- Fail (makeError "Unexpected standard output. See above for details")
213-
214116def runTest (testScript: Path): Result Unit Error =
215117 def shouldPass =
216118 testScript
@@ -233,6 +135,22 @@ def runTest (testScript: Path): Result Unit Error =
233135 Pass (Some content)
234136 None -> Pass None
235137
138+ def trim s =
139+ s
140+ | replace `^\s*` ""
141+ | replace `\s*$` ""
142+
143+ def readFileList list = match list
144+ Some file ->
145+ require Pass content = read file
146+
147+ content
148+ | tokenize `\n`
149+ | map trim
150+ | filter (_ !=* "")
151+ | Pass
152+ None -> Pass Nil
153+
236154 require Pass expectedStdout =
237155 source "{testDirectory}/stdout"
238156 | getPass
@@ -243,16 +161,32 @@ def runTest (testScript: Path): Result Unit Error =
243161 | getPass
244162 | readFile
245163
164+ require Pass deps =
165+ source "{testDirectory}/deps"
166+ | getPass
167+ | readFileList
168+
246169 require Pass visibleFiles = sources testDirectory `.*`
170+ require Pass (Pair wakeDir wakeVisible) = wakeToTestDir Unit
247171
248172 def inTestDir path = relative testDirectory path
249173
250- require Pass (Pair wakeDir wakeVisible) = wakeToTestDir Unit
174+ # Ensure all the required files for the test were built
175+ require Pass ds =
176+ deps
177+ | map (\x claimFileAsPath "{wakeDir}/{x}" ".build/test/{x}")
178+ | findFail
179+ else
180+ def _ =
181+ "{testName} skipped! One of the deps ({deps | catWith ", "}) is missing."
182+ | printlnLevel logWarning
183+
184+ Pass Unit
251185
252186 def testJob =
253187 makeExecPlan
254188 ("./{testScript.getPathName.inTestDir}", wakeDir.inTestDir, Nil)
255- (visibleFiles ++ wakeVisible)
189+ (visibleFiles ++ wakeVisible ++ ds )
256190 | setPlanDirectory testDirectory
257191 | setPlanLabel "testing: {testName}"
258192 | setPlanEnvironment ("HOME={testDirectory}",)
0 commit comments