Skip to content

Commit

Permalink
Refine definitions surrounding testing various jsh shell types
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpcaldwell committed Sep 2, 2024
1 parent 033c84e commit 793dac2
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 58 deletions.
8 changes: 7 additions & 1 deletion jrunscript/jsh/_.fifty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ namespace slime.jsh {
* To execute a script in an ad-hoc built shell, execute:
* `./jsh jrunscript/jsh/test/tools/run-in-built-shell.jsh.js <script> [arguments]`
*
* To execute a script in a packaged shell, execute:
* To execute a script in an ad-hoc packaged shell, execute:
* `./jsh jrunscript/jsh/test/tools/run-in-built-shell.jsh.js -packaged <script> [arguments]`
*
* ## Testing Tools
*
* The `jrunscript/jsh/fixtures.ts` script provides an {@link slime.jsh.test.Exports} object that provides access to several shell
* types, as represented by the {@link slime.jsh.test.Shells} that can be created by passing the global
* {@link slime.fifty.test.Kit | `fifty`} object.
*/
namespace slime.jsh.internal {

Expand Down
93 changes: 58 additions & 35 deletions jrunscript/jsh/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@

namespace slime.jsh.test {
export namespace shells {
export namespace remote {
export type Settings = Omit<slime.jsh.test.remote.Settings,"mock">
}

export interface Remote {
web: slime.jsh.unit.mock.Web
library: slime.jsh.test.remote.Exports
/**
* Creates a shell intention that represents a command that downloads the remote `jsh` launcher and then executes it
* with appropriate configuration in order to run the given script.
*/
getShellIntention: (p: {
PATH: slime.jrunscript.file.Searchpath
settings: remote.Settings

/**
* A path, relative within the SLIME project, of a remote script to run.
*/
script: string
}) => slime.jrunscript.shell.run.Intention
}
}

Expand All @@ -17,7 +32,6 @@ namespace slime.jsh.test {
built: slime.$api.fp.impure.External<slime.jsh.shell.BuiltInstallation>
packaged: slime.$api.fp.impure.External<slime.jsh.shell.PackagedInstallation>

// TODO unlike the other shell implementations, this one does no caching and will create a new server for each call
remote: slime.$api.fp.impure.External<shells.Remote>

// Would like to use something like this to match designs of others, but will need to refactor first to make it less OO
Expand Down Expand Up @@ -181,40 +195,49 @@ namespace slime.jsh.test {
package: to.pathname
};
}),
remote: $api.fp.impure.Input.memoized(function() {
// TODO add caching
var current = jsh.shell.jsh.Installation.from.current();

if (jsh.shell.jsh.Installation.is.unbuilt(current)) {
var slime = jsh.file.Location.from.os(current.src);

var loader = jsh.file.Location.directory.loader.synchronous({ root: slime });

var code: {
testing: slime.jrunscript.tools.github.internal.test.Script
} = {
testing: jsh.loader.synchronous.scripts(loader)("rhino/tools/github/test/module.js") as slime.jrunscript.tools.github.internal.test.Script
};

var library = {
testing: code.testing({
slime: jsh.file.object.directory(slime),
library: {
shell: jsh.shell
remote: $api.fp.impure.Input.memoized(
function(): shells.Remote {
var current = jsh.shell.jsh.Installation.from.current();

if (jsh.shell.jsh.Installation.is.unbuilt(current)) {
var slime = jsh.file.Location.from.os(current.src);

var loader = jsh.file.Location.directory.loader.synchronous({ root: slime });

var code: {
testing: slime.jrunscript.tools.github.internal.test.Script
} = {
testing: jsh.loader.synchronous.scripts(loader)("rhino/tools/github/test/module.js") as slime.jrunscript.tools.github.internal.test.Script
};

var library = {
testing: code.testing({
slime: jsh.file.object.directory(slime),
library: {
shell: jsh.shell
}
})
};

var server = library.testing.startMock(jsh);

return {
getShellIntention: function(p) {
return library.testing.getShellIntention({
PATH: p.PATH,
script: p.script,
settings: $api.Object.compose(
p.settings,
{ mock: server }
)
})
}
})
};

var server = library.testing.startMock(jsh);

return {
web: server,
library: library.testing
};
} else {
throw new Error();
};
} else {
throw new Error();
}
}
})
)
}
}
return fifty.global["jrunscript/jsh/fixtures.ts:shells"];
Expand Down
3 changes: 1 addition & 2 deletions jrunscript/jsh/shell/jsh.fifty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,9 @@ namespace slime.jsh.shell {
fifty.tests.exports.jsh.Installation.from.current.remote = function() {
var remote = fixtures.shells(fifty).remote();

var intention = remote.library.getShellIntention({
var intention = remote.getShellIntention({
PATH: jsh.shell.PATH,
settings: {
mock: remote.web,
branch: "local"
},
script: "jrunscript/jsh/test/jsh-data.jsh.js"
Expand Down
6 changes: 3 additions & 3 deletions jrunscript/jsh/test/remote.fifty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ namespace slime.jsh.test.remote {
)

fifty.tests.suite = function() {
var settings: slime.jsh.test.remote.Settings = {
mock: remote.web,
var settings: slime.jsh.test.shells.remote.Settings = {
branch: "local"
};

var shellIntention = remote.library.getShellIntention({
debugger;
var shellIntention = remote.getShellIntention({
PATH: jsh.shell.PATH,
settings: settings,
script: "jrunscript/jsh/test/jsh-data.jsh.js"
Expand Down
16 changes: 1 addition & 15 deletions rhino/tools/github/test/module.fifty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ namespace slime.jsh.test.remote {
export interface Exports {
startMock: (jsh: slime.jsh.Global) => slime.jsh.unit.mock.Web

downloadJshScriptCommand: (
PATH: slime.jrunscript.file.Searchpath,
options: Pick<Settings,"mock" | "token" | "branch">
) => string[]

processJshScriptCommand: (p: {
settings: Settings
script: string
}) => string[]

/**
* Outputs a single string, suitable for use at the shell command line, that will invoke a shell with the given settings
* using tools (`curl` or `wget`) found on the given search path.
Expand All @@ -42,11 +32,7 @@ namespace slime.jsh.test.remote {
script: string
}) => string

getShellIntention: (p: {
PATH: slime.jrunscript.file.Searchpath
settings: Settings
script: string
}) => slime.jrunscript.shell.run.Intention
getShellIntention: slime.jsh.test.shells.Remote["getShellIntention"]
}
}

Expand Down
2 changes: 0 additions & 2 deletions rhino/tools/github/test/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@

$export({
startMock: startMock,
downloadJshScriptCommand: downloadJshScriptCommand,
processJshScriptCommand: processJshScriptCommand,
getCommandLine: getCommand,
getShellIntention: getShellIntention
})
Expand Down

0 comments on commit 793dac2

Please sign in to comment.