Skip to content

Commit

Permalink
preprocessor: move golden files to a subdirectory
Browse files Browse the repository at this point in the history
In a later change we move logic for removal of target files (in
hugo/content) to the preprocessor instead of a script. In preparation
for that, move all golden files to a directory outside of hugo/content,
but a directory structure that matches in shape for ease of visual
scanning, organisation etc (rather than random files in a random
location).

Also establish hugo/.keep in txtar tests as a way of keep that directory
"alive". Therefore ignore .keep files as well as .golden files in the
"find" test command.

Preprocessor-No-Write-Cache: true
Signed-off-by: Paul Jolly <[email protected]>
Change-Id: I37f5d8ed336e277120be5ba851146380f7642c28
  • Loading branch information
myitcv committed Oct 2, 2023
1 parent b3df3c6 commit e7b1655
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 42 deletions.
3 changes: 2 additions & 1 deletion internal/cmd/preprocessor/cmd/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ func findCmd() int {
printEntry = *fDir
} else {
isGolden := filepath.Ext(d.Name()) == ".golden"
printEntry = !isGolden || *fGolden
isKeep := filepath.Ext(d.Name()) == ".keep"
printEntry = (!isGolden || *fGolden) && !isKeep
}
if printEntry {
fmt.Printf("%s\n", path)
Expand Down
17 changes: 9 additions & 8 deletions internal/cmd/preprocessor/cmd/testdata/execute_basic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
exec preprocessor execute --debug=all

# Verify that the target files matche the source contents
cmp hugo/content/en/branch_md/_index.md hugo/content/en/branch_md/_index.md.golden
cmp hugo/content/en/leaf_md/index.md hugo/content/en/leaf_md/index.md.golden
cmp hugo/content/en/branch_html/_index.html hugo/content/en/branch_html/_index.html.golden
cmp hugo/content/en/leaf_html/index.html hugo/content/en/leaf_html/index.html.golden
cmp hugo/content/en/branch_md/_index.md golden/hugo/content/en/branch_md/_index.md.golden
cmp hugo/content/en/leaf_md/index.md golden/hugo/content/en/leaf_md/index.md.golden
cmp hugo/content/en/branch_html/_index.html golden/hugo/content/en/branch_html/_index.html.golden
cmp hugo/content/en/leaf_html/index.html golden/hugo/content/en/leaf_html/index.html.golden

# Ensure that the contents of the filesystem are as expected
exec cmd-find
cmp stdout stdout.golden

-- hugo/.keep --
-- content/branch_md/_en.md --
---
title: test
Expand Down Expand Up @@ -42,22 +43,22 @@ title: test
leaf_html_en
-- content/leaf_html/site.cue --
package site
-- hugo/content/en/branch_md/_index.md.golden --
-- golden/hugo/content/en/branch_md/_index.md.golden --
---
title: test
---
branch_md_en
-- hugo/content/en/leaf_md/index.md.golden --
-- golden/hugo/content/en/leaf_md/index.md.golden --
---
title: test
---
leaf_md_en
-- hugo/content/en/branch_html/_index.html.golden --
-- golden/hugo/content/en/branch_html/_index.html.golden --
---
title: test
---
branch_html_en
-- hugo/content/en/leaf_html/index.html.golden --
-- golden/hugo/content/en/leaf_html/index.html.golden --
---
title: test
---
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/preprocessor/cmd/testdata/execute_check.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
exec preprocessor execute --check
! stdout .+

-- hugo/.keep --
-- content/dir1/page.cue --
package site

Expand All @@ -30,4 +31,3 @@ package site
---
title: JSON Superset
---
-- hugo/content/.gitkeep --
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ unquote content/dir/en.md
! exec preprocessor execute --debug=all
stderr 'error in site configuration: expected label or '':'', found ''IDENT'' is'

-- hugo/.keep --
-- content/site.cue --
package site
-- content/dir/page.cue --
Expand All @@ -15,7 +16,7 @@ this is very broken
>---
>title: JSON Superset
>---
-- hugo/content/en/dir/index.md.golden --
-- golden/hugo/content/en/dir/index.md.golden --
---
title: JSON Superset
---
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ unquote content/dir/en.md
! exec preprocessor execute
cmpenv stderr stderr.golden

-- hugo/.keep --
-- content/dir/site.cue --
package site
-- content/dir/en.md --
Expand All @@ -25,7 +26,7 @@ package site
>-- out.yaml --
>x: 5
>{{{end}}}
-- hugo/content/en/dir/index.md.golden --
-- golden/hugo/content/en/dir/index.md.golden --
---
title: JSON Superset
---
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/preprocessor/cmd/testdata/execute_filter.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
exec preprocessor execute --debug=all content/dir1

# Verify that the target files matche the source contents
cmp hugo/content/en/dir1/index.md hugo/content/en/dir1/index.md.golden
cmp hugo/content/en/dir1/index.md golden/hugo/content/en/dir1/index.md.golden

# Ensure that the contents of the filesystem are as expected
exec cmd-find
cmp stdout stdout.golden

-- hugo/.keep --
-- content/dir1/en.md --
---
---
Expand All @@ -22,7 +23,7 @@ package site
dir1_en.md
-- content/dir2/site.cue --
package site
-- hugo/content/en/dir1/index.md.golden --
-- golden/hugo/content/en/dir1/index.md.golden --
---
---
dir1_en.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ exec preprocessor execute --debug=all
cmp content/page/en.md content/page/en.md.golden

# Verify that the target files matche the source contents
cmp hugo/content/en/page/index.md hugo/content/en/page/index.md.golden
cmp hugo/content/en/page/index.md golden/hugo/content/en/page/index.md.golden

-- hugo/.keep --
-- content/page/site.cue --
package site
-- content/page/en.md --
Expand All @@ -39,7 +40,7 @@ package site
>-- out.cue --
>x: 5
>{{{end}}}
-- hugo/content/en/page/index.md.golden --
-- golden/hugo/content/en/page/index.md.golden --
---
title: title
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ exec preprocessor execute --debug=all
cmp content/page/en.md content/page/en.md.golden

# Verify that the target files matche the source contents
cmp hugo/content/en/page/index.md hugo/content/en/page/index.md.golden
cmp hugo/content/en/page/index.md golden/hugo/content/en/page/index.md.golden

-- hugo/.keep --
-- content/page/site.cue --
package site
-- content/page/en.md --
Expand Down Expand Up @@ -41,7 +42,7 @@ package site
> "x": 5
>}
>{{{end}}}
-- hugo/content/en/page/index.md.golden --
-- golden/hugo/content/en/page/index.md.golden --
---
title: title
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ exec preprocessor execute --debug=all
cmp content/page/en.md content/page/en.md.golden

# Verify that the target files matche the source contents
cmp hugo/content/en/page/index.md hugo/content/en/page/index.md.golden
cmp hugo/content/en/page/index.md golden/hugo/content/en/page/index.md.golden

-- hugo/.keep --
-- content/page/site.cue --
package site
-- content/page/en.md --
Expand All @@ -35,7 +36,7 @@ package site
>-- out.yaml --
>x: 5
>{{{end}}}
-- hugo/content/en/page/index.md.golden --
-- golden/hugo/content/en/page/index.md.golden --
---
title: title
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ cp content/dir/en.md content/dir/en.md.writeBack
cmp content/dir/en.md.writeBack content/dir/en.md.golden

# Verify that the target files matche the source contents
cmp hugo/content/en/dir/index.md hugo/content/en/dir/index.md.golden
cmp hugo/content/en/dir/index.md golden/hugo/content/en/dir/index.md.golden

-- hugo/.keep --
-- content/dir/site.cue --
package site
-- content/dir/en.md --
Expand Down Expand Up @@ -62,7 +63,7 @@ package site
>
>Some text after
>
-- hugo/content/en/dir/index.md.golden --
-- golden/hugo/content/en/dir/index.md.golden --
---
title: JSON Superset
---
Expand Down
9 changes: 5 additions & 4 deletions internal/cmd/preprocessor/cmd/testdata/execute_multiple.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ cmp content/dir1/en.md.writeBack content/dir1/en.md.golden
cmp content/dir2/en.md.writeBack content/dir2/en.md.golden

# Verify that the target files matche the source contents
cmp hugo/content/en/dir1/index.md hugo/content/en/dir1/index.md.golden
cmp hugo/content/en/dir2/index.md hugo/content/en/dir2/index.md.golden
cmp hugo/content/en/dir1/index.md golden/hugo/content/en/dir1/index.md.golden
cmp hugo/content/en/dir2/index.md golden/hugo/content/en/dir2/index.md.golden

-- hugo/.keep --
-- content/dir1/site.cue --
package site
-- content/dir1/en.md --
Expand Down Expand Up @@ -70,7 +71,7 @@ package site
> }
>}
>{{{end}}}
-- hugo/content/en/dir1/index.md.golden --
-- golden/hugo/content/en/dir1/index.md.golden --
---
title: JSON Superset
---
Expand Down Expand Up @@ -162,7 +163,7 @@ package site
> }
>}
>{{{end}}}
-- hugo/content/en/dir2/index.md.golden --
-- golden/hugo/content/en/dir2/index.md.golden --
---
title: JSON Superset
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ cp content/dir/en.md content/dir/en.md.writeBack
cmp content/dir/en.md.writeBack content/dir/en.md.writeBack.golden

# Verify that the target files match the source contents
cmp hugo/content/en/dir/index.md hugo/content/en/dir/index.md.golden
cmp hugo/content/en/dir/index.md golden/hugo/content/en/dir/index.md.golden

-- hugo/.keep --
-- content/dir/site.cue --
package site
-- content/dir/en.md --
Expand Down Expand Up @@ -69,7 +70,7 @@ package site
>cue eval in.cue # test
>{{{end}}}
>{{{end}}}
-- hugo/content/en/dir/index.md.golden --
-- golden/hugo/content/en/dir/index.md.golden --
---
title: JSON Superset
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
exec preprocessor execute --debug=all

# Verify golden files
cmp hugo/content/en/dir/_index.md hugo/content/en/dir/_index.md.golden
cmp hugo/content/en/dir/en.txt hugo/content/en/dir/en.txt.golden
cmp hugo/content/en/dir/other.txt hugo/content/en/dir/other.txt.golden
cmp hugo/content/en/dir/_index.md golden/hugo/content/en/dir/_index.md.golden
cmp hugo/content/en/dir/en.txt golden/hugo/content/en/dir/en.txt.golden
cmp hugo/content/en/dir/other.txt golden/hugo/content/en/dir/other.txt.golden

# Ensure that the contents of the filesystem are as expected
exec cmd-find
cmp stdout stdout.golden

-- hugo/.keep --
-- content/dir/site.cue --
package site
-- content/dir/.ignored/ignored.txt --
Expand All @@ -26,13 +27,13 @@ other.txt
_en.md
-- content/dir/_en/en.txt --
en.txt
-- hugo/content/en/dir/_index.md.golden --
-- golden/hugo/content/en/dir/_index.md.golden --
---
---
_en.md
-- hugo/content/en/dir/en.txt.golden --
-- golden/hugo/content/en/dir/en.txt.golden --
en.txt
-- hugo/content/en/dir/other.txt.golden --
-- golden/hugo/content/en/dir/other.txt.golden --
other.txt
-- stdout.golden --
content/dir/.ignored/ignored.txt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cp content/dir/en.md content/dir/en.md.writeBack
cmp content/dir/en.md.writeBack content/dir/en.md.golden

# Verify that the target files matche the source contents
cmp hugo/content/en/dir/index.md hugo/content/en/dir/index.md.golden
cmp hugo/content/en/dir/index.md golden/hugo/content/en/dir/index.md.golden

# Re-run the preprocessor and ensure we have a cache hit
exec preprocessor execute --debug=all
Expand All @@ -33,6 +33,7 @@ stderr $WORK${/}'content'${/}'dir'${/}'en.md: cache hit for content.dir.cache.si
exec preprocessor execute --debug=all --skipcache
stderr $WORK${/}'content'${/}'dir'${/}'en.md: skipping cache for content.dir.cache.sidebyside."json-superset"; was a hit'

-- hugo/.keep --
-- content/dir/site.cue --
package site
-- content/dir/en.md --
Expand Down Expand Up @@ -69,7 +70,7 @@ package site
> example1.cue: no package name
> example2.cue: no package name
>{{{end}}}
-- hugo/content/en/dir/index.md.golden --
-- golden/hugo/content/en/dir/index.md.golden --
---
title: JSON Superset
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cp content/dir/en.md content/dir/en.md.writeBack
cmp content/dir/en.md.writeBack content/dir/en.md.golden

# Verify that the target files matche the source contents
cmp hugo/content/en/dir/index.md hugo/content/en/dir/index.md.golden
cmp hugo/content/en/dir/index.md golden/hugo/content/en/dir/index.md.golden

# Re-run the preprocessor and ensure we have a cache hit
exec preprocessor execute --debug=all
Expand All @@ -26,6 +26,7 @@ stderr $WORK${/}'content'${/}'dir'${/}'en.md: cache hit for content.dir.cache.si
exec preprocessor execute --debug=all --skipcache
stderr $WORK${/}'content'${/}'dir'${/}'en.md: skipping cache for content.dir.cache.sidebyside."json-superset"; was a hit'

-- hugo/.keep --
-- content/dir/site.cue --
package site
-- content/dir/en.md --
Expand Down Expand Up @@ -54,7 +55,7 @@ package site
> "x": 5
>}
>{{{end}}}
-- hugo/content/en/dir/index.md.golden --
-- golden/hugo/content/en/dir/index.md.golden --
---
title: JSON Superset
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cp content/dir/en.md content/dir/en.md.writeBack
cmp content/dir/en.md.writeBack content/dir/en.md.golden

# Verify that the target files matche the source contents
cmp hugo/content/en/dir/index.md hugo/content/en/dir/index.md.golden
cmp hugo/content/en/dir/index.md golden/hugo/content/en/dir/index.md.golden

# Re-run the preprocessor and ensure we have a cache hit
exec preprocessor execute --debug=all
Expand All @@ -34,6 +34,7 @@ stderr $WORK${/}'content'${/}'dir'${/}'en.md: cache hit for content.dir.cache.si
exec preprocessor execute --debug=all --skipcache
stderr $WORK${/}'content'${/}'dir'${/}'en.md: skipping cache for content.dir.cache.sidebyside."json-superset"; was a hit'

-- hugo/.keep --
-- content/dir/site.cue --
package site
-- content/dir/en.md --
Expand Down Expand Up @@ -73,7 +74,7 @@ package site
>
>Some text after
>
-- hugo/content/en/dir/index.md.golden --
-- golden/hugo/content/en/dir/index.md.golden --
---
title: JSON Superset
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ cp content/dir/en.md content/dir/en.md.writeBack
cmp content/dir/en.md.writeBack content/dir/en.md.golden

# Verify that the target files matche the source contents
cmp hugo/content/en/dir/index.md hugo/content/en/dir/index.md.golden
cmp hugo/content/en/dir/index.md golden/hugo/content/en/dir/index.md.golden

-- hugo/.keep --
-- content/dir/site.cue --
package site
-- content/dir/en.md --
Expand All @@ -40,7 +41,7 @@ package site
>
>Some text after
>
-- hugo/content/en/dir/index.md.golden --
-- golden/hugo/content/en/dir/index.md.golden --
---
title: JSON Superset
---
Expand Down

0 comments on commit e7b1655

Please sign in to comment.