<commit_before>import os, subprocess, sys, random

class Test:
	def __init__(self, path, test, expected, seed, runs):
		self.path = path
		self.test = test
		self.expected = expected
		self.seed = seed
		self.runs = runs
	def __call__(self):
		test = ["./" + self.test]
		def getSeed():
			return [str(random.randint(0, 2**32 - 1))] if self.seed else []
		if self.seed:
			random.seed(self.seed)
		with open(self.path + "/test.output", "w+") as outfile:
			for _ in range(0, self.runs):
				print(self.path)
				status = subprocess.call(test + getSeed(), cwd=self.path, stdout=outfile)
				outfile.seek(0)
				if status:
					for line in outfile:
						print(line, end="")
					return False
				if self.expected:
					status = subprocess.call(["diff", "-q", self.expected, "test.output"], cwd=self.path)
					if status:
						for line in outfile:
							print(line, end="")
						return False
			for line in outfile:
				print(line, end="")
		return True

def hasTest(files):
	return any(filename.endswith((".test", ".c")) or filename == "makefile" for filename in files)

def makeTest(path, files):
	config = [filename for filename in files if filename.endswith(".conf")]
	config = config[0] if config else None
	options = dict()
	if config:
		for line in open(config):
			(key, _, val) = line.partition(" ")
			options[key] = val
	status = 0;
	if not any(filename.endswith(".test") for filename in files):
		if "makefile" in files:
			print("using makefile in " + path)
			status = subprocess.call(["make"], cwd=path)
		else:
			print("compiling c files in " + path)
			print("gcc -I" + os.path.dirname(os.path.abspath(__file__)) + "/../src ...")
			status = subprocess.call(["gcc", "-I" + os.path.dirname(os.path.abspath(__file__)) + "/../src", "-o", "test.test"] + [srcfile for srcfile in files if srcfile.endswith(".c")], cwd=path)
			files.append("test.test")
	expected = [filename for filename in files if filename.endswith(".expected")]
	expected = expected[0] if expected else None
	seed = options["seed"] if "seed" in options else None
	runs = options["runs"] if "runs" in options else 1
	test = next(filename for filename in files if filename.endswith(".test"))
	return Test(path, test, expected, seed, runs)

testfiles = ((path, files) for (path, dirs, files) in os.walk(".") if not dirs and hasTest(files))

tests = (makeTest(path, files) for path, files in testfiles)

passed = 0
tested = 0
for test in tests:
	if test():<commit_msg>Set std=c99 in test.py<commit_after>import os, subprocess, sys, random

class Test:
	def __init__(self, path, test, expected, seed, runs):
		self.path = path
		self.test = test
		self.expected = expected
		self.seed = seed
		self.runs = runs
	def __call__(self):
		test = ["./" + self.test]
		def getSeed():
			return [str(random.randint(0, 2**32 - 1))] if self.seed else []
		if self.seed:
			random.seed(self.seed)
		with open(self.path + "/test.output", "w+") as outfile:
			for _ in range(0, self.runs):
				print(self.path)
				status = subprocess.call(test + getSeed(), cwd=self.path, stdout=outfile)
				outfile.seek(0)
				if status:
					for line in outfile:
						print(line, end="")
					return False
				if self.expected:
					status = subprocess.call(["diff", "-q", self.expected, "test.output"], cwd=self.path)
					if status:
						for line in outfile:
							print(line, end="")
						return False
			for line in outfile:
				print(line, end="")
		return True

def hasTest(files):
	return any(filename.endswith((".test", ".c")) or filename == "makefile" for filename in files)

def makeTest(path, files):
	config = [filename for filename in files if filename.endswith(".conf")]
	config = config[0] if config else None
	options = dict()
	if config:
		for line in open(config):
			(key, _, val) = line.partition(" ")
			options[key] = val
	status = 0;
	if not any(filename.endswith(".test") for filename in files):
		if "makefile" in files:
			print("using makefile in " + path)
			status = subprocess.call(["make"], cwd=path)
		else:
			print("compiling c files in " + path)
			print("gcc -I" + os.path.dirname(os.path.abspath(__file__)) + "/../src ...")
			status = subprocess.call(["gcc", "-std=c99", "-I" + os.path.dirname(os.path.abspath(__file__)) + "/../src", "-o", "test.test"] + [srcfile for srcfile in files if srcfile.endswith(".c")], cwd=path)
			files.append("test.test")
	expected = [filename for filename in files if filename.endswith(".expected")]
	expected = expected[0] if expected else None
	seed = options["seed"] if "seed" in options else None
	runs = options["runs"] if "runs" in options else 1
	test = next(filename for filename in files if filename.endswith(".test"))
	return Test(path, test, expected, seed, runs)

testfiles = ((path, files) for (path, dirs, files) in os.walk(".") if not dirs and hasTest(files))

tests = (makeTest(path, files) for path, files in testfiles)

passed = 0
tested = 0
for test in tests:
	if test():
{'fraction_non_alphanumeric': 0.1572736520854527, 'fraction_numerical': 0.006103763987792472, 'mean_word_length': 3.6508987701040683, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3042830', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1658, 'n_words': 517}