diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-01-04 18:24:36 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-05-16 18:01:29 +0200 |
commit | 241b21b0fd34d91fccb2ce69874110dceae6f926 (patch) | |
tree | d4e0118eac7e9c42f065815447a70805f8d6ad3e /testscripts | |
parent | 6aededf6b42011c3039f5f66487a89a8dd65e0e7 (diff) |
Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code.
Also,
* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.
Closes #10896
Closes #10620
Diffstat (limited to 'testscripts')
25 files changed, 597 insertions, 0 deletions
diff --git a/testscripts/commands/commands_errors.txt b/testscripts/commands/commands_errors.txt new file mode 100644 index 000000000..fcce6197f --- /dev/null +++ b/testscripts/commands/commands_errors.txt @@ -0,0 +1,7 @@ +# Testing various error situations. + +! hugo mods +stderr 'Did you mean this\?' + +! hugo mod clea +stderr 'Did you mean this\?' diff --git a/testscripts/commands/completion.txt b/testscripts/commands/completion.txt new file mode 100644 index 000000000..04d79e3a1 --- /dev/null +++ b/testscripts/commands/completion.txt @@ -0,0 +1,4 @@ +# Test the completion commands. + +hugo completion -h +stdout 'Generate the autocompletion script for hugo for the specified shell.'
\ No newline at end of file diff --git a/testscripts/commands/config.txt b/testscripts/commands/config.txt new file mode 100644 index 000000000..7f8fc4974 --- /dev/null +++ b/testscripts/commands/config.txt @@ -0,0 +1,19 @@ +# Test the config command. + +hugo config -h +stdout 'Print the site configuration' + + +hugo config +stdout '\"baseurl\": \"https://example.com/\",' + +hugo config mounts -h +stdout 'Print the configured file mounts' + +hugo config mounts +stdout '\"source\": \"content\",' + +# Test files +-- hugo.toml -- +baseURL="https://example.com/" +title="My New Hugo Site" diff --git a/testscripts/commands/convert.txt b/testscripts/commands/convert.txt new file mode 100644 index 000000000..1cf756215 --- /dev/null +++ b/testscripts/commands/convert.txt @@ -0,0 +1,42 @@ +# Test the convert commands. + +hugo convert -h +stdout 'Convert your content' +hugo convert toJSON -h +stdout 'to use JSON for the front matter' +hugo convert toTOML -h +stdout 'to use TOML for the front matter' +hugo convert toYAML -h +stdout 'to use YAML for the front matter' + +hugo convert toJSON -o myjsoncontent +stdout 'processing 3 content files' +grep '^{' myjsoncontent/content/mytoml.md +grep '^{' myjsoncontent/content/myjson.md +grep '^{' myjsoncontent/content/myyaml.md +hugo convert toYAML -o myyamlcontent +stdout 'processing 3 content files' +hugo convert toTOML -o mytomlcontent +stdout 'processing 3 content files' + + + + + +-- hugo.toml -- +baseURL = "http://example.org/" +-- content/mytoml.md -- ++++ +title = "TOML" ++++ +TOML content +-- content/myjson.md -- +{ + "title": "JSON" +} +JSON content +-- content/myyaml.md -- +--- +title: YAML +--- +YAML content diff --git a/testscripts/commands/deploy.txt b/testscripts/commands/deploy.txt new file mode 100644 index 000000000..b21bf0b38 --- /dev/null +++ b/testscripts/commands/deploy.txt @@ -0,0 +1,24 @@ +# Test the deploy command. + +hugo deploy -h +stdout 'Deploy your site to a Cloud provider\.' +mkdir mybucket +hugo deploy --target mydeployment +grep 'hello' mybucket/index.html +replace public/index.html 'hello' 'changed' +hugo deploy --target mydeployment --invalidateCDN --dryRun +stdout 'Would upload: index.html' +stdout 'Would invalidate CloudFront CDN with ID foobar' +-- hugo.toml -- +disableKinds = ["RSS", "sitemap", "robotsTXT", "404", "taxonomy", "term"] +baseURL = "https://example.org/" +[deployment] +[[deployment.targets]] +name = "myfirst" +url="gs://asdfasdf" +[[deployment.targets]] +name = "mydeployment" +url="file://./mybucket" +cloudFrontDistributionID = "foobar" +-- public/index.html -- +<html><body>hello</body></html> diff --git a/testscripts/commands/env.txt b/testscripts/commands/env.txt new file mode 100644 index 000000000..742e05ffc --- /dev/null +++ b/testscripts/commands/env.txt @@ -0,0 +1,5 @@ +# Test the hugo env command. + +hugo env +stdout 'GOARCH' +! stderr .
\ No newline at end of file diff --git a/testscripts/commands/gen.txt b/testscripts/commands/gen.txt new file mode 100644 index 000000000..06f060b3c --- /dev/null +++ b/testscripts/commands/gen.txt @@ -0,0 +1,19 @@ +# Test the gen commands. +# Note that adding new commands will require updating the NUM_COMMANDS value. +env NUM_COMMANDS=41 + +hugo gen -h +stdout 'A collection of several useful generators\.' + +hugo gen doc --dir clidocs +checkfilecount $NUM_COMMANDS clidocs + +hugo gen man -h +stdout 'up-to-date man pages' +hugo gen man --dir manpages +checkfilecount $NUM_COMMANDS manpages + +hugo gen chromastyles -h +stdout 'Generate CSS stylesheet for the Chroma code highlighter' +hugo gen chromastyles --style monokai +stdout 'color: #f8f8f2'
\ No newline at end of file diff --git a/testscripts/commands/hugo.txt b/testscripts/commands/hugo.txt new file mode 100644 index 000000000..7dfabe592 --- /dev/null +++ b/testscripts/commands/hugo.txt @@ -0,0 +1,19 @@ +# Test the hugo command. + +hugo +stdout 'Pages.*|1' +stdout 'Total in' +checkfile public/index.html +checkfile public/p1/index.html + +-- hugo.toml -- +baseURL = "http://example.org/" +disableKinds = ["RSS", "sitemap", "robotsTXT", "404", "taxonomy", "term"] +-- layouts/index.html -- +Home. +-- layouts/_default/single.html -- +Title: {{ .Title }} +-- content/p1.md -- +--- +title: "P1" +--- diff --git a/testscripts/commands/hugo__errors.txt b/testscripts/commands/hugo__errors.txt new file mode 100644 index 000000000..2400ce69b --- /dev/null +++ b/testscripts/commands/hugo__errors.txt @@ -0,0 +1,18 @@ +# Testing error output. + +# The hugo mod get command handles flags a little special, but the -h flag should print the help. +hugo mod get -h +stdout 'Resolves dependencies in your current Hugo Project' + +# Invalid flag. Should print an error message to stderr and the help to stdout. +! hugo --asdf +stderr 'unknown flag: --asdf' +stdout 'hugo is the main command' + +# This should fail the build, print an error message to stderr, but no help output. +! hugo +! stdout 'hugo is the main command' +stderr 'failed to load config' + +-- hugo.toml -- +invalid: toml
\ No newline at end of file diff --git a/testscripts/commands/hugo__flags.txt b/testscripts/commands/hugo__flags.txt new file mode 100644 index 000000000..46243f8a9 --- /dev/null +++ b/testscripts/commands/hugo__flags.txt @@ -0,0 +1,27 @@ +# Test the hugo command. + +hugo --baseURL http://example.com/ --destination ${WORK}/newpublic --clock 2021-11-06T22:30:00.00+09:00 -e staging --config ${WORK}/myconfig --configDir ${WORK}/myconfigdir -s mysource +stdout 'Pages.*|1' +stdout 'Total in' +grep 'Home: http://example.com/, Time: 2021-11-06' newpublic/index.html +grep 'Environment: staging, foo: bar, bar: baz' newpublic/index.html + +hugo --quiet +! stdout . + +-- myconfig.toml -- +baseURL = "http://example.org/" +disableKinds = ["RSS", "sitemap", "robotsTXT", "404", "taxonomy", "term"] +[params] +foo = "bar" +-- myconfigdir/_default/params.toml -- +bar = "baz" +-- mysource/layouts/index.html -- +Home: {{ .Permalink }}, Time: {{ now }} +Environment: {{ hugo.Environment }}, foo: {{ .Site.Params.foo }}, bar: {{ .Site.Params.bar }} +-- mysource/layouts/_default/single.html -- +Title: {{ .Title }} +-- mysource/content/p1.md -- +--- +title: "P1" +--- diff --git a/testscripts/commands/hugo__watch.txt b/testscripts/commands/hugo__watch.txt new file mode 100644 index 000000000..b434bd112 --- /dev/null +++ b/testscripts/commands/hugo__watch.txt @@ -0,0 +1,28 @@ +# Test the hugo command. + +# See https://github.com/rogpeppe/go-internal/issues/228 +[windows] skip + +hugo -w & + +sleep 3 +grep 'P1start' public/p1/index.html + +replace content/p1.md 'P1start' 'P1end' +sleep 2 +grep 'P1end' public/p1/index.html + +stop + +-- hugo.toml -- +baseURL = "http://example.org/" +disableKinds = ["RSS", "sitemap", "robotsTXT", "404", "taxonomy", "term"] +-- layouts/index.html -- +Home. +-- layouts/_default/single.html -- +Title: {{ .Title }}| {{ .Content }} +-- content/p1.md -- +--- +title: "P1" +--- +P1start
\ No newline at end of file diff --git a/testscripts/commands/import_jekyll.txt b/testscripts/commands/import_jekyll.txt new file mode 100644 index 000000000..8d229ba2e --- /dev/null +++ b/testscripts/commands/import_jekyll.txt @@ -0,0 +1,19 @@ +# Test the import jekyll command. + +hugo import -h +stdout 'Import your site from other web site generators like Jekyll\.' + +hugo import jekyll -h +stdout 'hugo import from Jekyll\.' + +hugo import jekyll myjekyllsite myhugosite +checkfilecount 1 myhugosite/content/post +grep 'example\.org' myhugosite/hugo.yaml + +# A simple Jekyll site. +-- myjekyllsite/_posts/2012-01-18-hello-world.markdown -- +--- +layout: post +title: "Hello World" +--- +Hello world! diff --git a/testscripts/commands/list.txt b/testscripts/commands/list.txt new file mode 100644 index 000000000..68d1097d7 --- /dev/null +++ b/testscripts/commands/list.txt @@ -0,0 +1,34 @@ +# Test the hugo list commands. + +hugo list drafts +! stderr . +stdout 'draft.md,2019-01-01T00:00:00Z' + +hugo list future +stdout 'future.md,2030-01-01T00:00:00Z' + +hugo list expired +stdout 'expired.md,2018-01-01T00:00:00Z' + +hugo list all +stdout 'future.md,2030-01-01T00:00:00Z' +stdout 'draft.md,2019-01-01T00:00:00Z' +stdout 'expired.md,2018-01-01T00:00:00Z' + +-- hugo.toml -- +baseURL = "https://example.org/" +disableKinds = ["taxonomy", "term"] +-- content/draft.md -- +--- +draft: true +date: 2019-01-01 +--- +-- content/expired.md -- +--- +date: 2018-01-01 +expiryDate: 2019-01-01 +--- +-- content/future.md -- +--- +date: 2030-01-01 +---
\ No newline at end of file diff --git a/testscripts/commands/mod.txt b/testscripts/commands/mod.txt new file mode 100644 index 000000000..a2ea0ad24 --- /dev/null +++ b/testscripts/commands/mod.txt @@ -0,0 +1,44 @@ +# Test the hugo mod commands. + +dostounix golden/vendor.txt +dostounix golden/go.mod.testsubmod + +hugo mod graph +stdout 'empty-hugo' +hugo mod verify +! stderr . +hugo mod get -u +! stderr . +hugo mod get -u ./... +! stderr . +hugo mod vendor +! stderr . +cmp _vendor/modules.txt golden/vendor.txt +hugo mod clean +! stderr . +stdout 'hugo: removed 1 dirs in module cache for \"github.com/bep/empty-hugo-module\"' +hugo mod clean --all +stdout 'Deleted 2\d{2} files from module cache\.' +cd submod +hugo mod init testsubmod +cmpenv go.mod $WORK/golden/go.mod.testsubmod +-- hugo.toml -- +title = "Hugo Modules Test" +[module] +[[module.imports]] +path="github.com/bep/empty-hugo-module" +[[module.imports.mounts]] +source="README.md" +target="content/_index.md" +-- go.mod -- +go 1.19 + +module github.com/gohugoio/testmod +-- submod/hugo.toml -- +title = "Hugo Sub Module" +-- golden/vendor.txt -- +# github.com/bep/empty-hugo-module v1.0.0 +-- golden/go.mod.testsubmod -- +module testsubmod + +go ${GOVERSION} diff --git a/testscripts/commands/mod_npm.txt b/testscripts/commands/mod_npm.txt new file mode 100644 index 000000000..fb0aa38c8 --- /dev/null +++ b/testscripts/commands/mod_npm.txt @@ -0,0 +1,23 @@ +# Test mod npm. + +hugo mod npm pack +cmp package.hugo.json golden/package.hugo.json + +-- hugo.toml -- +baseURL = "https://example.org/" +-- package.json -- +{ + "name": "test", + "version": "1.0.0", + "dependencies": { + "mod": "foo-bar" + } +} +-- golden/package.hugo.json -- +{ + "name": "test", + "version": "1.0.0", + "dependencies": { + "mod": "foo-bar" + } +} diff --git a/testscripts/commands/mod_tidy.txt b/testscripts/commands/mod_tidy.txt new file mode 100644 index 000000000..6e8d37f64 --- /dev/null +++ b/testscripts/commands/mod_tidy.txt @@ -0,0 +1,21 @@ +# Test hugo mod tidy. + +dostounix golden/go.mod.cleaned + +hugo mod tidy + +cmp go.mod golden/go.mod.cleaned + +-- hugo.toml -- +title = "Hugo Modules Test" +-- go.mod -- +go 1.19 + +require github.com/bep/empty-hugo-module v1.0.0 + +module github.com/gohugoio/testmod +-- golden/go.mod.cleaned -- +go 1.19 + + +module github.com/gohugoio/testmod diff --git a/testscripts/commands/new.txt b/testscripts/commands/new.txt new file mode 100644 index 000000000..11fe753b9 --- /dev/null +++ b/testscripts/commands/new.txt @@ -0,0 +1,27 @@ +# Test the new command. + +hugo new site -h +stdout 'Create a new site in the provided directory' +hugo new site mysite +stdout 'Congratulations! Your new Hugo site is created in' +cd mysite +checkfile hugo.toml + +hugo new theme -h +stdout 'Create a new site in the provided directory' +hugo new theme mytheme +stdout 'Creating theme' +cd themes +cd mytheme +checkfile theme.toml +checkfile hugo.toml +exists layouts/_default/list.html +exists layouts/_default/single.html + +cd $WORK/mysite + +hugo new -h +stdout 'Create a new content file.' +hugo new posts/my-first-post.md +checkfile content/posts/my-first-post.md + diff --git a/testscripts/commands/server.txt b/testscripts/commands/server.txt new file mode 100644 index 000000000..1316356eb --- /dev/null +++ b/testscripts/commands/server.txt @@ -0,0 +1,30 @@ +# Test the hugo server command. + +# We run these tests in parallel so let Hugo decide which port to use. +hugo server & + +waitServer + +httpget $HUGOTEST_BASEURL_0 'Title: Hugo Server Test' $HUGOTEST_BASEURL_0 'ServerPort: \d{4,5}' 'myenv: thedevelopment' 'livereload\.js' 'Env: development' 'IsServer: true' +httpget ${HUGOTEST_BASEURL_0}doesnotexist 'custom 404' + +# By defauilt, the server renders to memory. +! exists public/index.html + +stopServer +! stderr . + +-- hugo.toml -- +title = "Hugo Server Test" +baseURL = "https://example.org/" +disableKinds = ["taxonomy", "term", "sitemap"] +-- config/production/params.toml -- +myenv = "theproduction" +-- config/development/params.toml -- +myenv = "thedevelopment" +-- layouts/index.html -- +<body> +Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}|ServerPort: {{ site.ServerPort }}|myenv: {{ .Site.Params.myenv }}|Env: {{ hugo.Environment }}|IsServer: {{ site.IsServer }}| +</body> +-- layouts/404.html -- +custom 404 diff --git a/testscripts/commands/server__edit_config.txt b/testscripts/commands/server__edit_config.txt new file mode 100644 index 000000000..e3972bf07 --- /dev/null +++ b/testscripts/commands/server__edit_config.txt @@ -0,0 +1,43 @@ +# Test the hugo server command when editing the config file. + +# We run these tests in parallel so let Hugo decide which port to use. +hugo server & + +waitServer + +httpget $HUGOTEST_BASEURL_0 'Title: Hugo Server Test' $HUGOTEST_BASEURL_0 + +mv edits/title.toml hugo.toml + +httpget $HUGOTEST_BASEURL_0 'Title: Hugo New Server Test' $HUGOTEST_BASEURL_0 + +mv edits/addlanguage.toml hugo.toml + +httpget $HUGOTEST_BASEURL_0 'Title: Hugo New Server Test' $HUGOTEST_BASEURL_0 +httpget ${HUGOTEST_BASEURL_0}nn/ 'Hugo Nynorsk Server Test' ${HUGOTEST_BASEURL_0}nn/ + +stopServer +! stderr . + +-- hugo.toml -- +title = "Hugo Server Test" +baseURL = "https://example.org/" +-- edits/title.toml -- +title = "Hugo New Server Test" +baseURL = "https://example.org/" +-- edits/addlanguage.toml -- +title = "Hugo New Server Test" +baseURL = "https://example.org/" +[languages] +[languages.en] +languageName = "English" +weight = 1 +[languages.nn] +languageName = "Nynorsk" +title = "Hugo Nynorsk Server Test" +weight = 2 + +-- layouts/index.html -- +Title: {{ .Title }}|BaseURL: {{ .Permalink }}| + + diff --git a/testscripts/commands/server__edit_content.txt b/testscripts/commands/server__edit_content.txt new file mode 100644 index 000000000..5a2d9d502 --- /dev/null +++ b/testscripts/commands/server__edit_content.txt @@ -0,0 +1,55 @@ +# Test the hugo server command when editing content. + +# We run these tests in parallel so let Hugo decide which port to use. +# Render to disk so we can check the /public dir. +hugo server --renderToDisk & + +waitServer + +httpget ${HUGOTEST_BASEURL_0}p1/ 'Title: P1' $HUGOTEST_BASEURL_0 + +ls public/p2 +cp stdout lsp2_1.txt +ls public/staticfiles +stdout 'static\.txt' +cp stdout lsstaticfiles_1.txt + +replace $WORK/content/p1/index.md 'P1' 'P1 New' + +httpget ${HUGOTEST_BASEURL_0}p1/ 'Title: P1 New' $HUGOTEST_BASEURL_0 + +ls public/p2 +cp stdout lsp2_2.txt +cmp lsp2_1.txt lsp2_2.txt +ls public/staticfiles +cp stdout lsstaticfiles_2.txt +cmp lsstaticfiles_1.txt lsstaticfiles_2.txt + +stopServer +! stderr . + +-- hugo.toml -- +title = "Hugo Server Test" +baseURL = "https://example.org/" +disableKinds = ["taxonomy", "term", "sitemap"] +-- layouts/index.html -- +Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}| +-- layouts/_default/single.html -- +Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}| +-- content/_index.md -- +--- +title: Hugo Home +--- +-- content/p1/index.md -- +--- +title: P1 +--- +-- content/p2/index.md -- +--- +title: P2 +--- +-- static/staticfiles/static.txt -- +static + + + diff --git a/testscripts/commands/server__multihost.txt b/testscripts/commands/server__multihost.txt new file mode 100644 index 000000000..492cac855 --- /dev/null +++ b/testscripts/commands/server__multihost.txt @@ -0,0 +1,32 @@ +# Test the hugo server command. + +# We run these tests in parallel so let Hugo decide which port to use. +hugo server & + +waitServer + +httpget $HUGOTEST_BASEURL_0 'Title: Hugo Server Test' $HUGOTEST_BASEURL_0 +httpget $HUGOTEST_BASEURL_1 'Title: Hugo Serveur Test' $HUGOTEST_BASEURL_1 + +stopServer +! stderr . + +-- hugo.toml -- +title = "Hugo Server Test" +baseURL = "https://example.org/" +disableKinds = ["taxonomy", "term", "sitemap"] +[languages] +[languages.en] +baseURL = "https://en.example.org/" +languageName = "English" +title = "Hugo Server Test" +weight = 1 +[languages.fr] +baseURL = "https://fr.example.org/" +title = "Hugo Serveur Test" +languageName = "Français" +weight = 2 +-- layouts/index.html -- +Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}| + + diff --git a/testscripts/commands/server_render_static_to_disk.txt b/testscripts/commands/server_render_static_to_disk.txt new file mode 100644 index 000000000..f2f10e78f --- /dev/null +++ b/testscripts/commands/server_render_static_to_disk.txt @@ -0,0 +1,25 @@ +# Test the hugo server command. + +# We run these tests in parallel so let Hugo decide which port to use. +hugo server --renderStaticToDisk & + +waitServer + +httpget $HUGOTEST_BASEURL_0 'Title: Hugo Server Test' $HUGOTEST_BASEURL_0 + +! exists public/index.html +exists public/mystatic.txt + +stopServer +! stderr . + +-- hugo.toml -- +title = "Hugo Server Test" +baseURL = "https://example.org/" +disableKinds = ["taxonomy", "term", "sitemap"] +-- static/mystatic.txt -- +This is a static file. +-- layouts/index.html -- +Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}| + + diff --git a/testscripts/commands/server_render_to_memory.txt b/testscripts/commands/server_render_to_memory.txt new file mode 100644 index 000000000..53ab74aa5 --- /dev/null +++ b/testscripts/commands/server_render_to_memory.txt @@ -0,0 +1,25 @@ +# Test the hugo server command. + +# We run these tests in parallel so let Hugo decide which port to use. +hugo server & + +waitServer + +httpget $HUGOTEST_BASEURL_0 'Title: Hugo Server Test' $HUGOTEST_BASEURL_0 + +! exists public/index.html +! exists public/mystatic.txt + +stopServer +! stderr . + +-- hugo.toml -- +title = "Hugo Server Test" +baseURL = "https://example.org/" +disableKinds = ["taxonomy", "term", "sitemap"] +-- static/mystatic.txt -- +This is a static file. +-- layouts/index.html -- +Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}| + + diff --git a/testscripts/commands/version.txt b/testscripts/commands/version.txt new file mode 100644 index 000000000..25fbbc85f --- /dev/null +++ b/testscripts/commands/version.txt @@ -0,0 +1,7 @@ +# Test the hugo version command. + +hugo -h +stdout 'hugo is the main command, used to build your Hugo site' + +hugo version +stdout 'hugo v.* BuildDate=unknown' diff --git a/testscripts/unfinished/noop.txt b/testscripts/unfinished/noop.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/testscripts/unfinished/noop.txt |