Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boozook committed Sep 8, 2023
1 parent d32ae89 commit 641ea3e
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 29 deletions.
7 changes: 7 additions & 0 deletions .github/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[unstable]
unstable-options = true
config-include = true
check-cfg = ["features", "names", "values", "output"]
panic-abort-tests = true
mtime-on-use = true
avoid-dev-deps = true
29 changes: 16 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ jobs:
- name: Cache
uses: Swatinem/rust-cache@v1

- name: Config
run: |
mkdir -p .cargo
cp -rf .github/config.toml .cargo/config.toml
- name: Install Playdate SDK ${{ matrix.sdk }}
id: sdk
uses: pd-rs/get-playdate-sdk@main
Expand Down Expand Up @@ -111,6 +116,11 @@ jobs:
- name: Cache
uses: Swatinem/rust-cache@v1

- name: Config
run: |
mkdir -p .cargo
cp -rf .github/config.toml .cargo/config.toml
- name: Install Playdate SDK ${{ matrix.sdk }}
id: sdk
uses: pd-rs/get-playdate-sdk@main
Expand All @@ -120,15 +130,6 @@ jobs:
- name: SDK ${{ steps.sdk.outputs.version }} installed
run: which pdc && pdc --version

# - name: Install cargo-action-fmt
# uses: baptiste0928/cargo-install@v2.1.0
# with:
# crate: cargo-action-fmt
# - name: Check
# run: |
# cargo check -p=cargo-playdate -q --message-format=json | cargo-action-fmt
# cargo test -p=cargo-playdate --no-run -q --message-format=json | cargo-action-fmt

- name: Test Utils
run: |
cargo test -p=playdate-build-utils --all-features
Expand All @@ -137,11 +138,13 @@ jobs:
- name: Test
run: |
rm -rf ./target/tmp || true
cargo test -p=cargo-playdate -- --nocapture --test-threads=1
cargo test -p=cargo-playdate -- --nocapture
rm -rf ./target/tmp
rm -rf ./target/tmp || true
- name: Test (+usb)
run: |
cargo test -p=cargo-playdate --features=usb -- --nocapture
rm -rf ./target/tmp
- name: Install
run: |
Expand Down
1 change: 1 addition & 0 deletions api/sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub mod misc {

#[doc(hidden)]
#[no_mangle]
#[cfg(target_os = "windows")]
// TODO: Somehow link with proper impl: https://stackoverflow.com/q/76439798/829264
pub extern "C" fn _sbrk() {}
};
Expand Down
10 changes: 8 additions & 2 deletions cargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ features = ["assets-report", "toml"]
default-features = false

[dependencies.tool]
version = "=0.1.0" # TODO: relax semver when tool's api stabilized
version = "=0.1.0" # TODO: relax semver when tool's api stabilized
path = "../support/tool"
package = "playdate-tool"
features = ["usb", "clap", "usb", "cli"]
features = ["clap", "cli"]


[dependencies.clap]
Expand All @@ -94,3 +94,9 @@ features = [

[dev-dependencies]
target = "2.0.0"
rand = "0.8"


[features]
default = []
usb = ["tool/usb"]
6 changes: 3 additions & 3 deletions cargo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ Generate new project using `new` or `init` command.

```bash
mkdir hello-world && cd $_
crank init --lib --full-metadata --deps="sys:git, controls:git"
crank run
cargo playdate init --lib --full-metadata --deps="sys:git, controls:git"
cargo playdate run
```


Expand All @@ -69,7 +69,7 @@ TODO

There is no configuration other then inherited by cargo and some special environment variables.

- `CRANK_LOG` working same way as `CARGO_LOG` or default `RUST_LOG`. Also `CRANK_LOG_STYLE`
- `CARGO_PLAYDATE_LOG` working same way as `CARGO_LOG` or default `RUST_LOG`. Also `CARGO_PLAYDATE_LOG_STYLE`
- `PLAYDATE_SDK_PATH` path to the SDK root
- `ARM_GCC_PATH` path to the `arm-none-eabi-gcc` executable.

Expand Down
8 changes: 4 additions & 4 deletions cargo/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ pub fn initialize_from(args: impl IntoIterator<Item = impl Into<OsString> + AsRe
.flatten()
.is_some()
{
// skip "crank" command
// skip root command
matches.subcommand()
} else {
// get "crank", then subcommand
// get root, then subcommand
matches.subcommand_matches(CMD_NAME)
.map(|m| m.subcommand())
.flatten()
Expand Down Expand Up @@ -389,9 +389,9 @@ fn compile_options(cmd: &Cmd, matches: &ArgMatches, ws: &Workspace<'_>) -> Cargo

/// - Find `cmd` and replace to `Cmd::Build`
/// - Replace all `--target(=)PlaydateTarget::*` to normalized `CompileKind`
/// - Strip first args such as `cargo crank cmd`.
/// - Strip first args such as `cargo playdate cmd`.
///
/// Note: this doesn't support flag-series with values like `-abc="c-value"`.
/// Note: this doesn't supports flag-series with values like `-abc="c-value"`.
fn adapt_args_for_underlying_cargo<S, I>(cmd: &Cmd,
aliases: Option<&HashMap<String, String>>,
args: I,
Expand Down
2 changes: 1 addition & 1 deletion cargo/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<T: Layout> Layout for &mut T {


pub trait LayoutLockable: Layout {
/// The lockfile filename for a build (e.g: `.crank-lock`).
/// The lockfile filename for a build (e.g: `.name-lock`).
fn lockfilename(&self) -> Cow<str>;

/// Lock the destination directory of the layout.
Expand Down
2 changes: 1 addition & 1 deletion cargo/tests/build/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::common::*;

fn run_build(crate_path: &Path,
args: impl IntoIterator<Item = impl Into<OsString>>)
-> Result<(Output, &'static Path)> {
-> Result<(Output, PathBuf)> {
println!("crate: {}", crate_path.display());

let target_dir = target_dir();
Expand Down
15 changes: 13 additions & 2 deletions cargo/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,23 @@ pub fn to_dyn_lib_name<S: Display>(crate_name: S) -> String {
}


pub fn target_dir() -> &'static Path {
pub fn target_dir() -> PathBuf {
use rand::RngCore;

let tmp = Path::new(env!("CARGO_TARGET_TMPDIR"));
if !tmp.exists() {
std::fs::create_dir_all(tmp).expect("can't create tmp dir");
}
tmp

// add random:
let mut values = [0u8; 4];
rand::thread_rng().fill_bytes(&mut values);
let rand = values.into_iter()
.map(|v| v.to_string())
.collect::<Vec<_>>()
.join("");

tmp.join(rand)
}

pub fn target_triple() -> String {
Expand Down
2 changes: 1 addition & 1 deletion cargo/tests/init/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn run(crate_name: &str,
-> Result<(Output, PathBuf)> {
println!("crate: {}", crate_name);

let crate_path = target_dir().join("create-init-tests").join(&crate_name);
let crate_path = target_dir().join(format!("create-init--{crate_name}"));

if crate_path.try_exists()? {
std::fs::remove_dir_all(&crate_path)?;
Expand Down
4 changes: 2 additions & 2 deletions cargo/tests/init/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ fn run(crate_name: &str,
-> Result<(Output, PathBuf)> {
println!("crate: {}", crate_name);

let crate_path = target_dir().join("create-new-tests").join(&crate_name);
let crate_path = target_dir().join(format!("create-new--{crate_name}"));

if crate_path.try_exists()? {
std::fs::remove_dir_all(&crate_path)?;
}

let crate_parent = crate_path.parent().expect("parent");
if !crate_parent.try_exists()? {
std::fs::create_dir_all(&crate_path)?;
std::fs::create_dir_all(&crate_parent)?;
}

let mut extra = vec![OsString::from(&crate_path)];
Expand Down

0 comments on commit 641ea3e

Please sign in to comment.