Skip to content

Commit 14fa069

Browse files
authored
improve test coverate of Ctags.doCtags() a bit (#4923)
1 parent 512e738 commit 14fa069

File tree

2 files changed

+20
-18
lines changed
  • opengrok-indexer/src

2 files changed

+20
-18
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/Ctags.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2005, 2026, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>.
2323
*/
2424
package org.opengrok.indexer.analysis;
@@ -454,7 +454,7 @@ private void addScalaSupport(List<String> command) {
454454
}
455455

456456
/**
457-
* Run ctags on a file.
457+
* Run {@code ctags} program on a file.
458458
* @param file file path to process
459459
* @return valid instance of {@link Definitions} or {@code null} on error
460460
* @throws IOException I/O exception
@@ -463,7 +463,7 @@ private void addScalaSupport(List<String> command) {
463463
@Nullable
464464
public Definitions doCtags(String file) throws IOException, InterruptedException {
465465

466-
if (file.length() < 1 || "\n".equals(file)) {
466+
if (file.isEmpty() || "\n".equals(file)) {
467467
return null;
468468
}
469469

opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/CtagsTest.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2010, 2026, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2019, Chris Fraire <cfraire@me.com>.
2323
*/
2424
package org.opengrok.indexer.analysis;
2525

2626
import java.io.File;
27+
import java.net.URL;
2728
import java.util.List;
2829

2930
import org.junit.jupiter.api.AfterAll;
@@ -33,10 +34,13 @@
3334
import org.junit.jupiter.api.condition.OS;
3435
import org.junit.jupiter.params.ParameterizedTest;
3536
import org.junit.jupiter.params.provider.MethodSource;
37+
import org.junit.jupiter.params.provider.ValueSource;
3638
import org.opengrok.indexer.util.TestRepository;
3739

3840
import static org.junit.jupiter.api.Assertions.assertAll;
3941
import static org.junit.jupiter.api.Assertions.assertEquals;
42+
import static org.junit.jupiter.api.Assertions.assertNotNull;
43+
import static org.junit.jupiter.api.Assertions.assertNull;
4044
import static org.junit.jupiter.api.Assertions.assertTrue;
4145

4246
/**
@@ -53,7 +57,9 @@ static void setUpClass() throws Exception {
5357
ctags = new Ctags();
5458

5559
repository = new TestRepository();
56-
repository.create(CtagsTest.class.getClassLoader().getResource("sources"));
60+
URL repositoryURL = CtagsTest.class.getClassLoader().getResource("sources");
61+
assertNotNull(repositoryURL);
62+
repository.create(repositoryURL);
5763

5864
/*
5965
* This setting is only needed for bug19195 but it does not seem
@@ -84,6 +90,12 @@ private static Definitions getDefs(String fileName) throws Exception {
8490
return ctags.doCtags(new File(path).getAbsolutePath());
8591
}
8692

93+
@ParameterizedTest
94+
@ValueSource(strings = {"", "\n"})
95+
void testEmptyFile(String filePath) throws Exception {
96+
assertNull(ctags.doCtags(filePath));
97+
}
98+
8799
/**
88100
* Test of doCtags method, of class Ctags.
89101
*/
@@ -150,8 +162,8 @@ void testTfTags(final SingleTagTestData data) throws Exception {
150162
var defs = getDefs("terraform/" + data.file + ".tf");
151163
assertAll(
152164
() -> assertEquals(1, defs.getTags().size()),
153-
() -> assertEquals(data.symbol, defs.getTags().get(0).symbol),
154-
() -> assertEquals(data.type, defs.getTags().get(0).type)
165+
() -> assertEquals(data.symbol, defs.getTags().getFirst().symbol),
166+
() -> assertEquals(data.type, defs.getTags().getFirst().type)
155167
);
156168
}
157169

@@ -166,16 +178,6 @@ private static List<SingleTagTestData> terraformTestParams() {
166178
);
167179
}
168180

169-
private static class SingleTagTestData {
170-
private final String file;
171-
private final String symbol;
172-
private final String type;
173-
174-
SingleTagTestData(final String file, final String symbol, final String type) {
175-
this.file = file;
176-
this.symbol = symbol;
177-
this.type = type;
178-
}
181+
private record SingleTagTestData(String file, String symbol, String type) {
179182
}
180-
181183
}

0 commit comments

Comments
 (0)