|
2 | 2 |
|
3 | 3 |
|
4 | 4 | import de.peeeq.wurstio.WurstCompilerJassImpl; |
5 | | -import de.peeeq.wurstio.languageserver.Convert; |
6 | | -import de.peeeq.wurstio.languageserver.WFile; |
7 | 5 | import de.peeeq.wurstio.utils.FileUtils; |
8 | | -import de.peeeq.wurstscript.RunArgs; |
9 | | -import de.peeeq.wurstscript.attributes.CompileError; |
10 | | -import de.peeeq.wurstscript.gui.WurstGui; |
11 | | -import de.peeeq.wurstscript.gui.WurstGuiLogger; |
12 | | -import org.eclipse.lsp4j.Diagnostic; |
13 | | -import org.eclipse.lsp4j.PublishDiagnosticsParams; |
14 | 6 | import org.testng.annotations.Test; |
15 | 7 |
|
16 | | -import java.io.BufferedWriter; |
17 | 8 | import java.io.File; |
18 | | -import java.io.FileWriter; |
19 | 9 | import java.io.IOException; |
| 10 | +import java.util.ArrayList; |
| 11 | +import java.util.List; |
20 | 12 | import java.nio.file.Files; |
21 | 13 |
|
22 | 14 | import static org.testng.Assert.assertEquals; |
| 15 | +import static org.testng.Assert.assertTrue; |
23 | 16 |
|
24 | 17 | public class DependencyFileParserTest { |
25 | 18 |
|
26 | 19 | @Test |
27 | | - public void testDepFileParsing() throws IOException { |
28 | | - File projectFolder = new File("./temp/testDepFileParsing/"); |
| 20 | + public void testAddDependenciesFromBuildFolder() throws IOException { |
| 21 | + File projectFolder = new File("./temp/testAddDependenciesFromBuildFolder/"); |
29 | 22 | newCleanFolder(projectFolder); |
30 | | - File a = new File(projectFolder, "a"); |
31 | | - File b = new File(projectFolder, "b"); |
32 | | - File c = new File(projectFolder, "c"); |
| 23 | + File depsRoot = new File(new File(projectFolder, "_build"), "dependencies"); |
| 24 | + File a = new File(depsRoot, "a"); |
| 25 | + File b = new File(depsRoot, "b"); |
| 26 | + File ignoredFile = new File(depsRoot, "not-a-dir.txt"); |
33 | 27 |
|
34 | 28 | a.mkdirs(); |
35 | | - //b.mkdirs(); |
36 | | - c.mkdirs(); |
| 29 | + b.mkdirs(); |
| 30 | + Files.writeString(ignoredFile.toPath(), "x"); |
37 | 31 |
|
38 | | - File dep = new File(projectFolder, "wurst.dependencies"); |
39 | | - try (BufferedWriter w = new BufferedWriter(new FileWriter(dep))) { |
40 | | - w.write(a.getAbsolutePath() + "\n"); |
41 | | - w.write(b.getAbsolutePath() + "\n"); |
42 | | - w.write(c.getAbsolutePath() + "\n"); |
43 | | - } |
| 32 | + List<File> dependencies = new ArrayList<>(); |
| 33 | + WurstCompilerJassImpl.addDependenciesFromFolder(projectFolder, dependencies); |
44 | 34 |
|
| 35 | + assertEquals(dependencies.size(), 2); |
| 36 | + assertTrue(containsSameFile(dependencies, a)); |
| 37 | + assertTrue(containsSameFile(dependencies, b)); |
| 38 | + } |
45 | 39 |
|
46 | | - WurstGui gui = new WurstGuiLogger(); |
47 | | - WurstCompilerJassImpl comp = new WurstCompilerJassImpl(projectFolder, gui, null, new RunArgs()); |
48 | | - comp.loadWurstFilesInDir(projectFolder); |
| 40 | + @Test |
| 41 | + public void testAddDependenciesFromBuildFolderDoesNotDuplicate() throws IOException { |
| 42 | + File projectFolder = new File("./temp/testAddDependenciesFromBuildFolderDoesNotDuplicate/"); |
| 43 | + newCleanFolder(projectFolder); |
| 44 | + File depsRoot = new File(new File(projectFolder, "_build"), "dependencies"); |
| 45 | + File a = new File(depsRoot, "a"); |
| 46 | + a.mkdirs(); |
49 | 47 |
|
50 | | - assertEquals(gui.getErrorList().size(), 1); |
51 | | - CompileError err = gui.getErrorList().get(0); |
52 | | - assertEquals(err.getSource().getLine(), 2); |
53 | | - assertEquals(err.getSource().getStartColumn(), 1); |
54 | | - assertEquals(err.getSource().getEndLine(), 2); |
55 | | - assertEquals(err.getSource().getEndColumn(), b.getAbsolutePath().length() + 1); |
| 48 | + List<File> dependencies = new ArrayList<>(); |
| 49 | + dependencies.add(a); |
56 | 50 |
|
57 | | - PublishDiagnosticsParams diag = Convert.createDiagnostics("", WFile.create(dep), gui.getErrorList()); |
58 | | - assertEquals(diag.getDiagnostics().size(), 1); |
59 | | - Diagnostic d = diag.getDiagnostics().get(0); |
60 | | - assertEquals(d.getRange().getStart().getLine(), 1); |
61 | | - assertEquals(d.getRange().getStart().getCharacter(), 0); |
62 | | - assertEquals(d.getRange().getEnd().getLine(), 1); |
63 | | - assertEquals(d.getRange().getEnd().getCharacter(), b.getAbsolutePath().length()); |
| 51 | + WurstCompilerJassImpl.addDependenciesFromFolder(projectFolder, dependencies); |
| 52 | + assertEquals(dependencies.size(), 1); |
| 53 | + } |
64 | 54 |
|
| 55 | + private boolean containsSameFile(List<File> files, File expected) { |
| 56 | + for (File f : files) { |
| 57 | + if (FileUtils.sameFile(f, expected)) { |
| 58 | + return true; |
| 59 | + } |
| 60 | + } |
| 61 | + return false; |
65 | 62 | } |
66 | 63 |
|
67 | 64 | private void newCleanFolder(File f) throws IOException { |
|
0 commit comments