Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Apr 13, 2022
1 parent d0cbe00 commit 77e73e3
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 11 deletions.
51 changes: 51 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
build:
working_directory: ~/repo
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
docker:
- image: circleci/golang:1.17
# Add steps to the job
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
steps:
- checkout

- restore_cache:
keys:
- go-mod-v4-{{ checksum "go.sum" }}

- run:
name: Install Dependencies
command: go mod download

- run:
name: Fetch Vale
command: |
go install github.com/errata-ai/vale/v2/cmd/vale@cd147755b9fc6cf7d9ca1a70f4f75c633beeaf17
echo 'export PATH=$PATH:$(go env GOPATH)/bin' >> $BASH_ENV
- save_cache:
key: go-mod-v4-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"

- run:
name: Run tests
command: |
mkdir -p /tmp/test-reports
gotestsum --junitfile /tmp/test-reports/unit-tests.xml
- store_test_results:
path: /tmp/test-reports

# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
sample: # This is the name of the workflow, feel free to change it to better match your workflow.
# Inside the workflow, you define the jobs you want to run.
jobs:
- build
11 changes: 0 additions & 11 deletions .vale.ini

This file was deleted.

8 changes: 8 additions & 0 deletions Hugo/.vale.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[*.md]
# Exclude `{{< ... >}}`, `{{% ... %}}`, [Who]({{< ... >}})
TokenIgnores = ({{[%<] .* [%>]}}.*?{{[%<] ?/.* [%>]}}), \
(\[\w+\]\({{< .+ >}}\))

# Exclude `{{< myshortcode `This is some <b>HTML</b>, ... >}}`
BlockIgnores = (?sm)^({{[%<] [^{]*? [%>]}})\n$, \
(?s) *({{< highlight [^>]* ?>}}.*?{{< ?/ ?highlight >}})
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/errata-ai/Hugo

go 1.17

require github.com/google/go-cmdtest v0.4.0

require (
github.com/google/go-cmp v0.3.1 // indirect
github.com/google/renameio v0.1.0 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/google/go-cmdtest v0.4.0 h1:ToXh6W5spLp3npJV92tk6d5hIpUPYEzHLkD+rncbyhI=
github.com/google/go-cmdtest v0.4.0/go.mod h1:apVn/GCasLZUVpAJ6oWAuyP7Ne7CEsQbTnc0plM3m+o=
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

import "os"

func cdf() int {
os.Chdir(os.Args[1])
return 0
}
46 changes: 46 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"

"github.com/google/go-cmdtest"
)

var update = flag.Bool("update", false, "replace test file contents with output")

func Test(t *testing.T) {
ts, err := cmdtest.Read("testdata")
if err != nil {
t.Fatal(err)
}

ts.Setup = func(_ string) error {
_, testFileName, _, ok := runtime.Caller(0)
if !ok {
return fmt.Errorf("failed get real working directory from caller")
}

projectRootDir := filepath.Join(filepath.Dir(testFileName), "testdata")
if err := os.Setenv("ROOTDIR", projectRootDir); err != nil {
return fmt.Errorf("failed change 'ROOTDIR' to caller working directory: %v", err)
}

return nil
}

path, err := exec.LookPath("vale")
if err != nil {
t.Fatal(err)
}

ts.Commands["vale"] = cmdtest.Program(path)
ts.Commands["cdf"] = cmdtest.InProcessProgram("cdf", cdf)

ts.Run(t, *update)
}
10 changes: 10 additions & 0 deletions testdata/shortcodes/.vale.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[*.md]
BasedOnStyles = Vale

# Exclude `{{< ... >}}`, `{{% ... %}}`, [Who]({{< ... >}})
TokenIgnores = ({{[%<] .* [%>]}}.*?{{[%<] ?/.* [%>]}}), \
(\[\w+\]\({{< .+ >}}\))

# Exclude `{{< myshortcode `This is some <b>HTML</b>, ... >}}`
BlockIgnores = (?sm)^({{[%<] [^{]*? [%>]}})\n$, \
(?s) *({{< highlight [^>]* ?>}}.*?{{< ?/ ?highlight >}})
51 changes: 51 additions & 0 deletions testdata/shortcodes/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Shortcodes

> Shortcodes are simple snippets inside your content files calling built-in or
> custom templates.
{{% mdshortcode %}}Stuff to `process` in the *center*.{{% /mdshortcode %}}

Shortcodes are non-standard markup that appears within normal Markdown.

{{< highlt go >}} A bunch of code here {{< /highlt >}}

Shortcodes are non-standard markup that appears within normal Markdown.

{{< myshortcode This is some <b>HTML</b>,
and a new line with a "quoted string". >}}

Shortcodes are non-standard markup that appears within normal Markdown.

{{< myshortcode This is some <b>HTML</b>,. >}}

Shortcodes are non-standard markup that appears within normal Markdown.

{{< myshortcode src="/media/spf13.jpg" title="Steve Francia" >}}

Shortcodes are non-standard markup that appears within normal Markdown.

{{< highlight html >}}
<section id="main">
<div>
<h1 id="title">{{ .Title }}</h1>
{{ range .Pages }}
{{ .Render "summary"}}
{{ end }}
</div>
</section>
{{< /highlight >}}

Shortcodes are non-standard markup that appears within normal Markdown.

{{< instagram BWNjjyYFxVx hidecaption >}}

Shortcodes are non-standard markup that appears within normal Markdown.

[Who]({{< relref "about.md#who" >}})

hidecaption

{{< youtube id="w7Ft2ymGmfc" autoplay="true" >}}

Shortcodes are non-standard markup that appears within normal Markdown.

13 changes: 13 additions & 0 deletions testdata/test.ct
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$ cdf ${ROOTDIR}/shortcodes
$ vale --output=line --sort --normalize --relative --no-exit test.md
test.md:1:3:Vale.Spelling:Did you really mean 'Shortcodes'?
test.md:3:3:Vale.Spelling:Did you really mean 'Shortcodes'?
test.md:8:1:Vale.Spelling:Did you really mean 'Shortcodes'?
test.md:12:1:Vale.Spelling:Did you really mean 'Shortcodes'?
test.md:17:1:Vale.Spelling:Did you really mean 'Shortcodes'?
test.md:21:1:Vale.Spelling:Did you really mean 'Shortcodes'?
test.md:25:1:Vale.Spelling:Did you really mean 'Shortcodes'?
test.md:38:1:Vale.Spelling:Did you really mean 'Shortcodes'?
test.md:42:1:Vale.Spelling:Did you really mean 'Shortcodes'?
test.md:46:1:Vale.Spelling:Did you really mean 'hidecaption'?
test.md:50:1:Vale.Spelling:Did you really mean 'Shortcodes'?

0 comments on commit 77e73e3

Please sign in to comment.