Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Add integration tests for 'stable env' #73

Merged
merged 8 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build
/stable/test/integration/tmp/**
!/stable/test/integration/tmp/.gitkeep
# generated
stable/version.pony
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ else
endif

SOURCE_FILES := $(shell find $(SRC_DIR) -path $(SRC_DIR)/test -prune -o -name \*.pony)
TEST_FILES := $(shell find $(SRC_DIR)/test -name \*.pony)
TEST_FILES := $(shell find $(SRC_DIR)/test -name \*.pony -o -name helper.sh)
VERSION := "$(tag) [$(config)]"
GEN_FILES_IN := $(shell find $(SRC_DIR) -name \*.pony.in)
GEN_FILES = $(patsubst %.pony.in, %.pony, $(GEN_FILES_IN))
Expand All @@ -50,7 +50,7 @@ $(tests_binary): $(GEN_FILES) $(SOURCE_FILES) $(TEST_FILES) | $(BUILD_DIR)
${PONYC} $(arch_arg) --debug -o ${BUILD_DIR} $(SRC_DIR)/test

integration: $(binary) $(tests_binary)
STABLE_BIN=$$(pwd)/$(binary) $(tests_binary) --only=integration
STABLE_BIN=$$(pwd)/$(binary) $(tests_binary) --only=integration --sequential

test: $(tests_binary)
$^ --exclude=integration
Expand Down
9 changes: 9 additions & 0 deletions stable/test/integration/_clean_tmp.pony
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use "files"

actor _CleanTmp
let _fp: FilePath
new create(fp: FilePath) =>
_fp = fp

be dispose() =>
_fp.remove()
11 changes: 9 additions & 2 deletions stable/test/integration/_exec.pony
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ actor _Exec
new create(
h: TestHelper,
cmdline: String,
tmp: String,
cleaner: DisposableActor,
notifier: ProcessNotify iso)
=>
let stable_bin =
Expand All @@ -18,13 +20,18 @@ actor _Exec
end
try
let args = cmdline.split_by(" ")
let path = FilePath(h.env.root as AmbientAuth, stable_bin)?
let vars: Array[String] iso = []
let path = FilePath(h.env.root as AmbientAuth,
"stable/test/integration/helper.sh")?
let auth = h.env.root as AmbientAuth
let vars: Array[String] iso = [
"CWD=" + tmp
"STABLE_BIN=" + stable_bin
]
let pm: ProcessMonitor = ProcessMonitor(auth, auth, consume notifier,
path, consume args, consume vars)
pm.done_writing()
h.dispose_when_done(pm)
h.dispose_when_done(cleaner)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the test creating the tmpdir should be responsible for cleaning it up. So just call this right after the temporary directory has been created.

else
h.fail("Could not create FilePath!")
end
Expand Down
3 changes: 3 additions & 0 deletions stable/test/integration/helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
cd "$CWD" || exit 100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a hack. While this is fine, this shows that ProessMonitor should support setting the cwd like e.g. the python subprocess.Popen allows. I will create an issue in the ponyc repo for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created ponylang/ponyc#2821 maybe link this somewhere in your code, so we track it and be able to remove this hack once ProcessMonitor supports setting the cwd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! :)

exec "$STABLE_BIN" "$@"
223 changes: 223 additions & 0 deletions stable/test/integration/test_env.pony
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
use "ponytest"
use "files"
use "process"
use ".."

actor EnvTests is TestList
new create(env: Env) => PonyTest(env, this)
new make() => None

fun tag tests(test: PonyTest) =>
test(TestEnvNoBundle)
test(TestEnvEmptyBundleInSameDir)
test(TestEnvBundleInSameDir)
test(TestEnvBundleInSameDirWithCall)
test(TestEnvBundleInParentDir)
test(TestEnvBadBundleInNestedAndValidBundleInParentDir)

class TestEnvNoBundle is UnitTest
new iso create() => None

fun name(): String => "integration.Env(no bundle.json)"

fun apply(h: TestHelper) =>
h.long_test(200_000_000)
let tmp =
try
FilePath.mkdtemp(h.env.root as AmbientAuth,
"stable/test/integration/tmp/")?
else
h.fail("failed to create temporary directory")
return
end

let notifier: ProcessNotify iso = _ExpectClient(h,
None,
["No bundle.json in current working directory or ancestors."],
0)
_Exec(h, "stable env", tmp.path, _CleanTmp(tmp), consume notifier)

class TestEnvEmptyBundleInSameDir is UnitTest
new iso create() => None

fun name(): String => "integration.Env(empty bundle in same directory)"

fun apply(h: TestHelper) =>
h.long_test(200_000_000)
let tmp =
try
FilePath.mkdtemp(h.env.root as AmbientAuth,
"stable/test/integration/tmp/")?
else
h.fail("failed to create temporary directory")
return
end

let f =
try
Directory(tmp)?.create_file("bundle.json")?
else
h.fail("failed to create bundle.json in temporary directory")
return
end
h.assert_true(f.write("{\"deps\":[]}\n"), "prepare bundle.json")

let notifier: ProcessNotify iso = _ExpectClient(h,
["PONYPATH=\n"], // empty
None,
0)
_Exec(h, "stable env", tmp.path, _CleanTmp(tmp), consume notifier)

class TestEnvBundleInSameDir is UnitTest
new iso create() => None

fun name(): String => "integration.Env(bundle in same directory)"

fun apply(h: TestHelper) =>
h.long_test(200_000_000)
let tmp =
try
FilePath.mkdtemp(h.env.root as AmbientAuth,
"stable/test/integration/tmp/")?
else
h.fail("failed to create temporary directory")
return
end

let f =
try
Directory(tmp)?.create_file("bundle.json")?
else
h.fail("failed to create bundle.json in temporary directory")
return
end
h.assert_true(f.write("{\"deps\":[
{\"type\": \"local\", \"local-path\":\"../local/a\"},
{\"type\": \"local-git\", \"local-path\":\"../local-git/b\"},
{\"type\": \"github\", \"repo\":\"github/c\"},
{\"type\": \"gitlab\", \"repo\":\"gitlab/d\"}
]}\n"), "prepare bundle.json")

let expected =
try
"../local/a" + ":" +
tmp.join(".deps/-local-git-b16798852821555717647")?.path + ":" +
tmp.join(".deps/github/c")?.path + ":" +
tmp.join(".deps/gitlab/d")?.path
else
h.fail("failed to construct expected PONYPATH")
return
end

let notifier: ProcessNotify iso = _ExpectClient(h,
["PONYPATH=" + expected],
None,
0)
_Exec(h, "stable env", tmp.path, _CleanTmp(tmp), consume notifier)

class TestEnvBundleInSameDirWithCall is UnitTest
new iso create() => None

fun name(): String => "integration.Env(calling a program)"

fun apply(h: TestHelper) =>
h.long_test(200_000_000)
let tmp =
try
FilePath.mkdtemp(h.env.root as AmbientAuth,
"stable/test/integration/tmp/")?
else
h.fail("failed to create temporary directory")
return
end

let f =
try
Directory(tmp)?.create_file("bundle.json")?
else
h.fail("failed to create bundle.json in temporary directory")
return
end
h.assert_true(f.write("{\"deps\":[
{\"type\": \"local\", \"local-path\":\"../local/a\"}
]}\n"), "prepare bundle.json")

let notifier: ProcessNotify iso = _ExpectClient(h,
["../local/a"],
None,
0)
_Exec(h, "stable env printenv PONYPATH", tmp.path, _CleanTmp(tmp),
consume notifier)

class TestEnvBundleInParentDir is UnitTest
new iso create() => None

fun name(): String => "integration.Env(bundle.json in parent dir)"

fun apply(h: TestHelper) =>
h.long_test(200_000_000)
let tmp =
try
FilePath.mkdtemp(h.env.root as AmbientAuth,
"stable/test/integration/tmp/")?
else
h.fail("failed to create temporary directory")
return
end

(let f, let nested) =
try
h.assert_true(Directory(tmp)?.mkdir("nested"), "create nested directory")
let n = tmp.join("nested")?
(Directory(tmp)?.create_file("bundle.json")?, n)
else
h.fail("failed to create bundle.json in nested temporary directory")
return
end
h.assert_true(f.write("{\"deps\":[
{\"type\": \"local\", \"local-path\":\"../local/a\"}
]}\n"), "prepare bundle.json")

let notifier: ProcessNotify iso = _ExpectClient(h,
["PONYPATH=../local/a"],
None,
0)
_Exec(h, "stable env", nested.path, _CleanTmp(tmp), consume notifier)

class TestEnvBadBundleInNestedAndValidBundleInParentDir is UnitTest
new iso create() => None

fun name(): String => "integration.Env(invalid bundle.json in nested dir)"

fun apply(h: TestHelper) =>
h.long_test(200_000_000)
let tmp =
try
FilePath.mkdtemp(h.env.root as AmbientAuth,
"stable/test/integration/tmp/")?
else
h.fail("failed to create temporary directory")
return
end

(let bad_bundle, let good_bundle, let nested) =
try
h.assert_true(Directory(tmp)?.mkdir("nested"), "create nested directory")
let n = tmp.join("nested")?
(Directory(n)?.create_file("bundle.json")?,
Directory(tmp)?.create_file("bundle.json")?,
n)
else
h.fail("failed to create bundle.json example data files")
return
end
h.assert_true(good_bundle.write("{\"deps\":[
{\"type\": \"local\", \"local-path\":\"../local/a\"}
]}\n"), "prepare good bundle.json")
h.assert_true(bad_bundle.write("{}"), "prepare bad bundle.json")

let notifier: ProcessNotify iso = _ExpectClient(h,
["PONYPATH=../local/a"],
["JSON error at: " + bad_bundle.path.path + ": missing \"deps\" array"],
0)
_Exec(h, "stable env", nested.path, _CleanTmp(tmp), consume notifier)
14 changes: 12 additions & 2 deletions stable/test/integration/test_usage.pony
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use "ponytest"
use "files"
use "process"
use ".."

Expand All @@ -11,7 +12,16 @@ class TestUsage is UnitTest
fun name(): String => "integration.Usage(" + _args + ")"

fun apply(h: TestHelper) =>
h.long_test(100_000_000)
h.long_test(200_000_000)
let tmp =
try
FilePath.mkdtemp(h.env.root as AmbientAuth,
"stable/test/integration/tmp/")?
else
h.fail("failed to create temporary directory")
return
end

let notifier: ProcessNotify iso = _ExpectClient(h,
[ "Usage: stable COMMAND \\[\\.\\.\\.\\]"
"A simple dependency manager for the Pony language"
Expand All @@ -23,4 +33,4 @@ class TestUsage is UnitTest
],
None, // stderr
0)
_Exec(h, "stable " + _args, consume notifier)
_Exec(h, "stable " + _args, tmp.path, _CleanTmp(tmp), consume notifier)
14 changes: 12 additions & 2 deletions stable/test/integration/test_version.pony
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use "ponytest"
use "files"
use "process"
use ".."

Expand All @@ -7,9 +8,18 @@ class TestVersion is UnitTest
fun name(): String => "integration.Version"

fun apply(h: TestHelper) =>
h.long_test(100_000_000)
h.long_test(200_000_000)
let tmp =
try
FilePath.mkdtemp(h.env.root as AmbientAuth,
"stable/test/integration/tmp/")?
else
h.fail("failed to create temporary directory")
return
end

let notifier: ProcessNotify iso = _ExpectClient(h,
["\\d\\.\\d\\.\\d-[a-f0-9]+ \\[[a-z]+\\]"],
None, // stderr
0)
_Exec(h, "stable version", consume notifier)
_Exec(h, "stable version", tmp.path, _CleanTmp(tmp), consume notifier)
Empty file.
2 changes: 2 additions & 0 deletions stable/test/main.pony
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ actor Main is TestList
test(integration.TestUsage("help"))
test(integration.TestUsage("unknown arguments"))
test(integration.TestVersion)

integration.EnvTests.make().tests(test)