This repository has been archived by the owner on Sep 18, 2022. It is now read-only.
forked from LucasCatchlove/Cmin_Cross_Assembler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aunit.java
65 lines (57 loc) · 1.89 KB
/
aunit.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* aunit.java - AUnit
//
// Copyright (C) 1996-2021 by Michel de Champlain
//
*/
import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Vector;
class Test {
Test(int number, String name) {
this.number = number;
this.name = name;
}
int number;
String name;
}
public class aunit {
static Vector<Test> failedTests = new Vector<Test>();
public static void main(String[] args) throws IOException {
String line;
if (args.length != 1) {
System.out.println("Usage: aunit Tests.txt");
return;
}
BufferedReader reader = new BufferedReader(new java.io.FileReader(new File(args[0])));
int testNumber = 1;
// Reading all tests
while ( (line = reader.readLine()) != null) {
if (line.startsWith("Test")) {
Test test = new Test(testNumber, line);
String expectedOutput = reader.readLine();
String output = reader.readLine();
char status = expectedOutput.equals(output) ? '.' : 'F';
if (status == 'F') {
failedTests.addElement(test);
}
System.out.print(status);
} else {
System.out.println("\nTest #" + testNumber + " should start with \"Test...\" (see file 'runTests.txt' for details)");
return;
}
++testNumber;
}
System.out.println();
// Reporting only if at least one test failed
if (failedTests.isEmpty()) {
System.out.println("OK");
} else {
System.out.println("\nFailed Tests:");
for (Test t : failedTests) {
System.out.println("- "+ t.name);
}
}
}
}