Skip to content

Commit 91c665a

Browse files
authored
Merge pull request #12214 from quarto-dev/execute-header-include
correctly shallow copy nested element for includes
2 parents 0502c32 + b523ebf commit 91c665a

File tree

18 files changed

+57
-31
lines changed

18 files changed

+57
-31
lines changed

src/command/render/freeze.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ export function freezeExecuteResult(
5353
result: ExecuteResult,
5454
) {
5555
// resolve includes within executeResult
56+
// nb: Beware to not modify the original result object
5657
const innerResult = {
5758
...result,
59+
includes: result.includes ? { ...result.includes } : undefined,
5860
} as ExecuteResult;
5961
const resolveIncludes = (
6062
name: "include-in-header" | "include-before-body" | "include-after-body",

tests/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Python Environments
22
.env
33
.venv
4-
env/
5-
venv/
4+
/env/
5+
/venv/
66
ENV/
77
env.bak/
88
venv.bak/

tests/docs/smoke-all/2024/06/19/9208.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ _quarto:
88
html:
99
noErrors: true
1010
printsMessage:
11-
- WARN
12-
- 'code-link.*ignored'
11+
level: WARN
12+
regex: 'code-link.*ignored'
1313
ensureHtmlElements:
1414
- []
1515
- ['pre.downlit']

tests/docs/smoke-all/2024/08/30/10291/latex-hyphen-lang-es-no-install.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ _quarto:
77
pdf:
88
noErrors: true
99
printsMessage:
10-
- WARN
11-
- 'missing hyphenation.*hyphen-spanish'
10+
level: WARN
11+
regex: 'missing hyphenation.*hyphen-spanish'
1212
---
1313

1414
```{r}

tests/docs/smoke-all/2024/09/30/10931-2.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ _quarto:
55
tests:
66
pptx:
77
printsMessage:
8-
- INFO
9-
- 'WARNING.*FloatRefTargets require'
8+
level: INFO
9+
regex: 'WARNING.*FloatRefTargets require'
1010
ensurePptxXpath:
1111
-
1212
- 2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.quarto/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project:
2+
type: default
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
format: html
3+
engine: julia
4+
_quarto:
5+
tests:
6+
html:
7+
printsMessage:
8+
level: INFO
9+
regex: 'FATAL[\s\S]*Error resolving header-includes'
10+
negate: true
11+
---
12+
13+
```{julia}
14+
?for
15+
```

tests/docs/smoke-all/crossrefs/float/latex/latex-raw-table-env-no-tbl-label.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ _quarto:
99
- ['[\s\S]+\\begin\{table\}\[htbp\][\s\S]+', '[\s\S]+\\caption\{\\label\{mod\}']
1010
- []
1111
printsMessage:
12-
- INFO
13-
- 'WARNING(.*)Raw LaTeX table found with non-tbl label:'
12+
level: INFO
13+
regex: 'WARNING(.*)Raw LaTeX table found with non-tbl label:'
1414
---
1515

1616
This document has a raw LaTeX table with no intent to use quarto crossref. It uses a label with `tbl-` id.

tests/smoke/env/check.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ testQuartoCmd(
1212
[],
1313
[
1414
noErrorsOrWarnings,
15-
printsMessage("INFO", /Version: 99\.9\.9/),
15+
printsMessage({level: "INFO", regex: /Version: 99\.9\.9/}),
1616
],
1717
);

tests/smoke/env/install.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ testQuartoCmd(
1212
["list"],
1313
[
1414
noErrorsOrWarnings,
15-
printsMessage("INFO", /tinytex\s+/),
16-
// printsMessage("INFO", /chromium\s+/),
15+
printsMessage({level: "INFO", regex: /tinytex\s+/}),
16+
// printsMessage({level: "INFO", regex: /chromium\s+/}),
1717
// temporarily disabled until we get puppeteer back
1818
],
1919
);

tests/smoke/jupyter/cache.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test({
4141
verify: [
4242
folderExists(cacheFolder),
4343
// this will check only for the second render that should be read from cache
44-
printsMessage("INFO", /Notebook read from cache/)
44+
printsMessage({ level: "INFO", regex: /Notebook read from cache/})
4545
],
4646
type: "smoke",
4747
});
@@ -82,7 +82,7 @@ test({
8282
verify: [
8383
folderExists(cacheFolder2),
8484
// this will check only for the second render that should be read from cache
85-
printsMessage("INFO", /Notebook read from cache/)
85+
printsMessage({level: "INFO", regex: /Notebook read from cache/})
8686
],
8787
type: "smoke",
8888
});

tests/smoke/project/project-prepost.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ testQuartoCmd(
3636

3737

3838

39-
// Tests that if the pre-renderf script mutates the output directory
39+
// Tests that if the pre-render script mutates the output directory
4040
// we throw an error that complains about this.
4141
const mutateRenderDir = docs("project/prepost/invalid-mutate");
4242
const mutateRenderDirAbs = join(Deno.cwd(), mutateRenderDir);
@@ -45,7 +45,7 @@ const mutateRenderOutDir = join(mutateRenderDirAbs, "_site");
4545
testQuartoCmd(
4646
"render",
4747
[mutateRenderDir],
48-
[printsMessage("ERROR", /output-dir may not be mutated/gm)],
48+
[printsMessage({level: "ERROR", regex: /output-dir may not be mutated/gm})],
4949
{
5050
teardown: async () => {
5151
const mdClean = join(mutateRenderDirAbs, "_metadata.yml");

tests/smoke/smoke-all.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ function resolveTestSpecs(
160160
verifyFns.push(verifyMap[key](outputFile.outputPath, ...value));
161161
}
162162
} else if (key === "printsMessage") {
163-
verifyFns.push(verifyMap[key](...value));
163+
verifyFns.push(verifyMap[key](value));
164164
} else if (verifyMap[key]) {
165165
// FIXME: We should find another way that having this requirement of keep-* in the metadata
166166
if (key === "ensureTypstFileRegexMatches") {
@@ -325,7 +325,7 @@ Promise.all(testFilesPromises).then(() => {
325325
for (const project of testedProjects) {
326326
// Clean project output directory
327327
const projectOutDir = join(project, findProjectOutputDir(project));
328-
if (safeExistsSync(projectOutDir)) {
328+
if (projectOutDir !== project && safeExistsSync(projectOutDir)) {
329329
safeRemoveSync(projectOutDir, { recursive: true });
330330
}
331331
// Clean hidden .quarto directory

tests/smoke/use/template.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ ensureDirSync(nonEmptyWorkingDir);
3939
testQuartoCmd(
4040
"use",
4141
["template", "quarto-journals/jasa", "--no-prompt"],
42-
[printsMessage("ERROR", /directory isn't empty/), directoryContainsOnlyAllowedPaths(nonEmptyWorkingDir, [nonEmptyFileName])],
42+
[printsMessage({level: "ERROR", regex: /directory isn't empty/}), directoryContainsOnlyAllowedPaths(nonEmptyWorkingDir, [nonEmptyFileName])],
4343
{
4444
setup: () => {
4545
Deno.writeTextFileSync(join(nonEmptyWorkingDir, nonEmptyFileName), "Just making a non-empty file!");

tests/smoke/yaml-intelligence/yaml-intelligence-code-cell-options.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const testYamlValidationFails = (file: string) => {
88
testQuartoCmd(
99
"render",
1010
[yamlDocs(file, "html").input, "--to", "html", "--quiet"],
11-
[printsMessage("ERROR", /Validation of YAML cell metadata failed/)],
11+
[printsMessage({level: "ERROR", regex: /Validation of YAML cell metadata failed/})],
1212
);
1313
};
1414

tests/smoke/yaml/config-yaml-validation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ const input = docs("yaml/bad-config-yaml/subfolder/bad-config-yaml.qmd");
1414
testQuartoCmd(
1515
"render",
1616
[input],
17-
[printsMessage("ERROR", /bad-config-yaml[\/\\]+_quarto[.]yml validation failed/)]
17+
[printsMessage({level: "ERROR", regex: /bad-config-yaml[\/\\]+_quarto[.]yml validation failed/})]
1818
);

tests/verify.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,26 @@ export const noErrorsOrWarnings: Verify = {
133133
},
134134
};
135135

136-
export const printsMessage = (
137-
level: "DEBUG" | "INFO" | "WARN" | "ERROR",
138-
regex: RegExp | string,
139-
): Verify => {
136+
export const printsMessage = (options: {
137+
level: "DEBUG" | "INFO" | "WARN" | "ERROR";
138+
regex: string | RegExp;
139+
negate?: boolean;
140+
}): Verify => {
141+
const { level, regex: regexPattern, negate = false } = options; // Set default here
140142
return {
141-
name: `${level} matches ${String(regex)}`,
143+
name: `${level} matches ${String(regexPattern)}`,
142144
verify: (outputs: ExecuteOutput[]) => {
143-
if (typeof regex === "string") {
144-
regex = new RegExp(regex);
145-
}
145+
const regex = typeof regexPattern === "string"
146+
? new RegExp(regexPattern)
147+
: regexPattern;
148+
146149
const printedMessage = outputs.some((output) => {
147150
return output.levelName === level && output.msg.match(regex);
148151
});
149-
assert(printedMessage, `Missing ${level} ${String(regex)}`);
152+
assert(
153+
negate ? !printedMessage : printedMessage,
154+
`${negate ? "Found" : "Missing"} ${level} ${String(regex)}`
155+
);
150156
return Promise.resolve();
151157
},
152158
};

0 commit comments

Comments
 (0)