File: ScriptedStyleTest.java

package info (click to toggle)
mkgmap 0.0.0%2Bsvn4923-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,068 kB
  • sloc: java: 73,955; xml: 1,719; python: 713; sh: 240; makefile: 147; perl: 31
file content (104 lines) | stat: -rw-r--r-- 2,753 bytes parent folder | download | duplicates (4)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright (C) 2010.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 or
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */
package func.style;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;

import uk.me.parabola.mkgmap.main.StyleTester;

import func.lib.TestUtils;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
 * A set of tests written as files, using the StyleTester.
 */
public class ScriptedStyleTest {
	private OutputStream output;

	/**
	 * This is to check that the tests are working.  Run a test that fails
	 * on purpose to check that we can detect this.
	 */
	@Test
	public void failureTest() {
		TestUtils.registerFile("styletester.style");
		StyleTester.runSimpleTest("test/resources/rules/fails-on-purpose.fail");
		String result = output.toString();
		assertTrue("failure check", result.contains("ERROR"));
	}

	/**
	 * This is really a whole bunch of tests as we find test files in a
	 * directory and run each one in turn.
	 */
	@Test
	public void testAllRuleFiles() throws IOException {
		File d = new File("test/resources/rules/");
		assertTrue(d.isDirectory());

		// Only run files ending in .test
		FilenameFilter filter = (dir, name) -> {
			if (name.endsWith(".test"))
				return true;
			return false;
		};

		int count = 0;
		File[] files = d.listFiles(filter);
		assert files != null;
		for (File file : files) {
			setup();
			String name = file.getCanonicalPath();
			try {
				StyleTester.runSimpleTest(name);
			} catch (Exception e) {
				assertFalse(name, true);
			}
			String result = output.toString();

			// Make sure that the result does not contain an error
			if (result.contains("ERROR")) {
				System.out.println(result);
				assertFalse(name, true);
			}

			// make sure that the output was reasonable (and not 'cannot open
			// file', for example).
			assertTrue(name, result.contains("WAY 1:"));

			count++;
		}

		// Check that some tests were run (ie. it will fail if you just delete
		// them all).
		assertTrue("tests run", count >= 3);
	}

	@Before
	public void setup() {
		output = new ByteArrayOutputStream();
		PrintStream ps = new PrintStream(output);
		StyleTester.setOut(ps);

		// Make sure that there is a given result set
		StyleTester.forceUseOfGiven();
	}
}