diff --git a/corral/cmd/_test.pony b/corral/cmd/_test.pony index 8ebb2220..187f1c86 100644 --- a/corral/cmd/_test.pony +++ b/corral/cmd/_test.pony @@ -9,3 +9,4 @@ actor Main is TestList fun tag tests(test: PonyTest) => _TestCmdUpdate.make().tests(test) + _TestCmdFetch.make().tests(test) diff --git a/corral/cmd/_test_cmd_fetch.pony b/corral/cmd/_test_cmd_fetch.pony new file mode 100644 index 00000000..011e1a09 --- /dev/null +++ b/corral/cmd/_test_cmd_fetch.pony @@ -0,0 +1,102 @@ +use "files" +use "ponytest" +use "../bundle" +use "../util" +use "../vcs" + +actor _TestCmdFetch is TestList + new make() => + None + + fun tag tests(test: PonyTest) => + test(_TestFetchEmptyDeps) + test(_TestFetchEmptyFile) + test(_TestFetchMutuallyRecursive) + test(_TestFetchSelfReferential) + +class iso _TestFetchEmptyDeps is UnitTest + """ + Verify that when using corral.json with empty deps, that there + are never any sync, tag query, or checkout operations executed. + """ + + fun name(): String => + "cmd/fetch/" + __loc.type_name() + + fun apply(h: TestHelper) ? => + _OpsRecorderFetchTestRunner( + h, + "empty-deps", + _OpsRecorder(h, 0, 0, 0))? + +class iso _TestFetchEmptyFile is UnitTest + """ + Verify that when using corral.json with an empty deps file, that there + are never any sync, tag query, or checkout operations executed. + """ + + fun name(): String => + "cmd/fetch/" + __loc.type_name() + + fun apply(h: TestHelper) ? => + _OpsRecorderFetchTestRunner( + h, + "empty-file", + _OpsRecorder(h, 0, 0, 0))? + +class iso _TestFetchSelfReferential is UnitTest + """ + Verify that a self reference in a corral.json results in only 1 operation + """ + fun name(): String => + "cmd/fetch/" + __loc.type_name() + + fun apply(h: TestHelper) ? => + _OpsRecorderFetchTestRunner( + h, + "self-referential", + _OpsRecorder(h, 1, 0, 1))? + +class iso _TestFetchMutuallyRecursive is UnitTest + """ + Verify that when using mutually recursive corral.json files that we + execute the correct number of operations + """ + + fun name(): String => + "cmd/fetch/" + __loc.type_name() + + fun apply(h: TestHelper) ? => + _OpsRecorderFetchTestRunner( + h, + "mutually-recursive/foo", + _OpsRecorder(h, 2, 0, 2))? + +primitive _OpsRecorderFetchTestRunner + fun apply(h: TestHelper, dep_path: String val, recorder: _OpsRecorder) ? => + """ + Runs an _OpsRecorder test. + """ + let auth = h.env.root as AmbientAuth + let log = Log(LvlNone, h.env.err, SimpleLogFormatter) + let fp: FilePath = _TestData.file_path_from(h, dep_path)? + let repo_cache = _TestRepoCache(auth, "_test_cmd_fetch_repo_cache")? + let ctx = Context(h.env, log, log, false, repo_cache) + let project = Project(auth, log, fp) + let bundle = Bundle.load(fp, log)? + let vcs_builder: VCSBuilder = _TestCmdFetchVCSBuilder(recorder) + + let fetcher = _Fetcher(ctx, project, consume bundle, vcs_builder, + recorder) + + // when fetcher is finished, it will send a `cmd_completed` message to + // _OpsRecorder which will trigger pass/fail + +class val _TestCmdFetchVCSBuilder is VCSBuilder + let _recorder: _OpsRecorder + + new val create(recorder: _OpsRecorder) => + _recorder = recorder + + fun val apply(kind: String): VCS => + _RecordedVCS(_recorder) diff --git a/corral/cmd/cmd_fetch.pony b/corral/cmd/cmd_fetch.pony index 4c39d531..f4a7cef8 100644 --- a/corral/cmd/cmd_fetch.pony +++ b/corral/cmd/cmd_fetch.pony @@ -18,7 +18,7 @@ class CmdFetch is CmdType match project.load_bundle() | let base_bundle: Bundle iso => - _Fetcher(ctx, project, consume base_bundle, vcs_builder) + _Fetcher(ctx, project, consume base_bundle, vcs_builder, result_receiver) | let err: Error => ctx.uout.err(err.message) ctx.env.exitcode(1) @@ -31,16 +31,19 @@ actor _Fetcher let fetched: Set[Locator] = fetched.create() let _vcs_builder: VCSBuilder + let _results_receiver: CmdResultReceiver new create(ctx': Context, project': Project, base_bundle': Bundle iso, - vcs_builder: VCSBuilder) + vcs_builder: VCSBuilder, + results_receiver: CmdResultReceiver) => ctx = ctx' project = project' base_bundle = consume base_bundle' _vcs_builder = vcs_builder + _results_receiver = results_receiver ctx.log.info("Fetching direct deps of project bundle: " + base_bundle.name()) fetch_bundle_deps(base_bundle) @@ -58,6 +61,7 @@ actor _Fetcher ctx.uout.info("fetch: would have fetched dep: " + dep.name() + " @ " + dep.version()) end end + _results_receiver.cmd_completed() fun fetch_dep(dep: Dep val) => try