Skip to content

Commit

Permalink
Merge pull request #41
Browse files Browse the repository at this point in the history
(#38) Create directory for `outputPath` if it does not exists already
  • Loading branch information
jayasuryat authored Oct 11, 2023
2 parents 1a27ecc + 76df281 commit 4ce5cdf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ public class MendableReportGenerator(
}

require(outputPath.isNotEmpty()) { "outputPath cannot be empty" }
val output = File(outputPath)
require(output.exists()) { "$output does not exist" }
require(output.isDirectory) { "$output is not a directory" }

require(outputFileName.isNotEmpty()) { "outputFileName cannot be empty" }
}
Expand Down Expand Up @@ -259,6 +256,7 @@ public class MendableReportGenerator(
): String {

val directory = File(Paths.get(outputDirectory).absolutePathString())
directory.mkdirs()
val file = File("${directory.absolutePath}/$outputName.$extension")
file.writeText(content)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,35 @@ internal class MendableReportGeneratorTest {
result.shouldBeInstanceOf<Progress.Error>()
}

@Test
fun `should not throw error for non-existent output path`() = runTest {

val path = this::class.java.classLoader?.getResource("app_release-composables.txt")?.path
require(!path.isNullOrEmpty())

val scanPath = File(path).parent
val outputPath = "${temporaryFolder.root}${File.separator}some-folder"
val outputName = "output"

val request = MendableReportGeneratorRequest(
scanPath = scanPath,
outputPath = outputPath,
scanRecursively = false,
outputFileName = outputName,
exportType = ExportType.HTML,
includeModules = IncludeModules.ALL,
)

val result: Progress.Result = generator.generate(request = request)

result.shouldBeInstanceOf<Progress.SuccessfullyCompleted>()

val output = File(result.outputPath)

output.exists() shouldBe true
output.isFile shouldBe true
}

@Test
fun `should throw error for empty output file name`() = runTest {

Expand Down

0 comments on commit 4ce5cdf

Please sign in to comment.