Skip to content

Commit 77e73e3

Browse files
committed
Add tests
1 parent d0cbe00 commit 77e73e3

File tree

10 files changed

+203
-11
lines changed

10 files changed

+203
-11
lines changed

.circleci/config.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Use the latest 2.1 version of CircleCI pipeline process engine.
2+
# See: https://circleci.com/docs/2.0/configuration-reference
3+
version: 2.1
4+
5+
# Define a job to be invoked later in a workflow.
6+
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
7+
jobs:
8+
build:
9+
working_directory: ~/repo
10+
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
11+
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
12+
docker:
13+
- image: circleci/golang:1.17
14+
# Add steps to the job
15+
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
16+
steps:
17+
- checkout
18+
19+
- restore_cache:
20+
keys:
21+
- go-mod-v4-{{ checksum "go.sum" }}
22+
23+
- run:
24+
name: Install Dependencies
25+
command: go mod download
26+
27+
- run:
28+
name: Fetch Vale
29+
command: |
30+
go install github.com/errata-ai/vale/v2/cmd/vale@cd147755b9fc6cf7d9ca1a70f4f75c633beeaf17
31+
echo 'export PATH=$PATH:$(go env GOPATH)/bin' >> $BASH_ENV
32+
- save_cache:
33+
key: go-mod-v4-{{ checksum "go.sum" }}
34+
paths:
35+
- "/go/pkg/mod"
36+
37+
- run:
38+
name: Run tests
39+
command: |
40+
mkdir -p /tmp/test-reports
41+
gotestsum --junitfile /tmp/test-reports/unit-tests.xml
42+
- store_test_results:
43+
path: /tmp/test-reports
44+
45+
# Invoke jobs via workflows
46+
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
47+
workflows:
48+
sample: # This is the name of the workflow, feel free to change it to better match your workflow.
49+
# Inside the workflow, you define the jobs you want to run.
50+
jobs:
51+
- build

.vale.ini

Lines changed: 0 additions & 11 deletions
This file was deleted.

Hugo/.vale.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[*.md]
2+
# Exclude `{{< ... >}}`, `{{% ... %}}`, [Who]({{< ... >}})
3+
TokenIgnores = ({{[%<] .* [%>]}}.*?{{[%<] ?/.* [%>]}}), \
4+
(\[\w+\]\({{< .+ >}}\))
5+
6+
# Exclude `{{< myshortcode `This is some <b>HTML</b>, ... >}}`
7+
BlockIgnores = (?sm)^({{[%<] [^{]*? [%>]}})\n$, \
8+
(?s) *({{< highlight [^>]* ?>}}.*?{{< ?/ ?highlight >}})

go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/errata-ai/Hugo
2+
3+
go 1.17
4+
5+
require github.com/google/go-cmdtest v0.4.0
6+
7+
require (
8+
github.com/google/go-cmp v0.3.1 // indirect
9+
github.com/google/renameio v0.1.0 // indirect
10+
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
github.com/google/go-cmdtest v0.4.0 h1:ToXh6W5spLp3npJV92tk6d5hIpUPYEzHLkD+rncbyhI=
2+
github.com/google/go-cmdtest v0.4.0/go.mod h1:apVn/GCasLZUVpAJ6oWAuyP7Ne7CEsQbTnc0plM3m+o=
3+
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
4+
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
5+
github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA=
6+
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=

main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package main
2+
3+
import "os"
4+
5+
func cdf() int {
6+
os.Chdir(os.Args[1])
7+
return 0
8+
}

main_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"os"
7+
"os/exec"
8+
"path/filepath"
9+
"runtime"
10+
"testing"
11+
12+
"github.com/google/go-cmdtest"
13+
)
14+
15+
var update = flag.Bool("update", false, "replace test file contents with output")
16+
17+
func Test(t *testing.T) {
18+
ts, err := cmdtest.Read("testdata")
19+
if err != nil {
20+
t.Fatal(err)
21+
}
22+
23+
ts.Setup = func(_ string) error {
24+
_, testFileName, _, ok := runtime.Caller(0)
25+
if !ok {
26+
return fmt.Errorf("failed get real working directory from caller")
27+
}
28+
29+
projectRootDir := filepath.Join(filepath.Dir(testFileName), "testdata")
30+
if err := os.Setenv("ROOTDIR", projectRootDir); err != nil {
31+
return fmt.Errorf("failed change 'ROOTDIR' to caller working directory: %v", err)
32+
}
33+
34+
return nil
35+
}
36+
37+
path, err := exec.LookPath("vale")
38+
if err != nil {
39+
t.Fatal(err)
40+
}
41+
42+
ts.Commands["vale"] = cmdtest.Program(path)
43+
ts.Commands["cdf"] = cmdtest.InProcessProgram("cdf", cdf)
44+
45+
ts.Run(t, *update)
46+
}

testdata/shortcodes/.vale.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[*.md]
2+
BasedOnStyles = Vale
3+
4+
# Exclude `{{< ... >}}`, `{{% ... %}}`, [Who]({{< ... >}})
5+
TokenIgnores = ({{[%<] .* [%>]}}.*?{{[%<] ?/.* [%>]}}), \
6+
(\[\w+\]\({{< .+ >}}\))
7+
8+
# Exclude `{{< myshortcode `This is some <b>HTML</b>, ... >}}`
9+
BlockIgnores = (?sm)^({{[%<] [^{]*? [%>]}})\n$, \
10+
(?s) *({{< highlight [^>]* ?>}}.*?{{< ?/ ?highlight >}})

testdata/shortcodes/test.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Shortcodes
2+
3+
> Shortcodes are simple snippets inside your content files calling built-in or
4+
> custom templates.
5+
6+
{{% mdshortcode %}}Stuff to `process` in the *center*.{{% /mdshortcode %}}
7+
8+
Shortcodes are non-standard markup that appears within normal Markdown.
9+
10+
{{< highlt go >}} A bunch of code here {{< /highlt >}}
11+
12+
Shortcodes are non-standard markup that appears within normal Markdown.
13+
14+
{{< myshortcode This is some <b>HTML</b>,
15+
and a new line with a "quoted string". >}}
16+
17+
Shortcodes are non-standard markup that appears within normal Markdown.
18+
19+
{{< myshortcode This is some <b>HTML</b>,. >}}
20+
21+
Shortcodes are non-standard markup that appears within normal Markdown.
22+
23+
{{< myshortcode src="/media/spf13.jpg" title="Steve Francia" >}}
24+
25+
Shortcodes are non-standard markup that appears within normal Markdown.
26+
27+
{{< highlight html >}}
28+
<section id="main">
29+
<div>
30+
<h1 id="title">{{ .Title }}</h1>
31+
{{ range .Pages }}
32+
{{ .Render "summary"}}
33+
{{ end }}
34+
</div>
35+
</section>
36+
{{< /highlight >}}
37+
38+
Shortcodes are non-standard markup that appears within normal Markdown.
39+
40+
{{< instagram BWNjjyYFxVx hidecaption >}}
41+
42+
Shortcodes are non-standard markup that appears within normal Markdown.
43+
44+
[Who]({{< relref "about.md#who" >}})
45+
46+
hidecaption
47+
48+
{{< youtube id="w7Ft2ymGmfc" autoplay="true" >}}
49+
50+
Shortcodes are non-standard markup that appears within normal Markdown.
51+

testdata/test.ct

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$ cdf ${ROOTDIR}/shortcodes
2+
$ vale --output=line --sort --normalize --relative --no-exit test.md
3+
test.md:1:3:Vale.Spelling:Did you really mean 'Shortcodes'?
4+
test.md:3:3:Vale.Spelling:Did you really mean 'Shortcodes'?
5+
test.md:8:1:Vale.Spelling:Did you really mean 'Shortcodes'?
6+
test.md:12:1:Vale.Spelling:Did you really mean 'Shortcodes'?
7+
test.md:17:1:Vale.Spelling:Did you really mean 'Shortcodes'?
8+
test.md:21:1:Vale.Spelling:Did you really mean 'Shortcodes'?
9+
test.md:25:1:Vale.Spelling:Did you really mean 'Shortcodes'?
10+
test.md:38:1:Vale.Spelling:Did you really mean 'Shortcodes'?
11+
test.md:42:1:Vale.Spelling:Did you really mean 'Shortcodes'?
12+
test.md:46:1:Vale.Spelling:Did you really mean 'hidecaption'?
13+
test.md:50:1:Vale.Spelling:Did you really mean 'Shortcodes'?

0 commit comments

Comments
 (0)