hugo
The atago project wrote these specs on its own initiative and runs them in its own CI, to exercise atago against a real program. They are not hugo’s official test suite, and the hugo project is not affiliated with atago.
Summary #
2 suites · 10 scenarios
Contents #
- hugo (scaffold + build CLI, tree-snapshot testbed) — 7 scenarios
- new site scaffolds the documented directory tree
- new content plus a minimal layout builds the public tree
- building outside a site directory fails with a config hint
- scaffolding into a non-empty directory is refused until –force
- creating content that already exists is refused
- drafts stay out of the build until –buildDrafts asks for them
- rebuilding an unchanged site is byte-for-byte idempotent
- hugo server (suite-wide service + http peer) — 3 scenarios
hugo (scaffold + build CLI, tree-snapshot testbed) #
Hugo is a scaffolder and a build tool in one binary, and both produce their result as a directory tree rather than as output on stdout.
That shape is what this suite is about. hugo new site must generate the
documented layout — the whole tree, asserted against a committed snapshot,
so an unexpected new file or a silently dropped one both show up. hugo --minify must then turn content into a built site whose files exist and
contain what they should.
A generator is only trustworthy if the shape of what it generates is trustworthy, which is why the assertion is the tree, not a spot check on one file.
Source: test/e2e/thirdparty/hugo/hugo.atago.yaml
Scenario: new site scaffolds the documented directory tree #
only when hugo version succeeds
When #
hugo new site mysite
Then #
- exit code is
0 - stdout contains
Congratulations - dir
mysitecontainsarchetypes, containsarchetypes/default.md, containsassets, containscontent, containsdata, containshugo.toml, containsi18n, containslayouts, containsstatic, containsthemes, has 2 entries, (recursive) - file
mysite/hugo.tomlcontainsbaseURL
Scenario: new content plus a minimal layout builds the public tree #
only when hugo version succeeds
Given #
- Fixture file
mysite/layouts/home.htmlis created. - Fixture file
mysite/layouts/single.htmlis created. - Fixture file
mysite/layouts/list.htmlis created.
Inputs #
Fixture mysite/layouts/home.html:
<!DOCTYPE html><html><body><h1>HOME</h1>{{ range site.RegularPages }}<a href="{{ .RelPermalink }}">{{ .Title }}</a>{{ end }}</body></html>
Fixture mysite/layouts/single.html:
<!DOCTYPE html><html><body><article><h1>{{ .Title }}</h1>{{ .Content }}</article></body></html>
Fixture mysite/layouts/list.html:
<html><body>{{ range .Pages }}{{ .Title }}{{ end }}</body></html>
When #
hugo new site mysite --quiet
hugo new content posts/hello.md
hugo --minify --buildDrafts
Then #
- after
hugo new content posts/hello.md:- exit code is
0 - file
mysite/content/posts/hello.mdcontainsdraft
- exit code is
- after
hugo --minify --buildDrafts:- exit code is
0 - file
mysite/public/index.htmlcontainsHOME - file
mysite/public/index.htmlcontains/posts/hello/ - file
mysite/public/posts/hello/index.htmlcontains<h1>Hello</h1> - dir
mysite/publiccontainsindex.html, containssitemap.xml, containsposts/hello/index.html, matches glob*.xml, (recursive)
- exit code is
Scenario: building outside a site directory fails with a config hint #
only when hugo version succeeds
When #
hugo
Then #
- exit code is not
0 - stderr matches
/(?i)config/
Scenario: scaffolding into a non-empty directory is refused until –force #
only when hugo version succeeds
Given #
- Fixture file
occupied/keep.txtis created.
Inputs #
Fixture occupied/keep.txt:
not written by hugo
When #
hugo new site occupied
hugo new site occupied --force
Then #
- after
hugo new site occupied:- exit code is
1 - stderr contains
already exists and is not empty,--force - file
occupied/keep.txtcontainsnot written by hugo - dir
occupieddoes not containhugo.toml
- exit code is
- after
hugo new site occupied --force:- exit code is
0 - stdout contains
Congratulations - dir
occupiedcontainshugo.toml, containskeep.txt
- exit code is
Scenario: creating content that already exists is refused #
only when hugo version succeeds
When #
hugo new site mysite --quiet
hugo new content posts/dup.md
hugo new content posts/dup.md
Then #
- after
hugo new content posts/dup.md:- exit code is
0
- exit code is
- after
hugo new content posts/dup.md:- exit code is
1 - stderr contains
conflicts with existing content
- exit code is
Scenario: drafts stay out of the build until –buildDrafts asks for them #
only when hugo version succeeds
Given #
- Fixture file
mysite/layouts/home.htmlis created. - Fixture file
mysite/layouts/single.htmlis created. - Fixture file
mysite/layouts/list.htmlis created.
Inputs #
Fixture mysite/layouts/home.html:
<!DOCTYPE html><html><body><h1>HOME</h1></body></html>
Fixture mysite/layouts/single.html:
<html><body><h1>{{ .Title }}</h1></body></html>
Fixture mysite/layouts/list.html:
<html><body>list</body></html>
When #
hugo new site mysite --quiet
hugo new content posts/draft-post.md
hugo --quiet
hugo --quiet --buildDrafts
Then #
- after
hugo new content posts/draft-post.md:- exit code is
0 - file
mysite/content/posts/draft-post.mdcontainsdraft = true
- exit code is
- after
hugo --quiet:- exit code is
0 - dir
mysite/public/postsdoes not containdraft-post
- exit code is
- after
hugo --quiet --buildDrafts:- exit code is
0 - dir
mysite/public/postscontainsdraft-post - file
mysite/public/posts/draft-post/index.htmlcontainsDraft Post
- exit code is
Scenario: rebuilding an unchanged site is byte-for-byte idempotent #
only when hugo version succeeds
Given #
- Fixture file
mysite/layouts/home.htmlis created.
Inputs #
Fixture mysite/layouts/home.html:
<!DOCTYPE html><html><body><h1>HOME</h1></body></html>
When #
hugo new site mysite --quiet
hugo --quiet
cd mysite && hugo --quiet
Then #
- after
hugo --quiet:- exit code is
0
- exit code is
- after
cd mysite && hugo --quiet:- exit code is
0 - the step changed exactly created nothing, modified nothing, deleted nothing
- exit code is
hugo server (suite-wide service + http peer) #
hugo server is the half of Hugo a developer actually looks at: the site,
served over HTTP, rendered. This suite scaffolds a site, starts the real
development server against it, and then asks for pages the way a browser
would — so what is asserted is the HTML that reached the client.
The ordering is the interesting constraint. A site must exist before a server can serve it, so the scaffold runs first and the server starts at exactly that point in the sequence, once, for the whole suite — the build-then-serve bootstrap every “run my app and test it” setup needs.
Source: test/e2e/thirdparty/hugo/hugo_server.atago.yaml
Scenario: the home page lists the post #
When #
# HTTP GET /
Then #
- HTTP status is
200 - body contains
HOME - body contains
/posts/hello/
Scenario: the post page renders its title #
When #
# HTTP GET /posts/hello/
Then #
- HTTP status is
200 - body contains
<h1>Hello</h1>
Scenario: an unknown path is a 404 #
When #
# HTTP GET /no/such/page/
Then #
- HTTP status is
404