-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Chasing Concept ACK]: Replacing CI tests with a python script #194
Open
elichai
wants to merge
1
commit into
rust-bitcoin:master
Choose a base branch
from
elichai:2020-01-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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,126 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import itertools | ||
import subprocess | ||
import sys | ||
import os | ||
from pathlib import Path | ||
|
||
FEATURES = ['rand-std', 'recovery', 'endomorphism', 'lowmemory', 'serde'] | ||
MSRV = 1.22 | ||
RUSTC = None | ||
|
||
|
||
def call(command, cwd): | ||
print(command) | ||
try: | ||
assert subprocess.check_call(command, shell=True, cwd=str(cwd)) == 0 | ||
except subprocess.CalledProcessError as e: | ||
print('Execution failed, error:', e.returncode, file=sys.stderr) | ||
exit(e.returncode) | ||
|
||
|
||
def set_rustc(): | ||
global RUSTC | ||
try: | ||
RUSTC = str(subprocess.check_output(["rustc", "--version"])) | ||
except subprocess.CalledProcessError as e: | ||
print('Execution failed, error:', e, file=sys.stderr) | ||
exit(e.returncode) | ||
|
||
|
||
def is_nightly(): | ||
global RUSTC | ||
assert RUSTC | ||
return "nightly" in RUSTC | ||
|
||
|
||
def is_stable(): | ||
global RUSTC | ||
global MSRV | ||
assert RUSTC | ||
return "nightly" not in RUSTC \ | ||
and "beta" not in RUSTC \ | ||
and str(MSRV) not in RUSTC | ||
|
||
|
||
def is_linux(): | ||
return "linux" in sys.platform | ||
|
||
|
||
def test_features(features, cwd, release=""): | ||
assert type(features) is list | ||
print('Running Tests') | ||
# Get all feature combinations | ||
for i in range(len(features) + 1): | ||
for feature_set in itertools.combinations(features, i): | ||
feature_set = ', '.join(feature_set) | ||
# Check that all features work even without the std feature. | ||
call('cargo build {} --verbose --no-default-features --features="{}"'.format(release, feature_set), cwd) | ||
# Check that all tests pass with all features. | ||
call('cargo test {} --verbose --features="{}"'.format(release, feature_set), cwd) | ||
# Check that fuzztarget compiles + links (tests won't pass) with all features. | ||
call('cargo test {} --verbose --no-run --features="fuzztarget, {}"'.format(release, feature_set), cwd) | ||
print() | ||
|
||
|
||
def run_examples(cwd, features=None): | ||
print('Running Examples') | ||
features = ', '.join(features) | ||
# Get all examples in the examples dir | ||
for example in os.scandir(str(cwd.joinpath("examples").resolve())): | ||
if example.is_file() and example.path.endswith('.rs'): | ||
# Enable all features, as some examples need specific features(ie recovery and rand) | ||
call('cargo run --verbose --example {} --features="{}"'.format(Path(example.name).stem, features), cwd) | ||
|
||
|
||
def run_doc(cwd, features): | ||
features = ', '.join(features) | ||
call('cargo doc --verbose --features="{}"'.format(features), cwd) | ||
|
||
|
||
def install_web(cwd): | ||
call("CARGO_TARGET_DIR=cargo_web cargo install --verbose --force cargo-web", cwd) | ||
|
||
|
||
def test_web(cwd): | ||
call("cargo web build --verbose --target=asmjs-unknown-emscripten", cwd) | ||
call("cargo web test --verbose --target=asmjs-unknown-emscripten", cwd) | ||
|
||
|
||
def main(): | ||
set_rustc() | ||
main_features = ['rand-std', 'recovery', 'endomorphism', 'lowmemory', 'serde'] | ||
sys_features = ['recovery', 'endomorphism', 'lowmemory'] | ||
dir_path = Path(__file__).absolute().parent | ||
main_path = dir_path.parent | ||
sys_path = main_path.joinpath("secp256k1-sys") | ||
|
||
test_features(main_features, main_path) | ||
test_features(main_features, main_path, '--release') | ||
test_features(sys_features, sys_path) | ||
test_features(sys_features, sys_path, '--release') | ||
run_examples(main_path, main_features) | ||
|
||
# test benchmarks | ||
if is_nightly(): | ||
call("cargo test --verbose --benches --features=unstable, recovery", main_path) | ||
# test cargo doc | ||
elif is_stable(): | ||
run_doc(main_path, main_features) | ||
run_doc(sys_path, sys_features) | ||
|
||
# test no-std | ||
if is_nightly() and is_linux(): | ||
path = main_path.joinpath("no_std_test") | ||
call('cargo run --verbose --release | grep -q "Verified Successfully"', path) | ||
|
||
# tes cargo web | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tes -> test |
||
if is_stable() and is_linux(): | ||
install_web(main_path) | ||
test_web(main_path) | ||
test_web(sys_path) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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.
The assert is superfluous. Is it used for reader's convenience?
(https://docs.python.org/3.5/library/subprocess.html#subprocess.check_call)
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.
you're right. I changed the method multiple times and didn't realize this one throws and I can remove the assert.