about summary refs log blame commit diff stats
path: root/all_tests.py
blob: 6693b8708e2bbabf0b15769277ff525c2a1504b5 (plain) (tree)
e9
#!/usr/bin/python
"""Run all the tests inside the test/ directory as a test suite."""
if __name__ == '__main__':
	import unittest
	from test import *
	from sys import exit, argv

	try:
		verbosity = int(argv[1])
	except IndexError:
		verbosity = 2

	tests = []
	for key, val in vars().copy().items():
		if key.startswith('tc_'):
			tests.extend(v for k,v in vars(val).items() if type(v) == type)

	suite = unittest.TestSuite(map(unittest.makeSuite, tests))
	result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
	if len(result.errors) + len(result.failures) > 0:
		exit(1)
pan class="p">[ ] sink:&:sink:char, writer:num/routine <- start-writing filesystem:&:filesystem, [a] sink <- write sink, 120/x sink <- write sink, 121/y close sink wait-for-routine writer contents-read-back:text <- slurp filesystem, [a] 10:bool/raw <- equal contents-read-back, [xy] memory-should-contain [ 10 <- 1 # file contents read back exactly match what was written ] ] scenario write-to-fake-file-that-exists [ local-scope assume-filesystem [ [a] <- [] ] sink:&:sink:char, writer:num/routine <- start-writing filesystem:&:filesystem, [a] sink <- write sink, 120/x sink <- write sink, 121/y close sink wait-for-routine writer contents-read-back:text <- slurp filesystem, [a] 10:bool/raw <- equal contents-read-back, [xy] memory-should-contain [ 10 <- 1 # file contents read back exactly match what was written ] ] scenario write-to-existing-file-preserves-other-files [ local-scope assume-filesystem [ [a] <- [] [b] <- [ |bcd| ] ] sink:&:sink:char, writer:num/routine <- start-writing filesystem:&:filesystem, [a] sink <- write sink, 120/x sink <- write sink, 121/y close sink wait-for-routine writer contents-read-back:text <- slurp filesystem, [a] 10:bool/raw <- equal contents-read-back, [xy] other-file-contents:text <- slurp filesystem, [b] 11:bool/raw <- equal other-file-contents, [bcd ] memory-should-contain [ 10 <- 1 # file contents read back exactly match what was written 11 <- 1 # other files also continue to persist unchanged ] ] def slurp fs:&:filesystem, filename:text -> contents:text [ local-scope load-ingredients source:&:source:char <- start-reading fs, filename buf:&:buffer <- new-buffer 30/capacity { c:char, done?:bool, source <- read source break-if done? buf <- append buf, c loop } contents <- buffer-to-array buf ]