Skip to content

Commit

Permalink
Extract test helpers from Update tests for use with other Cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
JONBRWN committed Jun 9, 2020
1 parent f238178 commit f178e2b
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 113 deletions.
127 changes: 14 additions & 113 deletions corral/cmd/_test_cmd_update.pony
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ actor _TestCmdUpdate is TestList
None

fun tag tests(test: PonyTest) =>
test(_TestEmptyDeps)
test(_TestMutuallyRecursive)
test(_TestRegression120)
test(_TestSelfReferential)
test(_TestUpdateEmptyDeps)
test(_TestUpdateMutuallyRecursive)
test(_TestUpdateRegression120)
test(_TestUpdateSelfReferential)

class iso _TestEmptyDeps is UnitTest
class iso _TestUpdateEmptyDeps is UnitTest
"""
Verify that when using an corral.json for with empty deps, that there
are never any sync, tag query, or checkout operations executed.
Expand All @@ -24,12 +24,12 @@ class iso _TestEmptyDeps is UnitTest
"cmd/update/" + __loc.type_name()

fun apply(h: TestHelper) ? =>
_OpsRecorderTestRunner(
_OpsRecorderUpdateTestRunner(
h,
"empty-deps",
_OpsRecorder(h, 0, 0, 0))?

class iso _TestMutuallyRecursive is UnitTest
class iso _TestUpdateMutuallyRecursive is UnitTest
"""
Verify that when using mutually recursive corral.json files that we
execute the correct number of operations
Expand All @@ -39,12 +39,12 @@ class iso _TestMutuallyRecursive is UnitTest
"cmd/update/" + __loc.type_name()

fun apply(h: TestHelper) ? =>
_OpsRecorderTestRunner(
_OpsRecorderUpdateTestRunner(
h,
"mutually-recursive/foo",
_OpsRecorder(h, 2, 2, 2))?

class iso _TestRegression120 is UnitTest
class iso _TestUpdateRegression120 is UnitTest
"""
Issue #120 identified a problem with transitive dependencies that resulted
in too many operations being performaned across the loading of all
Expand All @@ -63,33 +63,33 @@ class iso _TestRegression120 is UnitTest
"cmd/update/" + __loc.type_name()

fun apply(h: TestHelper) ? =>
_OpsRecorderTestRunner(
_OpsRecorderUpdateTestRunner(
h,
"regression-120/bundle-entrypoint",
_OpsRecorder(h, 4, 4, 4))?

class iso _TestSelfReferential is UnitTest
class iso _TestUpdateSelfReferential is UnitTest
"""
Verify that a self reference in a corral.json results in only 1 operation
"""
fun name(): String =>
"cmd/update/" + __loc.type_name()

fun apply(h: TestHelper) ? =>
_OpsRecorderTestRunner(
_OpsRecorderUpdateTestRunner(
h,
"self-referential",
_OpsRecorder(h, 1, 1, 1))?

primitive _OpsRecorderTestRunner
primitive _OpsRecorderUpdateTestRunner
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)?
let repo_cache = _TestRepoCache(auth, "_test_cmd_update_repo_cache")?
let ctx = Context(h.env, log, log, false, repo_cache)
let project = Project(auth, log, fp)
let bundle = Bundle.load(fp, log)?
Expand All @@ -101,40 +101,6 @@ primitive _OpsRecorderTestRunner
// _OpsRecorder which will trigger pass/fail
h.long_test(2_000_000_000)

actor _OpsRecorder is CmdResultReceiver
let _h: TestHelper

let _expected_sync: U64
let _expected_tag_query: U64
let _expected_checkout: U64

var _sync: U64 = 0
var _tag_query: U64 = 0
var _checkout: U64 = 0

new create(h: TestHelper, s: U64, tq: U64, c: U64) =>
_h = h
_expected_sync = s
_expected_tag_query = tq
_expected_checkout = c

be sync() =>
_sync = _sync + 1

be tag_query() =>
_tag_query = _tag_query + 1

be checkout() =>
_checkout = _checkout + 1

be cmd_completed() =>
_h.assert_eq[U64](_expected_sync, _sync)
_h.assert_eq[U64](_expected_tag_query, _tag_query)
_h.assert_eq[U64](_expected_checkout, _checkout)

_h.complete(true)


class val _TestCmdUpdateVCSBuilder is VCSBuilder
let _recorder: _OpsRecorder

Expand All @@ -143,68 +109,3 @@ class val _TestCmdUpdateVCSBuilder is VCSBuilder

fun val apply(kind: String): VCS =>
_RecordedVCS(_recorder)


class val _RecordedVCS is VCS
let _recorder: _OpsRecorder

new val create(recorder: _OpsRecorder) =>
_recorder = recorder

fun val sync_op(next: RepoOperation): RepoOperation =>
_RecordedSync(_recorder, next)

fun val tag_query_op(receiver: TagListReceiver): RepoOperation =>
_RecordedTagQuery(_recorder, receiver)

fun val checkout_op(rev: String, next: RepoOperation): RepoOperation =>
_RecordedCheckout(_recorder, next)


class val _RecordedSync is RepoOperation
let _recorder: _OpsRecorder
let _next: RepoOperation

new val create(recorder: _OpsRecorder, next: RepoOperation) =>
_recorder = recorder
_next = next

fun val apply(repo: Repo) =>
_recorder.sync()
_next(repo)


class val _RecordedTagQuery is RepoOperation
let _recorder: _OpsRecorder
let _next: TagListReceiver

new val create(recorder: _OpsRecorder, next: TagListReceiver) =>
_recorder = recorder
_next = next

fun val apply(repo: Repo) =>
let tags: Array[String] iso = recover Array[String] end
_recorder.tag_query()
_next(repo, consume tags)


class val _RecordedCheckout is RepoOperation
let _recorder: _OpsRecorder
let _next: RepoOperation

new val create(recorder: _OpsRecorder, next: RepoOperation) =>
_recorder = recorder
_next = next

fun val apply(repo: Repo) =>
_recorder.checkout()
_next(repo)

primitive _TestData
fun file_path_from(h: TestHelper, subdir: String = ""): FilePath ? =>
let auth = h.env.root as AmbientAuth
FilePath(auth, "corral/test/testdata")?.join(subdir)?

primitive _TestRepoCache
fun apply(auth: AmbientAuth): FilePath ? =>
FilePath(auth,"_test_cmd_update_repo_cache")?
101 changes: 101 additions & 0 deletions corral/cmd/_test_helpers.pony
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use "files"
use "ponytest"
use "../vcs"

actor _OpsRecorder is CmdResultReceiver
let _h: TestHelper

let _expected_sync: U64
let _expected_tag_query: U64
let _expected_checkout: U64

var _sync: U64 = 0
var _tag_query: U64 = 0
var _checkout: U64 = 0

new create(h: TestHelper, s: U64, tq: U64, c: U64) =>
_h = h
_expected_sync = s
_expected_tag_query = tq
_expected_checkout = c

be sync() =>
_sync = _sync + 1

be tag_query() =>
_tag_query = _tag_query + 1

be checkout() =>
_checkout = _checkout + 1

be cmd_completed() =>
_h.assert_eq[U64](_expected_sync, _sync)
_h.assert_eq[U64](_expected_tag_query, _tag_query)
_h.assert_eq[U64](_expected_checkout, _checkout)

_h.complete(true)


class val _RecordedVCS is VCS
let _recorder: _OpsRecorder

new val create(recorder: _OpsRecorder) =>
_recorder = recorder

fun val sync_op(next: RepoOperation): RepoOperation =>
_RecordedSync(_recorder, next)

fun val tag_query_op(receiver: TagListReceiver): RepoOperation =>
_RecordedTagQuery(_recorder, receiver)

fun val checkout_op(rev: String, next: RepoOperation): RepoOperation =>
_RecordedCheckout(_recorder, next)


class val _RecordedSync is RepoOperation
let _recorder: _OpsRecorder
let _next: RepoOperation

new val create(recorder: _OpsRecorder, next: RepoOperation) =>
_recorder = recorder
_next = next

fun val apply(repo: Repo) =>
_recorder.sync()
_next(repo)


class val _RecordedTagQuery is RepoOperation
let _recorder: _OpsRecorder
let _next: TagListReceiver

new val create(recorder: _OpsRecorder, next: TagListReceiver) =>
_recorder = recorder
_next = next

fun val apply(repo: Repo) =>
let tags: Array[String] iso = recover Array[String] end
_recorder.tag_query()
_next(repo, consume tags)


class val _RecordedCheckout is RepoOperation
let _recorder: _OpsRecorder
let _next: RepoOperation

new val create(recorder: _OpsRecorder, next: RepoOperation) =>
_recorder = recorder
_next = next

fun val apply(repo: Repo) =>
_recorder.checkout()
_next(repo)

primitive _TestData
fun file_path_from(h: TestHelper, subdir: String = ""): FilePath ? =>
let auth = h.env.root as AmbientAuth
FilePath(auth, "corral/test/testdata")?.join(subdir)?

primitive _TestRepoCache
fun apply(auth: AmbientAuth, path: String): FilePath ? =>
FilePath(auth, path)?

0 comments on commit f178e2b

Please sign in to comment.