Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/block_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cmd_test

import "testing"

func TestBlockCommand(t *testing.T) {
runScript(t, "testdata/script/block.txtar")
}
10 changes: 6 additions & 4 deletions cmd/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ package cmd

import (
"fmt"
"io"
"os"

"litdoc/internal"

"github.com/spf13/cobra"
)

var fileCmd = &cobra.Command{
Use: "file",
Use: "file <path>",
Short: "Process a file",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
data, err := io.ReadAll(os.Stdin)
data, err := internal.ProcessFile(args[0])
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Print(string(data))
fmt.Print(data)
},
}

Expand Down
34 changes: 34 additions & 0 deletions cmd/file_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cmd_test

import (
"fmt"
"os"
"testing"

"litdoc/cmd"

"github.com/rogpeppe/go-internal/testscript"
)

func TestMain(m *testing.M) {
testscript.Main(m, map[string]func(){
"litdoc": func() {
if err := cmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
},
})
}

func TestFileCommand(t *testing.T) {
runScript(t, "testdata/script/file.txtar")
}

func runScript(t *testing.T, script string) {
t.Helper()

testscript.Run(t, testscript.Params{
Files: []string{script},
})
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
stdin input.md
exec litdoc file
exec litdoc file input.md
stdout '# Hello'

-- input.md --
Expand Down
23 changes: 0 additions & 23 deletions main_test.go

This file was deleted.

Loading