From 8db5e83a37072699db46bc05844370f059020211 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 9 Sep 2023 10:55:00 +0200 Subject: [PATCH] [cli] Add test case for CPD --file-list --- .../net/sourceforge/pmd/cli/CpdCliTest.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pmd-cli/src/test/java/net/sourceforge/pmd/cli/CpdCliTest.java b/pmd-cli/src/test/java/net/sourceforge/pmd/cli/CpdCliTest.java index e751ebf741..8a9d4758de 100644 --- a/pmd-cli/src/test/java/net/sourceforge/pmd/cli/CpdCliTest.java +++ b/pmd-cli/src/test/java/net/sourceforge/pmd/cli/CpdCliTest.java @@ -12,6 +12,8 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.emptyString; import static org.hamcrest.Matchers.equalTo; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collection; @@ -147,17 +149,16 @@ class CpdCliTest extends BaseCliTest { @Test void testNoDuplicatesResultRendering() throws Exception { - final Path srcDir = Paths.get(SRC_DIR).toAbsolutePath(); String expectedReport = "\n" + "\n" - + " \n" - + " \n" - + " \n" - + " \n" + "\n"; @@ -228,4 +229,17 @@ class CpdCliTest extends BaseCliTest { "\n\n" )); } + + @Test + void testFileListOnly() throws Exception { + Path fileList = tempDir.resolve("fileList.txt"); + StringBuilder fileListContent = new StringBuilder(); + fileListContent.append(SRC_PATH.resolve("dup1.java")).append(System.lineSeparator()); + fileListContent.append(SRC_PATH.resolve("dup2.java")).append(System.lineSeparator()); + Files.write(fileList, fileListContent.toString().getBytes(StandardCharsets.UTF_8)); + runCli(VIOLATIONS_FOUND, "--minimum-tokens", "5", "--file-list", fileList.toString()) + .verify(result -> result.checkStdOut(containsString( + "Found a 14 line (86 tokens) duplication in the following files:" + ))); + } }