Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
- pushd examples/chat && yarn && anchor test && popd
- pushd examples/ido-pool && yarn && anchor test && popd
- pushd examples/swap/deps/serum-dex/dex && cargo build-bpf && cd ../../../ && anchor test && popd
- pushd examples/cfo && anchor run test && popd
- pushd examples/cfo && anchor run test-with-build && popd
- <<: *examples
name: Runs the examples 3
script:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ incremented for features.
### Features

* cli: Add keys `members` / `exclude` in config `programs` section ([#546](https://github.com/project-serum/anchor/pull/546)).
* cli: Allow to use custom command for test through scripts instead mocha runner ([#550](https://github.com/project-serum/anchor/pull/550)).
* cli: Allow program address configuration for test command through `clusters.localnet` ([#554](https://github.com/project-serum/anchor/pull/554)).
* lang: IDLs are now parsed from the entire crate ([#517](https://github.com/project-serum/anchor/pull/517)).

Expand Down
52 changes: 27 additions & 25 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ pub enum Command {
/// use this to save time when running test and the program code is not altered.
#[clap(long)]
skip_build: bool,
file: Option<String>,
#[clap(multiple = true)]
args: Vec<String>,
},
/// Creates a new program.
New { name: String },
Expand Down Expand Up @@ -255,13 +256,13 @@ fn main() -> Result<()> {
skip_deploy,
skip_local_validator,
skip_build,
file,
args,
} => test(
&opts.cfg_override,
skip_deploy,
skip_local_validator,
skip_build,
file,
args,
),
#[cfg(feature = "dev")]
Command::Airdrop => airdrop(cfg_override),
Expand All @@ -282,7 +283,16 @@ fn init(cfg_override: &ConfigOverride, name: String, typescript: bool) -> Result
std::env::set_current_dir(&name)?;
fs::create_dir("app")?;

let cfg = Config::default();
let mut cfg = Config::default();
cfg.scripts.insert(
"test".to_owned(),
if typescript {
"ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
} else {
"mocha -t 1000000 tests/"
}
.to_owned(),
);
let toml = cfg.to_string();
let mut file = File::create("Anchor.toml")?;
file.write_all(toml.as_bytes())?;
Expand Down Expand Up @@ -972,7 +982,7 @@ fn test(
skip_deploy: bool,
skip_local_validator: bool,
skip_build: bool,
file: Option<String>,
extra_args: Vec<String>,
) -> Result<()> {
with_workspace(cfg_override, |cfg, _path, _cargo| {
// Build if needed.
Expand Down Expand Up @@ -1005,26 +1015,18 @@ fn test(

// Run the tests.
let test_result: Result<_> = {
let ts_config_exist = Path::new("tsconfig.json").exists();
let cmd = if ts_config_exist { "ts-mocha" } else { "mocha" };
let mut args = if ts_config_exist {
vec![cmd, "-p", "./tsconfig.json"]
} else {
vec![cmd]
};
args.extend_from_slice(&[
"-t",
"1000000",
if let Some(ref file) = file {
file
} else if ts_config_exist {
"tests/**/*.ts"
} else {
"tests/"
},
]);

std::process::Command::new("npx")
let cmd = cfg
.scripts
.get("test")
.expect("Not able to find command for `test`")
.clone();
let mut args: Vec<&str> = cmd
.split(' ')
.chain(extra_args.iter().map(|arg| arg.as_str()))
.collect();
let program = args.remove(0);

std::process::Command::new(program)
.args(args)
.env("ANCHOR_PROVIDER_URL", cfg.provider.cluster.url())
.stdout(Stdio::inherit())
Expand Down
3 changes: 3 additions & 0 deletions examples/cashiers-check/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 2 additions & 1 deletion examples/cfo/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ lockup = { address = "6ebQNeTPZ1j7k3TtkCCtEPRvG7GQsucQrZ7sSEDQi9Ks", idl = "./de
#
# Testing.
#
test = "anchor run build && anchor test --skip-build"
test = "mocha -t 1000000 tests/"
test-with-build = "anchor run build && anchor test --skip-build"
#
# Build the program and all CPI dependencies.
#
Expand Down
3 changes: 3 additions & 0 deletions examples/chat/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/composite/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/errors/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/escrow/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/events/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/ido-pool/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/interface/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/lockup/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/misc/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ program = "./target/deploy/misc.so"

[workspace]
exclude = ["shared"]

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/multisig/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/pyth/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
3 changes: 3 additions & 0 deletions examples/spl/token-proxy/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/swap/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ wallet = "~/.config/solana/id.json"
[[test.genesis]]
address = "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"
program = "./deps/serum-dex/dex/target/deploy/serum_dex.so"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/sysvars/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/tutorial/basic-0/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/tutorial/basic-1/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/tutorial/basic-2/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/tutorial/basic-3/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/tutorial/basic-4/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/tutorial/basic-5/Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "mocha -t 1000000 tests/"
3 changes: 3 additions & 0 deletions examples/typescript/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ wallet = "~/.config/solana/id.json"
[workspace]
members = ["typescript"]
exclude = ["typescript"]

[scripts]
test = "ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
3 changes: 3 additions & 0 deletions examples/zero-copy/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ wallet = "~/.config/solana/id.json"

[workspace]
members = ["zero-copy"]

[scripts]
test = "mocha -t 1000000 tests/"