This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
generated from eosnetworkfoundation/product
-
Notifications
You must be signed in to change notification settings - Fork 0
Allow for escaped compiler and link optional parameters #33
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
#! /usr/bin/env python3 | ||
|
||
""" Test `antler-proj add` and `antler proj update` commands. """ | ||
|
||
import os | ||
import shutil | ||
|
||
from util import antler_in_proj_cmd, load_project | ||
from init_tests import init_project | ||
|
||
PROJECT_NAME="aou_project" | ||
PROJECT_PATH=os.path.join("./",PROJECT_NAME) | ||
|
||
def expect_subvalue(array_of_lists, name, tag, value): | ||
""" Inside array_of_lists, find the list that contains `name` and test the value | ||
stored in that list for the given tag against value. | ||
|
||
|
||
:param array_of_lists An array of lists. | ||
:param name The name to search for. | ||
:tag The tag that contains the value we to test. | ||
:value The expected value. | ||
|
||
""" | ||
|
||
for i in array_of_lists: | ||
if i["name"] == name: | ||
return i[tag] == value | ||
return False | ||
|
||
|
||
def setup_project(): | ||
"""Setup the project ensuring there is a fresh project file. | ||
""" | ||
|
||
shutil.rmtree(PROJECT_PATH, ignore_errors=True) | ||
init_project(PROJECT_NAME, "v1.0.0", PROJECT_PATH) | ||
assert os.path.isdir(PROJECT_PATH) | ||
|
||
|
||
def test_app_compile_options(): | ||
"""Add an application to the project and test its compile options can be updated. | ||
""" | ||
|
||
out, _ = antler_in_proj_cmd(PROJECT_PATH, "add app App1 C++ \\\\-O1") | ||
ScottBailey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
print(out) | ||
project = load_project(PROJECT_PATH) | ||
assert expect_subvalue(project["apps"], "App1", "compile_options", "-O1") | ||
|
||
out, _ = antler_in_proj_cmd(PROJECT_PATH, "update app App1 C++ \\\\-O2") | ||
print(out) | ||
project = load_project(PROJECT_PATH) | ||
assert expect_subvalue(project["apps"], "App1", "compile_options", "-O2") | ||
|
||
|
||
def test_app_link_options(): | ||
"""Add an application to the project and test its compile and link options can be updated. | ||
""" | ||
|
||
out, _ = antler_in_proj_cmd(PROJECT_PATH, "add app App2 C++ \"\\-O1\" \\\\-t") | ||
print(out) | ||
project = load_project(PROJECT_PATH) | ||
assert expect_subvalue(project["apps"], "App2", "compile_options", "-O1") | ||
assert expect_subvalue(project["apps"], "App2", "link_options", "-t") | ||
|
||
out, _ = antler_in_proj_cmd(PROJECT_PATH, "update app App2 C++ \"\\-O2\" \\\\-s") | ||
print(out) | ||
project = load_project(PROJECT_PATH) | ||
assert expect_subvalue(project["apps"], "App2", "compile_options", "-O2") | ||
assert expect_subvalue(project["apps"], "App2", "link_options", "-s") | ||
|
||
|
||
def test_app_update_options(): | ||
"""Add an application to the project and test its compile and link options | ||
can be updated with flags. | ||
""" | ||
|
||
out, _ = antler_in_proj_cmd(PROJECT_PATH, "add app App3 C++") | ||
print(out) | ||
project = load_project(PROJECT_PATH) | ||
assert expect_subvalue(project["apps"], "App3", "compile_options", "") | ||
assert expect_subvalue(project["apps"], "App3", "link_options", "") | ||
|
||
out, _ = antler_in_proj_cmd(PROJECT_PATH, "update app App3 --comp \\\\-O1") | ||
print(out) | ||
assert expect_subvalue(load_project(PROJECT_PATH)["apps"], "App3", "compile_options", "-O1") | ||
out, _ = antler_in_proj_cmd(PROJECT_PATH, "update app App3 --comp \"\\-O2\"") | ||
print(out) | ||
assert expect_subvalue(load_project(PROJECT_PATH)["apps"], "App3", "compile_options", "-O2") | ||
|
||
out, _ = antler_in_proj_cmd(PROJECT_PATH, "update app App3 --link \\\\-s") | ||
print(out) | ||
assert expect_subvalue(load_project(PROJECT_PATH)["apps"], "App3", "link_options", "-s") | ||
out, _ = antler_in_proj_cmd(PROJECT_PATH, "update app App3 --link \"\\-t\"") | ||
print(out) | ||
assert expect_subvalue(load_project(PROJECT_PATH)["apps"], "App3", "link_options", "-t") | ||
|
||
assert expect_subvalue(load_project(PROJECT_PATH)["apps"], "App3", "compile_options", "-O2") | ||
|
||
|
||
def test_lib_options(): | ||
"""Add a library to the project and test its compile and link options can be updated with flags. | ||
""" | ||
|
||
out, _ = antler_in_proj_cmd(PROJECT_PATH, "add lib Lib1 C++") | ||
print(out) | ||
project = load_project(PROJECT_PATH) | ||
assert expect_subvalue(project["libs"], "Lib1", "compile_options", "") | ||
assert expect_subvalue(project["libs"], "Lib1", "link_options", "") | ||
|
||
out, _ = antler_in_proj_cmd(PROJECT_PATH, "update lib Lib1 --comp -O1") | ||
print(out) | ||
assert expect_subvalue(load_project(PROJECT_PATH)["libs"], "Lib1", "compile_options", "-O1") | ||
out, _ = antler_in_proj_cmd(PROJECT_PATH, "update lib Lib1 --comp \"-O2\"") | ||
print(out) | ||
assert expect_subvalue(load_project(PROJECT_PATH)["libs"], "Lib1", "compile_options", "-O2") | ||
|
||
out, _ = antler_in_proj_cmd(PROJECT_PATH, "update lib Lib1 --link -s") | ||
print(out) | ||
assert expect_subvalue(load_project(PROJECT_PATH)["libs"], "Lib1", "link_options", "-s") | ||
out, _ = antler_in_proj_cmd(PROJECT_PATH, "update lib Lib1 --link \"-t\"") | ||
print(out) | ||
assert expect_subvalue(load_project(PROJECT_PATH)["libs"], "Lib1", "link_options", "-t") | ||
|
||
assert expect_subvalue(load_project(PROJECT_PATH)["libs"], "Lib1", "compile_options", "-O2") | ||
|
||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
setup_project() | ||
test_app_compile_options() | ||
test_app_link_options() | ||
test_app_update_options() | ||
test_lib_options() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import sys | ||
import shutil | ||
|
||
from util import * | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,44 @@ | ||
#! /usr/bin/env python3 | ||
|
||
"""Utility functions for antler-proj testing.""" | ||
|
||
import subprocess | ||
import os | ||
import yaml | ||
import shutil | ||
|
||
TEST_PATH = os.path.dirname(os.path.abspath(__file__)) | ||
APROJ_EXE = TEST_PATH + "/../antler-proj" | ||
|
||
def run_cmd(cmd): | ||
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
out, err = p.communicate() | ||
""" Execute `cmd`. """ | ||
result = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
out, err = result.communicate() | ||
return out.decode('utf-8'), err.decode('utf-8') | ||
|
||
def antler_proj_cmd(args): | ||
return run_cmd("../antler-proj " + args) | ||
""" Run antler-proj with `args`. """ | ||
return run_cmd(APROJ_EXE + " " + args) | ||
|
||
def antler_in_proj_cmd(path, args): | ||
""" Change directory to `path` and run antler-proj with `args`. """ | ||
return run_cmd("cd " + path + "; " + APROJ_EXE + " " + args) | ||
|
||
def load_project(path): | ||
with open("./{0}/project.yml".format(path), "r") as f: | ||
project = yaml.safe_load(f) | ||
""" Load a project.yml file """ | ||
with open("./{0}/project.yml".format(path), "r") as file_handle: | ||
project = yaml.safe_load(file_handle) | ||
return project | ||
|
||
def expected_cmd(cmd, expected): | ||
out, err = run_cmd(cmd) | ||
""" Test that cmd has an expected result. """ | ||
out, _ = run_cmd(cmd) | ||
if out != expected: | ||
print("ERROR: cmd: %s != expected: %s" % (cmd, expected)) | ||
assert(False) | ||
assert False | ||
|
||
def expected_proj_cmd(cmd, expected): | ||
out, err = antler_proj_cmd(cmd) | ||
""" Test that `antler-proj cmd` has an expected result. """ | ||
out, _ = antler_proj_cmd(cmd) | ||
if out != expected: | ||
print("ERROR: cmd: %s != expected: %s" % (cmd, expected)) | ||
assert(False) | ||
assert False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
general suggestion, please avoid whitespace only changes, it just messing history and makes changes more verbose. Not necessary to fix it for now as it is already there, so just for future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't actually notice I'd done it until AFTER Mikal had reviewed. Auto-updated in my editor. I generally agree, white space changes are to be avoided.