<commit_before>package ca.uwaterloo.joos.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintStream;

import org.junit.BeforeClass;
import org.junit.Test;

import ca.uwaterloo.joos.Main;
import ca.uwaterloo.joos.parser.LR1Parser;
import ca.uwaterloo.joos.scanner.Scanner;

@SuppressWarnings("serial")
public class A1Test {

	private static Main instance;

	class A1Exception extends Exception {
	}

	@BeforeClass
	public static void setUp() {
		instance = new Main();
	}

	@Test
	public void Test() {
		try {
			File outFile = new File("tmp/a1test.out");
			if (outFile.exists()) {
				outFile.delete();
			}
			System.setOut(new PrintStream(outFile));
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}

		File directory = new File("resources/testcases/a1");
		File[] testFileList = directory.listFiles();
		for (File testFile : testFileList) {
			Exception fileException = extractFileError(testFile);

			try {
				instance.execute(testFile);
				if (fileException != null) {
					System.out.println("ERROR: " + testFile.getName()
							+ "\nrealException: NoException" + " fileException: "
							+ fileException.getClass().getSimpleName() + "\n");
				}
			} catch (Exception realException) {
				if (fileException == null) {
					System.out.println("ERROR: " + testFile.getName()
							+ "\nrealException: " + realException.getClass().getSimpleName()
							+ " fileException: NoException\n");
				}
//				else if (!realException.getClass().getSimpleName().equals(fileException.getClass().getSimpleName())) {
//					System.out.println("WARNING: " + testFile.getName()
//							+ "\nrealException: "
//							+ realException.getClass().getSimpleName()
//							+ " fileException: "
//							+ fileException.getClass().getSimpleName()
//							+ "\n");
//				}
			}
		}
	}

	private Exception extractFileError(File testFile) {
		Exception fileExcpetion = null;
		try {
			BufferedReader br = new BufferedReader(new FileReader(testFile));
			String errorMessage = new String();

			while (errorMessage != null && !errorMessage.contains("JOOS1:")) {
				errorMessage = br.readLine();
			} 
			
			if(errorMessage != null) fileExcpetion = extractError(errorMessage);
			if (fileExcpetion == null && testFile.getName().contains("Je")) {
				fileExcpetion = new A1Exception();
			}
			br.close();

		} catch (Exception e) {
			e.printStackTrace();
		}
		return fileExcpetion;
	}

	public Exception extractError(String errorMessage) {
		if (errorMessage.contains("LEXER_EXCEPTION")) {
			return new Scanner.ScanException("");<commit_msg>Change output message format<commit_after>package ca.uwaterloo.joos.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintStream;

import org.junit.BeforeClass;
import org.junit.Test;

import ca.uwaterloo.joos.Main;
import ca.uwaterloo.joos.parser.LR1Parser;
import ca.uwaterloo.joos.scanner.Scanner;

@SuppressWarnings("serial")
public class A1Test {

	private static Main instance;

	class A1Exception extends Exception {
	}

	@BeforeClass
	public static void setUp() {
		instance = new Main();
	}

	@Test
	public void Test() {
		try {
			File outFile = new File("tmp/a1test.out");
			if (outFile.exists()) {
				outFile.delete();
			}
			System.setOut(new PrintStream(outFile));
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}

		File directory = new File("resources/testcases/a1");
		File[] testFileList = directory.listFiles();
		for (File testFile : testFileList) {
			Exception fileException = extractFileError(testFile);

			try {
				instance.execute(testFile);
				if (fileException != null) {
					System.out.println("Expecting: " + fileException.getClass().getSimpleName() + "\t" 
							+ "but got: NoException" + "\t\t"
							+ "[" + testFile.getName() + "]");
				}
			} catch (Exception realException) {
				if (fileException == null) {
					System.out.println("Expecting: NoException" + "\t" 
							+ "but got: " + realException.getClass().getSimpleName() + "\t\t"
							+ "[" + testFile.getName() + "]");
				}
//				else if (!realException.getClass().getSimpleName().equals(fileException.getClass().getSimpleName())) {
//					System.out.println("Expecting: " + fileException.getClass().getSimpleName() + "\t" 
//							+ "but got: " + realException.getClass().getSimpleName() + "\t\t"
//							+ "[" + testFile.getName() + "]");
//				}
			}
		}
	}

	private Exception extractFileError(File testFile) {
		Exception fileExcpetion = null;
		try {
			BufferedReader br = new BufferedReader(new FileReader(testFile));
			String errorMessage = new String();

			while (errorMessage != null && !errorMessage.contains("JOOS1:")) {
				errorMessage = br.readLine();
			} 
			
			if(errorMessage != null) fileExcpetion = extractError(errorMessage);
			if (fileExcpetion == null && testFile.getName().contains("Je")) {
				fileExcpetion = new A1Exception();
			}
			br.close();

		} catch (Exception e) {
			e.printStackTrace();
		}
		return fileExcpetion;
	}

	public Exception extractError(String errorMessage) {
		if (errorMessage.contains("LEXER_EXCEPTION")) {
			return new Scanner.ScanException("");
{'fraction_non_alphanumeric': 0.1473823975720789, 'fraction_numerical': 0.0034142640364188165, 'mean_word_length': 3.716457960644007, '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': '5093210', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1683, 'n_words': 322}