WONKY



LOG | FILES | OVERVIEW


#include <wobler.h>


int main(int argc,char **argv)
{

	if(argv[1]!=NULL)
	{
		log_dump_location=argv[1];
	}
	wobler_log=fopen(log_dump_location,"w");
	if(wobler_log==NULL)
	{
		printf("Could not open log file - %s\n Redirecting to stderr",log_dump_location);
		wobler_log=stderr;
	}

	//atexit(detect_abort);
	printf("THE WOBLER HAS AWOKEN!!\n\n");

		run_tests();
		print_result_summary();

	printf("\n\nTHE WOBLER GOES BACK TO SLUMBER! WONKY HAS BEEN SPARED FROM DEATH!\n");

	return 0;
}

void run_tests()
{
	for(current_test=0;current_test<NUMBER_OF_ELEMENTS_IN_ARRAY(tests);++current_test)
	{
		if(setjmp(wobler_mark)==0) /*if we don't return from a long jump invoked in an assert*/
		{
			tests[current_test].test_function(tests[current_test].filenames);
		}
	}
}
void should_compile(char **filenames)
{
	struct Program *program;
	time_t time_in,time_out;
	wonky_memory_init();

	time(&time_in);
		program=parse_program(filenames);
		passes_test[current_test]= (program->errors->size==0);
	time(&time_out);

	test_times[current_test]=difftime(time_out,time_in);

	print_result("did not compile when it should have",filenames,program);

	delete_program(program);
	wonky_memory_delete();
}
void should_not_compile(char **filenames)
{
	struct Program *program;
	time_t time_in,time_out;
	wonky_memory_init();

	time(&time_in);
		program=parse_program(filenames);
		passes_test[current_test] = (program->errors->size != 0);
	time(&time_out);

	test_times[current_test]=difftime(time_out,time_in);

	print_result("compiled when it should NOT have",filenames,program);

	delete_program(program);
	wonky_memory_delete();
}
void print_result_summary()
{
	printf("\n\n\tFor more details check %s\n\n",log_dump_location);
}
void dump_program(FILE *where,struct Program *program)
{
	struct Compiled_Object_Print *object;

	fprintf(where,"\n\n---------------- PROGRAM DUMP BEGIN ----------------\n\n");
	dump_program_messages(where,program);

	fprintf(where,"\n\n----- AST DUMP BEGIN -----\n\n");

	object=compile_program_for_print(program);
	save_compiled_object_for_print(object,where);
	fprintf(where,"\n\n----- AST DUMP END -----\n\n");

	fprintf(where,"\n\n---------------- PROGRAM DUMP END ----------------\n\n");
}
void dump_program_messages(FILE *where,struct Program *program)
{
	fprintf(where,"\n----- MESSAGES DUMP BEGIN -----\n");
	print_errors(where,program->errors);
	fprintf(where,"\n----- MESSAGES DUMP END -----\n");
}
void print_names()
{
	size_t i;
	char **filenames;
	filenames=tests[current_test].filenames;
	for(i=0;filenames[i]!=NULL && i<100;++i)
	{
		printf("%s ",filenames[i]);
		fprintf(wobler_log,"%s ",filenames[i]);
	}
}
void print_result(char *error_message,char **filenames,struct Program *program)
{
	printf("[ ");
	fprintf(wobler_log,"[ ");
	if(passes_test[current_test])
	{
		fprintf(wobler_log,"OK     ");
		printf("OK     ");
	}else
	{
		fprintf(wobler_log,"Error  ");
		printf("Error  ");
	}

	if(test_times[current_test] > tests[current_test].how_much_time_should_execution_take)
	{
		printf("SLOW  ");
		fprintf(wobler_log,"SLOW took %f seconds ( baseline is %f ) ",
				test_times[current_test],
				tests[current_test].how_much_time_should_execution_take
				);
	}

	fprintf(wobler_log,"]\t");
	printf("]\t");

	print_names();

	if(!passes_test[current_test])
	{
		fprintf(wobler_log," -- %s",error_message);
		fprintf(stdout," -- %s",error_message);

	}
	if(test_times[current_test] <= tests[current_test].how_much_time_should_execution_take)
	{
		fprintf(wobler_log,"took %f seconds ",test_times[current_test]);
	}
	if(program)
		dump_program(wobler_log,program);

	fprintf(wobler_log,"\n");
	printf("\n");
}

void detect_abort()
{
	if(!should_be_exiting_right_now)
	{
		printf("\n[ABORT ]\t");
		fprintf(wobler_log,"\n[ABORT ]\t");	
		print_names();
	}
}