Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package/scripts/common/quarto
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ else
export DENO_DOM_PLUGIN=$QUARTO_BIN_PATH/tools/${ARCH_DIR}/deno_dom/libplugin.so
fi


if [ "$QUARTO_DENO" == "" ]; then
DENO_ARCH_DIR=$ARCH_DIR
export QUARTO_DENO="${SCRIPT_PATH}/tools/${DENO_ARCH_DIR}/deno"
Expand Down
16 changes: 15 additions & 1 deletion src/command/render/flags.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* flags.ts
*
* Copyright (C) 2020-2022 Posit Software, PBC
* Copyright (C) 2020-2024 Posit Software, PBC
*/
import { existsSync } from "../../deno_ral/fs.ts";

Expand Down Expand Up @@ -344,6 +344,19 @@ export async function parseRenderFlags(args: string[]) {
}
break;

case "--env":
arg = argsStack.shift();
if (arg) {
const metadata = parseMetadataFlagValue(arg);
if (metadata) {
if (flags["env"] === undefined) {
flags["env"] = {};
}
flags["env"][metadata.name] = String(metadata.value);
}
}
break;

default:
arg = argsStack.shift();
break;
Expand Down Expand Up @@ -448,6 +461,7 @@ export function fixupPandocArgs(pandocArgs: string[], flags: RenderFlags) {
removeArgs.set("--quiet", false);
removeArgs.set("--q", false);
removeArgs.set("--profile", true);
removeArgs.set("--env", true);

// Remove un-needed pandoc args (including -M/--metadata as appropriate)
pandocArgs = removePandocArgs(pandocArgs, removeArgs);
Expand Down
2 changes: 1 addition & 1 deletion src/command/render/pandoc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* pandoc.ts
*
* Copyright (C) 2020-2022 Posit Software, PBC
* Copyright (C) 2020-2023 Posit Software, PBC
*/

import { basename, dirname, isAbsolute, join } from "../../deno_ral/path.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/command/render/render-files.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* render-files.ts
*
* Copyright (C) 2020-2022 Posit Software, PBC
* Copyright (C) 2020-2023 Posit Software, PBC
*/

// ensures cell handlers are installed
Expand Down
2 changes: 1 addition & 1 deletion src/command/render/render.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* render.ts
*
* Copyright (C) 2020-2022 Posit Software, PBC
* Copyright (C) 2020-2023 Posit Software, PBC
*/

import { ensureDirSync, existsSync } from "../../deno_ral/fs.ts";
Expand Down
3 changes: 2 additions & 1 deletion src/command/render/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* types.ts
*
* Copyright (C) 2020-2022 Posit Software, PBC
* Copyright (C) 2020-2023 Posit Software, PBC
*/

import { Document } from "../../core/deno-dom.ts";
Expand Down Expand Up @@ -248,6 +248,7 @@ export interface RenderFlags extends PandocFlags {
debug?: boolean;
quiet?: boolean;
version?: string;
env?: Record<string, string>;
}

export interface OutputRecipe {
Expand Down
3 changes: 2 additions & 1 deletion src/execute/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* types.ts
*
* Copyright (C) 2020-2022 Posit Software, PBC
* Copyright (C) 2020-2023 Posit Software, PBC
*/
import {
kIncludeAfterBody,
Expand Down Expand Up @@ -89,6 +89,7 @@ export interface ExecuteOptions {
quiet?: boolean;
previewServer?: boolean;
handledLanguages: string[]; // list of languages handled by cell language handlers, after the execution engine
env?: Record<string, string>;
project?: ProjectContext;
}

Expand Down
9 changes: 9 additions & 0 deletions src/resources/filters/ast/runemulation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,14 @@ function run_as_extended_ast(specTable)
end
end

if luacov_runner ~= nil then
table.insert(pandocFilterList, {
Pandoc = function(doc)
luacov_runner.shutdown()
return nil
end
})
end

return pandocFilterList
end
2 changes: 1 addition & 1 deletion src/resources/pandoc/datadir/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ function require(modname)
end

if os.getenv("QUARTO_LUACOV") ~= nil then
require("luacov")
luacov_runner = require("luacov")
end

-- resolves a path, providing either the original path
Expand Down
110 changes: 55 additions & 55 deletions src/resources/pandoc/datadir/luacov/reporter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local reporter = {}
local LineScanner = require("luacov.linescanner")
local luacov = require("luacov.runner")
local util = require("luacov.util")
local lfs_ok, lfs = pcall(require, "lfs")
-- local lfs_ok, lfs = pcall(require, "lfs")

----------------------------------------------------------------
local dir_sep = package.config:sub(1, 1)
Expand Down Expand Up @@ -97,60 +97,60 @@ function ReporterBase:new(conf)

-- including files without tests
-- only .lua files
if conf.includeuntestedfiles then
if not lfs_ok then
print("The option includeuntestedfiles requires the lfs module (from luafilesystem) to be installed.")
os.exit(1)
end

local function add_empty_file_coverage_data(file_path)

-- Leading "./" must be trimmed from the file paths because the paths of tested
-- files do not have a leading "./" either
if (file_path:match("^%.[/\\]")) then
file_path = file_path:sub(3)
end

if luacov.file_included(file_path) then
local file_stats = {
max = 0,
max_hits = 0
}

local filename = luacov.real_name(file_path)

if not filtered_data[filename] then
table.insert(files, filename)
filtered_data[filename] = file_stats
end
end

end

local function add_empty_dir_coverage_data(directory_path)

for filename, attr in dirtree(directory_path) do
if attr.mode == "file" and fileMatches(filename, '.%.lua$') then
add_empty_file_coverage_data(filename)
end
end

end

if (conf.includeuntestedfiles == true) then
add_empty_dir_coverage_data("." .. dir_sep)

elseif (type(conf.includeuntestedfiles) == "table" and conf.includeuntestedfiles[1]) then
for _, include_path in ipairs(conf.includeuntestedfiles) do
if (fileMatches(include_path, '.%.lua$')) then
add_empty_file_coverage_data(include_path)
else
add_empty_dir_coverage_data(include_path)
end
end
end

end
-- if conf.includeuntestedfiles then
-- if not lfs_ok then
-- print("The option includeuntestedfiles requires the lfs module (from luafilesystem) to be installed.")
-- os.exit(1)
-- end

-- local function add_empty_file_coverage_data(file_path)

-- -- Leading "./" must be trimmed from the file paths because the paths of tested
-- -- files do not have a leading "./" either
-- if (file_path:match("^%.[/\\]")) then
-- file_path = file_path:sub(3)
-- end

-- if luacov.file_included(file_path) then
-- local file_stats = {
-- max = 0,
-- max_hits = 0
-- }

-- local filename = luacov.real_name(file_path)

-- if not filtered_data[filename] then
-- table.insert(files, filename)
-- filtered_data[filename] = file_stats
-- end
-- end

-- end

-- local function add_empty_dir_coverage_data(directory_path)

-- for filename, attr in dirtree(directory_path) do
-- if attr.mode == "file" and fileMatches(filename, '.%.lua$') then
-- add_empty_file_coverage_data(filename)
-- end
-- end

-- end

-- if (conf.includeuntestedfiles == true) then
-- add_empty_dir_coverage_data("." .. dir_sep)

-- elseif (type(conf.includeuntestedfiles) == "table" and conf.includeuntestedfiles[1]) then
-- for _, include_path in ipairs(conf.includeuntestedfiles) do
-- if (fileMatches(include_path, '.%.lua$')) then
-- add_empty_file_coverage_data(include_path)
-- else
-- add_empty_dir_coverage_data(include_path)
-- end
-- end
-- end

-- end

table.sort(files)

Expand Down
38 changes: 20 additions & 18 deletions src/resources/pandoc/datadir/luacov/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ local on_exit_run_once = false
local function on_exit()
-- Lua >= 5.2 could call __gc when user call os.exit
-- so this method could be called twice
if on_exit_run_once then return end
on_exit_run_once = true
-- if on_exit_run_once then return end
-- on_exit_run_once = true
-- disable hooks before aggregating stats
debug.sethook(nil)
runner.save_stats()
Expand Down Expand Up @@ -424,16 +424,18 @@ local hook_per_thread

-- Determines whether debug hooks are separate for each thread.
local function has_hook_per_thread()
if hook_per_thread == nil then
local old_hook, old_mask, old_count = debug.gethook()
local noop = function() end
debug.sethook(noop, "l")
local thread_hook = coroutine.wrap(function() return debug.gethook() end)()
hook_per_thread = thread_hook ~= noop
debug.sethook(old_hook, old_mask, old_count)
end
return false

-- if hook_per_thread == nil then
-- local old_hook, old_mask, old_count = debug.gethook()
-- local noop = function() end
-- debug.sethook(noop, "l")
-- local thread_hook = coroutine.wrap(function() return debug.gethook() end)()
-- hook_per_thread = thread_hook ~= noop
-- debug.sethook(old_hook, old_mask, old_count)
-- end

return hook_per_thread
-- return hook_per_thread
end

--------------------------------------------------
Expand Down Expand Up @@ -467,10 +469,10 @@ function runner.init(configuration)

-- metatable trick on filehandle won't work if Lua exits through
-- os.exit() hence wrap that with exit code as well
os.exit = function(...) -- luacheck: no global
on_exit()
raw_os_exit(...)
end
-- os.exit = function(...) -- luacheck: no global
-- on_exit()
-- raw_os_exit(...)
-- end

debug.sethook(runner.debug_hook, "l")

Expand Down Expand Up @@ -503,9 +505,9 @@ function runner.init(configuration)
end
end

if not runner.tick then
runner.on_exit_trick = on_exit_wrap(on_exit)
end
-- if not runner.tick then
-- runner.on_exit_trick = on_exit_wrap(on_exit)
-- end

runner.initialized = true
runner.paused = false
Expand Down
Loading
Loading