-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for customizing the output color for #582. #585
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.pinterest.ktlint.reporter.plain | ||
|
||
import com.pinterest.ktlint.reporter.plain.internal.Color | ||
import java.io.PrintStream | ||
import java.lang.System.out | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.fail | ||
import org.junit.Test | ||
|
||
class PlainReporterProviderTest { | ||
@Test | ||
fun testNoColorNameProvided() { | ||
try { | ||
PlainReporterProvider().get( | ||
out = PrintStream(out, true), | ||
opt = mapOf() | ||
) as PlainReporter | ||
|
||
fail("Expected IllegalArgumentException.") | ||
} catch (iae: IllegalArgumentException) { | ||
// Expected case | ||
} catch (e: Exception) { | ||
fail("Expected IllegalArgumentException but was: $e") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: you don't need to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooo whoops. Want me to fix? |
||
} | ||
} | ||
|
||
@Test | ||
fun testEmptyColorNameProvided() { | ||
try { | ||
PlainReporterProvider().get( | ||
out = PrintStream(out, true), | ||
opt = mapOf("color_name" to "") | ||
) as PlainReporter | ||
|
||
fail("Expected IllegalArgumentException.") | ||
} catch (iae: IllegalArgumentException) { | ||
// Expected case | ||
} catch (e: Exception) { | ||
fail("Expected IllegalArgumentException but was: $e") | ||
} | ||
} | ||
|
||
@Test | ||
fun testValidColorNameProvided() { | ||
val plainReporter = PlainReporterProvider().get( | ||
out = PrintStream(out, true), | ||
opt = mapOf("color_name" to "RED") | ||
) as PlainReporter | ||
|
||
assertEquals(Color.RED, plainReporter.outputColor) | ||
} | ||
|
||
@Test | ||
fun testInvalidColorNameProvided() { | ||
try { | ||
PlainReporterProvider().get( | ||
out = PrintStream(out, true), | ||
opt = mapOf("colo_namer" to "GARBAGE_INPUT") | ||
) as PlainReporter | ||
|
||
fail("Expected IllegalArgumentException.") | ||
} catch (iae: IllegalArgumentException) { | ||
// Expected case | ||
} catch (e: Exception) { | ||
fail("Expected IllegalArgumentException but was: $e") | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import com.pinterest.ktlint.internal.formatFile | |
import com.pinterest.ktlint.internal.lintFile | ||
import com.pinterest.ktlint.internal.location | ||
import com.pinterest.ktlint.internal.printHelpOrVersionUsage | ||
import com.pinterest.ktlint.reporter.plain.internal.Color | ||
import java.io.File | ||
import java.io.IOException | ||
import java.io.PrintStream | ||
|
@@ -132,6 +133,12 @@ class KtlintCommandLine { | |
) | ||
var color: Boolean = false | ||
|
||
@Option( | ||
names = ["--color-name"], | ||
description = ["Customize the output color"] | ||
) | ||
var colorName: String = Color.DARK_GRAY.name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to use here enum type, but it will require a lot of changes :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree and thought the same but I wasn't sure if I could reference an enum as a command line argument? I assumed it had to be a string. If you know something I don't - let me know and I can try to adjust. |
||
|
||
@Option( | ||
names = ["--debug"], | ||
description = ["Turn on debug output"] | ||
|
@@ -346,7 +353,7 @@ class KtlintCommandLine { | |
ReporterTemplate( | ||
reporterId, | ||
split.lastOrNull { it.startsWith("artifact=") }?.let { it.split("=")[1] }, | ||
mapOf("verbose" to verbose.toString(), "color" to color.toString()) + parseQuery(rawReporterConfig), | ||
mapOf("verbose" to verbose.toString(), "color" to color.toString(), "color_name" to colorName) + parseQuery(rawReporterConfig), | ||
split.lastOrNull { it.startsWith("output=") }?.let { it.split("=")[1] } | ||
) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding tests 👍