Skip to content
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

feat: scarb-native-test #615

Merged
merged 8 commits into from
Jun 3, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
with:
files: |
target/release/cairo-native-test
target/release/scarb-native-test
target/release/cairo-native-compile
target/release/cairo-native-dump
target/release/cairo-native-run
Expand Down
91 changes: 91 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ required-features = ["build-cli"]
name = "cairo-native-test"
required-features = ["build-cli"]

[[bin]]
name = "scarb-native-test"
required-features = ["scarb"]

[features]
default = ["build-cli", "with-runtime"]
build-cli = ["dep:clap", "dep:tracing-subscriber", "dep:anyhow", "dep:cairo-lang-test-plugin",
"dep:cairo-lang-runner", "dep:colored", "dep:cairo-felt", "dep:keccak",
"dep:k256", "dep:p256", "dep:sec1"]
scarb = ["build-cli", "dep:scarb-ui", "dep:scarb-metadata", "dep:serde_json"]
with-debug-utils = []
with-runtime = ["dep:cairo-native-runtime"]
with-serde = ["dep:serde"]
Expand Down Expand Up @@ -83,7 +88,10 @@ cairo-felt = { version = "0.9.1", optional = true }
keccak = { version = "0.1.3", optional = true }
k256 = { version = "0.13.3", optional = true }
p256 = { version = "0.13.2", optional = true }
scarb-metadata = { git = "https://github.com/software-mansion/scarb.git", rev = "v2.6.3", optional = true }
scarb-ui = { git = "https://github.com/software-mansion/scarb.git", rev = "v2.6.3", optional = true }
sec1 = { version = "0.7.3", optional = true }
serde_json = { version = "1.0.117", optional = true }

[dev-dependencies]
cairo-felt = "0.9.1"
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,31 @@ cairo-native-test ./cairo-tests/

This will run all the tests (functions marked with the `#[test]` attribute).

# scarb-native-test cli tool

This tool mimics the `scarb test` [command](https://github.com/software-mansion/scarb/tree/main/extensions/scarb-cairo-test).
You can download it on our [releases](https://github.com/lambdaclass/cairo_native/releases) page.

```bash
$ scarb-native-test --help
Compiles all packages from a Scarb project matching `packages_filter` and
runs all functions marked with `#[test]`. Exits with 1 if the compilation
or run fails, otherwise 0.

Usage: scarb-native-test [OPTIONS]

Options:
-p, --package <SPEC> Packages to run this command on, can be a concrete package name (`foobar`) or a prefix glob (`foo*`) [env: SCARB_PACKAGES_FILTER=] [default: *]
-w, --workspace Run for all packages in the workspace
-f, --filter <FILTER> Run only tests whose name contain FILTER [default: ]
--include-ignored Run ignored and not ignored tests
--ignored Run only ignored tests
--run-mode <RUN_MODE> Run with JIT or AOT (compiled) [default: jit] [possible values: aot, jit]
-O, --opt-level <OPT_LEVEL> Optimization level, Valid: 0, 1, 2, 3. Values higher than 3 are considered as 3 [default: 0]
-h, --help Print help
-V, --version Print version
```

## Debugging Tips

### Useful environment variables
Expand Down
19 changes: 2 additions & 17 deletions src/bin/cairo-native-compile.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use anyhow::Context;
use cairo_lang_compiler::project::check_compiler_path;
use cairo_native::{
context::NativeContext, module_to_object, object_to_shared_lib,
utils::cairo_to_sierra_with_debug_info,
};
use clap::{Parser, ValueEnum};

use std::path::{Path, PathBuf};
use std::path::PathBuf;
use tracing_subscriber::{EnvFilter, FmtSubscriber};

#[derive(Clone, Debug, ValueEnum)]
Expand Down Expand Up @@ -80,18 +80,3 @@ fn main() -> anyhow::Result<()> {

Ok(())
}

pub fn check_compiler_path(single_file: bool, path: &Path) -> anyhow::Result<()> {
if path.is_file() {
if !single_file {
anyhow::bail!("The given path is a file, but --single-file was not supplied.");
}
} else if path.is_dir() {
if single_file {
anyhow::bail!("The given path is a directory, but --single-file was supplied.");
}
} else {
anyhow::bail!("The given path does not exist.");
}
Ok(())
}
Loading
Loading