Skip to content

Commit

Permalink
add test for Mercurial tag parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
vladak committed Sep 9, 2024
1 parent f79db40 commit 9e48dcd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.history;
Expand Down Expand Up @@ -283,7 +283,7 @@ boolean hasFileBasedTags() {
return false;
}

NavigableSet<TagEntry> getTagList() {
@Nullable NavigableSet<TagEntry> getTagList() {
return this.tagList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,27 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.opengrok.indexer.condition.EnabledForRepository;
import org.opengrok.indexer.configuration.CommandTimeoutType;
import org.opengrok.indexer.configuration.RuntimeEnvironment;
import org.opengrok.indexer.util.Executor;
import org.opengrok.indexer.util.IOUtils;
import org.opengrok.indexer.util.TestRepository;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -97,7 +105,7 @@ public class MercurialRepositoryTest {
*/
private void setUpTestRepository() throws IOException, URISyntaxException {
repository = new TestRepository();
repository.create(getClass().getResource("/repositories"));
repository.create(Objects.requireNonNull(getClass().getResource("/repositories")));
repositoryRoot = new File(repository.getSourceRoot(), "mercurial");
}

Expand Down Expand Up @@ -441,4 +449,31 @@ void testAnnotationPositive(Pair<String, List<String>> pair) throws Exception {
List<String> revisions = new ArrayList<>(annotation.getRevisions());
assertEquals(pair.getValue(), revisions);
}

@Test
void testBuildTagListEmpty() throws Exception {
Path repositoryRootPath = Files.createDirectory(Path.of(RuntimeEnvironment.getInstance().getSourceRootPath(),
"emptyTagsTest"));
File repositoryRoot = repositoryRootPath.toFile();
assertTrue(repositoryRoot.isDirectory());
runHgCommand(repositoryRoot, "init");
MercurialRepository hgRepo = (MercurialRepository) RepositoryFactory.getRepository(repositoryRoot);
assertNotNull(hgRepo);
hgRepo.buildTagList(new File(hgRepo.getDirectoryName()), CommandTimeoutType.INDEXER);
assertEquals(0, hgRepo.getTagList().size());
IOUtils.removeRecursive(repositoryRootPath);
}

@Test
void testBuildTagListInitial() throws Exception {
MercurialRepository hgRepo = (MercurialRepository) RepositoryFactory.getRepository(repositoryRoot);
assertNotNull(hgRepo);
hgRepo.buildTagList(new File(hgRepo.getDirectoryName()), CommandTimeoutType.INDEXER);
var tags = hgRepo.getTagList();
assertEquals(1, tags.size());
Set<TagEntry> expectedTags = new TreeSet<>();
TagEntry tagEntry = new MercurialTagEntry(7, "start_of_novel");
expectedTags.add(tagEntry);
assertEquals(expectedTags, tags);
}
}

0 comments on commit 9e48dcd

Please sign in to comment.