Skip to content

Commit

Permalink
add timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
aspeddro committed Apr 7, 2024
1 parent 4753240 commit bf7348e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions scripts/DocTests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,11 @@ function getCodeBlocks(example) {

async function runtimeTests(code) {
var match = await run("node", [
"-p",
"-e",
code
], {
cwd: compilerDir
cwd: compilerDir,
timeout: 2000
});
var stderr = match.stderr;
if (stderr.length > 0) {
Expand Down
15 changes: 9 additions & 6 deletions scripts/DocTests.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open RescriptCore

module Node = {
module Path = {
@module("path") external join2: (string, string) => string = "join"
Expand Down Expand Up @@ -41,14 +43,13 @@ module Node = {

type readable
type spawnReturns = {stderr: readable, stdout: readable}
type options = {cwd?: string}
type options = {cwd?: string, env?: Dict.t<string>, timeout?: int}
@module("child_process")
external spawn: (string, array<string>, ~options: options=?) => spawnReturns = "spawn"

@send external on: (readable, string, Buffer.t => unit) => unit = "on"
@send
external once: (spawnReturns, string, (Js.Null.t<float>, Js.Null.t<string>) => unit) => unit =
"once"
external once: (spawnReturns, string, (Null.t<float>, Null.t<string>) => unit) => unit = "once"
}

module OS = {
Expand All @@ -57,7 +58,6 @@ module Node = {
}
}

open RescriptCore
open Node

module Docgen = RescriptTools.Docgen
Expand Down Expand Up @@ -299,8 +299,11 @@ let getCodeBlocks = example => {
let runtimeTests = async code => {
let {stdout, stderr} = await SpawnAsync.run(
~command="node",
~args=["-p", code],
~options={cwd: compilerDir},
~args=["-e", code],
~options={
cwd: compilerDir,
timeout: 2000,
},
)

switch Array.length(stderr) > 0 {
Expand Down

0 comments on commit bf7348e

Please sign in to comment.