Skip to content

Commit

Permalink
Merge pull request #6 from jippi/more-tests
Browse files Browse the repository at this point in the history
print tests
  • Loading branch information
jippi authored Feb 15, 2024
2 parents 44323e2 + 76acd24 commit 28a0848
Show file tree
Hide file tree
Showing 19 changed files with 143 additions and 10 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ jobs:
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

- run: ./dottie

Expand Down
13 changes: 13 additions & 0 deletions cmd/print/prin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package print_cmd_test

import (
"testing"

"github.com/jippi/dottie/pkg/test_helpers"
)

func TestCommand(t *testing.T) {
t.Parallel()

test_helpers.RunFilebasedCommandTests(t, test_helpers.SkipEnvCopy, "print")
}
4 changes: 2 additions & 2 deletions cmd/print/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ func NewCommand() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
env, settings, warnings, err := setup(cmd.Flags())
if warnings != nil {
tui.Theme.Warning.StderrPrinter().Printfln("%+v", warnings)
tui.Theme.Warning.BuffPrinter(cmd.ErrOrStderr()).Printfln("%+v", warnings)
}
if err != nil {
return err
}

fmt.Println(render.NewRenderer(*settings).Statement(env).String())
fmt.Fprintln(cmd.OutOrStdout(), render.NewRenderer(*settings).Statement(env).String())

return nil
},
Expand Down
1 change: 1 addition & 0 deletions cmd/print/tests/empty.command.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--no-color
Empty file added cmd/print/tests/empty.env
Empty file.
2 changes: 2 additions & 0 deletions cmd/print/tests/empty/stdout.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


2 changes: 2 additions & 0 deletions cmd/print/tests/full.command.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--pretty
--no-color
29 changes: 29 additions & 0 deletions cmd/print/tests/full.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
################################################################################
# My first group
################################################################################

KEY_A="I'm key A"

# Comment for KEY_B
KEY_B="I'm key B"

KEY_C="I'm key C"

################################################################################
# My Second group
################################################################################

GROUP_TWO_A="hello"
# This is nice, format me
GROUP_TWO_A="WORLD"

################################################################################
# My Third group
################################################################################

# A Comment

# Another comment
# with two lines

SECRET=KEY
31 changes: 31 additions & 0 deletions cmd/print/tests/full/stdout.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
################################################################################
# My first group
################################################################################

KEY_A="I'm key A"

# Comment for KEY_B
KEY_B="I'm key B"

KEY_C="I'm key C"

################################################################################
# My Second group
################################################################################

GROUP_TWO_A="hello"

# This is nice, format me
GROUP_TWO_A="WORLD"

################################################################################
# My Third group
################################################################################

# A Comment

# Another comment
# with two lines

SECRET=KEY

1 change: 1 addition & 0 deletions cmd/print/tests/simple-pretty.command.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--no-color
6 changes: 6 additions & 0 deletions cmd/print/tests/simple-pretty.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
KEY_A="I'm key A"

# Comment for KEY_B
KEY_B="I'm key B"

KEY_C="I'm key C"
4 changes: 4 additions & 0 deletions cmd/print/tests/simple-pretty/stdout.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
KEY_A="I'm key A"
KEY_B="I'm key B"
KEY_C="I'm key C"

1 change: 1 addition & 0 deletions cmd/print/tests/simple.command.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--no-color
4 changes: 4 additions & 0 deletions cmd/print/tests/simple.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
KEY_A="I'm key A"
# Comment for KEY_B
KEY_B="I'm key B"
KEY_C="I'm key C"
4 changes: 4 additions & 0 deletions cmd/print/tests/simple/stdout.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
KEY_A="I'm key A"
KEY_B="I'm key B"
KEY_C="I'm key C"

3 changes: 3 additions & 0 deletions cmd/print/tests/specific-group.command.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--no-color
--group
my-first-group
29 changes: 29 additions & 0 deletions cmd/print/tests/specific-group.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
################################################################################
# My first group
################################################################################

KEY_A="I'm key A"

# Comment for KEY_B
KEY_B="I'm key B"

KEY_C="I'm key C"

################################################################################
# My Second group
################################################################################

GROUP_TWO_A="hello"
# This is nice, format me
GROUP_TWO_A="WORLD"

################################################################################
# My Third group
################################################################################

# A Comment

# Another comment
# with two lines

SECRET=KEY
4 changes: 4 additions & 0 deletions cmd/print/tests/specific-group/stdout.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
KEY_A="I'm key A"
KEY_B="I'm key B"
KEY_C="I'm key C"

14 changes: 7 additions & 7 deletions pkg/render/output_colorized.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (ColorizedOutput) Assignment(assignment *ast.Assignment, settings Settings)
var buf bytes.Buffer

if !assignment.Enabled {
tui.Theme.Danger.BuffPrinter(&buf).Print("#")
tui.Theme.Danger.Printer(tui.RendererWithTTY(&buf)).Print("#")
}

val := assignment.Literal
Expand All @@ -36,19 +36,19 @@ func (ColorizedOutput) Assignment(assignment *ast.Assignment, settings Settings)
val = assignment.Interpolated
}

tui.Theme.Primary.BuffPrinter(&buf).Print(assignment.Name)
tui.Theme.Dark.BuffPrinter(&buf).Print("=")
tui.Theme.Success.BuffPrinter(&buf).Print(assignment.Quote)
tui.Theme.Warning.BuffPrinter(&buf).Print(val)
tui.Theme.Success.BuffPrinter(&buf).Print(assignment.Quote)
tui.Theme.Primary.Printer(tui.RendererWithTTY(&buf)).Print(assignment.Name)
tui.Theme.Dark.Printer(tui.RendererWithTTY(&buf)).Print("=")
tui.Theme.Success.Printer(tui.RendererWithTTY(&buf)).Print(assignment.Quote)
tui.Theme.Warning.Printer(tui.RendererWithTTY(&buf)).Print(val)
tui.Theme.Success.Printer(tui.RendererWithTTY(&buf)).Print(assignment.Quote)

return NewLinesCollection().Add(buf.String())
}

func (ColorizedOutput) Comment(comment *ast.Comment, settings Settings) *Lines {
var buf bytes.Buffer

out := tui.Theme.Success.BuffPrinter(&buf)
out := tui.Theme.Success.Printer(tui.RendererWithTTY(&buf))

if comment.Annotation == nil {
out.Print(comment.Value)
Expand Down

0 comments on commit 28a0848

Please sign in to comment.