Skip to content

Commit a4dcd24

Browse files
committed
move the CI to a python script
1 parent 8c517e0 commit a4dcd24

File tree

2 files changed

+137
-31
lines changed

2 files changed

+137
-31
lines changed

.travis.yml

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: rust
2-
cache:
2+
cache:
33
directories:
44
- cargo_web
55

@@ -20,34 +20,14 @@ matrix:
2020
- rust: 1.22.0
2121
os: windows
2222

23-
script:
24-
- cargo build --verbose --no-default-features
25-
- cargo build --verbose --no-default-features --features="serde"
26-
- cargo build --verbose --no-default-features --features="lowmemory"
27-
- cargo build --verbose --no-default-features --features="rand"
28-
- cargo build --verbose --no-default-features --features="rand serde recovery endomorphism"
29-
- cargo build --verbose --no-default-features --features="fuzztarget recovery"
30-
- cargo build --verbose --features=rand
31-
- cargo test --no-run --features=fuzztarget
32-
- cargo test --verbose --features=rand
33-
- cargo test --verbose --features="rand rand-std"
34-
- cargo test --verbose --features="rand serde"
35-
- cargo test --verbose --features="rand serde recovery endomorphism"
36-
- cargo build --verbose
37-
- cargo test --verbose
38-
- cargo build --verbose --release
39-
- cargo test --verbose --release
40-
- cargo run --example sign_verify
41-
- cargo run --example sign_verify_recovery --features=recovery
42-
- cargo run --example generate_keys --features=rand
43-
- if [ ${TRAVIS_RUST_VERSION} == "stable" ]; then cargo doc --verbose --features="rand,serde,recovery,endomorphism"; fi
44-
- if [ ${TRAVIS_RUST_VERSION} == "nightly" ]; then cargo test --verbose --benches --features=unstable; fi
45-
- if [ ${TRAVIS_RUST_VERSION} == "nightly" -a "$TRAVIS_OS_NAME" = "linux" ]; then
46-
cd no_std_test &&
47-
cargo run --release | grep -q "Verified Successfully";
48-
fi
49-
- if [ ${TRAVIS_RUST_VERSION} == "stable" -a "$TRAVIS_OS_NAME" = "linux" ]; then
50-
CARGO_TARGET_DIR=cargo_web cargo install --verbose --force cargo-web &&
51-
cargo web build --verbose --target=asmjs-unknown-emscripten &&
52-
cargo web test --verbose --target=asmjs-unknown-emscripten;
23+
before_install:
24+
- if [ "$TRAVIS_OS_NAME" = "windows" ]; then
25+
choco install python3 --version 3.8 || (cat /c/ProgramData/chocolatey/logs/chocolatey.log && false) &&
26+
export PATH="/c/Python38:/c/Python38/Scripts:$PATH" &&
27+
shopt -s expand_aliases &&
28+
alias python3="py -3";
5329
fi
30+
31+
script:
32+
- python3 --version
33+
- python3 ./contrib/tests.py

contrib/tests.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/usr/bin/env python3
2+
3+
import itertools
4+
import subprocess
5+
import sys
6+
import os
7+
from pathlib import Path
8+
9+
FEATURES = ['rand-std', 'recovery', 'endomorphism', 'lowmemory', 'serde']
10+
MSRV = 1.22
11+
RUSTC = None
12+
13+
14+
def call(command, cwd):
15+
print(command)
16+
try:
17+
assert subprocess.check_call(command, shell=True, cwd=str(cwd)) == 0
18+
except subprocess.CalledProcessError as e:
19+
print('Execution failed, error:', e.returncode, file=sys.stderr)
20+
exit(e.returncode)
21+
22+
23+
def set_rustc():
24+
global RUSTC
25+
try:
26+
RUSTC = str(subprocess.check_output(["rustc", "--version"]))
27+
except subprocess.CalledProcessError as e:
28+
print('Execution failed, error:', e, file=sys.stderr)
29+
exit(e.returncode)
30+
31+
32+
def is_nightly():
33+
global RUSTC
34+
assert RUSTC
35+
return "nightly" in RUSTC
36+
37+
38+
def is_stable():
39+
global RUSTC
40+
global MSRV
41+
assert RUSTC
42+
return "nightly" not in RUSTC \
43+
and "beta" not in RUSTC \
44+
and str(MSRV) not in RUSTC
45+
46+
47+
def is_linux():
48+
return "linux" in sys.platform
49+
50+
51+
def test_features(features, cwd, release=""):
52+
assert type(features) is list
53+
print('Running Tests')
54+
# Get all feature combinations
55+
for i in range(len(features) + 1):
56+
for feature_set in itertools.combinations(features, i):
57+
feature_set = ', '.join(feature_set)
58+
# Check that all features work even without the std feature.
59+
call('cargo build {} --verbose --no-default-features --features="{}"'.format(release, feature_set), cwd)
60+
# Check that all tests pass with all features.
61+
call('cargo test {} --verbose --features="{}"'.format(release, feature_set), cwd)
62+
# Check that fuzztarget compiles + links (tests won't pass) with all features.
63+
call('cargo test {} --verbose --no-run --features="fuzztarget, {}"'.format(release, feature_set), cwd)
64+
print()
65+
66+
67+
def run_examples(cwd, features=None):
68+
print('Running Examples')
69+
features = ', '.join(features)
70+
# Get all examples in the examples dir
71+
for example in os.scandir(str(cwd.joinpath("examples").resolve())):
72+
if example.is_file() and example.path.endswith('.rs'):
73+
# Enable all features, as some examples need specific features(ie recovery and rand)
74+
call('cargo run --verbose --example {} --features="{}"'.format(Path(example.name).stem, features), cwd)
75+
76+
77+
def run_doc(cwd, features):
78+
features = ', '.join(features)
79+
call('cargo doc --verbose --features="{}"'.format(features), cwd)
80+
81+
82+
def install_web(cwd):
83+
call("CARGO_TARGET_DIR=cargo_web cargo install --verbose --force cargo-web", cwd)
84+
85+
86+
def test_web(cwd):
87+
call("cargo web build --verbose --target=asmjs-unknown-emscripten", cwd)
88+
call("cargo web test --verbose --target=asmjs-unknown-emscripten", cwd)
89+
90+
91+
def main():
92+
set_rustc()
93+
main_features = ['rand-std', 'recovery', 'endomorphism', 'lowmemory', 'serde']
94+
sys_features = ['recovery', 'endomorphism', 'lowmemory']
95+
dir_path = Path(__file__).absolute().parent
96+
main_path = dir_path.parent
97+
sys_path = main_path.joinpath("secp256k1-sys")
98+
99+
test_features(main_features, main_path)
100+
test_features(main_features, main_path, '--release')
101+
test_features(sys_features, sys_path)
102+
test_features(sys_features, sys_path, '--release')
103+
run_examples(main_path, main_features)
104+
105+
# test benchmarks
106+
if is_nightly():
107+
call("cargo test --verbose --benches --features=unstable, recovery", main_path)
108+
# test cargo doc
109+
elif is_stable():
110+
run_doc(main_path, main_features)
111+
run_doc(sys_path, sys_features)
112+
113+
# test no-std
114+
if is_nightly() and is_linux():
115+
path = main_path.joinpath("no_std_test")
116+
call('cargo run --verbose --release | grep -q "Verified Successfully"', path)
117+
118+
# tes cargo web
119+
if is_stable() and is_linux():
120+
install_web(main_path)
121+
test_web(main_path)
122+
test_web(sys_path)
123+
124+
125+
if __name__ == '__main__':
126+
main()

0 commit comments

Comments
 (0)