-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
preprocessor: add execute --check flag to validate page CUE
Our "mode" of loading the configuration for the cuelang.org site involves globbing CUE files found at page roots and presenting all those files to cue/load.Instances. The issue tracking adding more standard modes to cue/load is https://cuelang.org/issue/2018. Our mode of loading also seeks to enforce that a page rooted at content/a/b only declares CUE values under that path: content: a: b: { // ... } This commit adds a --check flag to the execute command that enforces this. It also adds this check to CI to enforce it. Preprocessor-No-Write-Cache: true Signed-off-by: Paul Jolly <[email protected]> Change-Id: Id963877e586b230f221b2e7843dc48471e86d1b7 Dispatch-Trailer: {"type":"trybot","CL":1170108,"patchset":3,"ref":"refs/changes/08/1170108/3","targetBranch":"alpha"}
- Loading branch information
Showing
5 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
internal/cmd/preprocessor/cmd/testdata/execute_check.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Ensure that we get no output when --check succeeds | ||
|
||
# Run the preprocessor | ||
exec preprocessor execute --check | ||
! stdout .+ | ||
|
||
-- content/dir1/page.cue -- | ||
package site | ||
|
||
// Page value defined | ||
content: dir1: {} | ||
-- content/dir1/en.md -- | ||
--- | ||
title: JSON Superset | ||
--- | ||
-- content/dir2/page.cue -- | ||
package site | ||
|
||
// Only content defined | ||
content: {} | ||
-- content/dir1/en.md -- | ||
--- | ||
title: JSON Superset | ||
--- | ||
-- content/dir3/page.cue -- | ||
package site | ||
|
||
// No value defined | ||
-- content/dir3/en.md -- | ||
--- | ||
title: JSON Superset | ||
--- | ||
-- hugo/content/.gitkeep -- |
21 changes: 21 additions & 0 deletions
21
internal/cmd/preprocessor/cmd/testdata/execute_err_bad_page_cue.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Ensure that we get a sensible error message when using the | ||
# --check flag to execute. | ||
|
||
unquote content/dir/en.md | ||
|
||
# Run the preprocessor | ||
! exec preprocessor execute --check | ||
cmpenv stderr stderr.golden | ||
|
||
-- content/dir/page.cue -- | ||
package site | ||
|
||
this: 5 | ||
-- content/dir/en.md -- | ||
>--- | ||
>title: JSON Superset | ||
>--- | ||
-- hugo/content/.gitkeep -- | ||
-- stderr.golden -- | ||
** $WORK/content/dir/page.cue:3: this: field not allowed; expected "content" | ||
terminating because of errors |