Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
chore: add test for generic workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
Gankra committed Jun 12, 2024
1 parent eef350f commit d296a2c
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ fn workspace_from(manifest_path: &Utf8Path) -> Result<WorkspaceInfo> {
let root_auto_includes = crate::find_auto_includes(&workspace_dir)?;

let mut package_info = vec![];
for member_dir in &manifest.workspace.members {
let mut package = package_from(&member_dir.join(DIST_PACKAGE_TOML))?;
for member_reldir in &manifest.workspace.members {
let member_dir = workspace_dir.join(member_reldir);
let member_manifest_path = member_dir.join(DIST_PACKAGE_TOML);
let mut package = package_from(&member_manifest_path)?;
crate::merge_auto_includes(&mut package, &root_auto_includes);
package_info.push(package);
}
Expand Down
57 changes: 56 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use camino::Utf8PathBuf;
use camino::{Utf8Path, Utf8PathBuf};

use crate::{changelog::ChangelogInfo, errors::AxoprojectError, Version, WorkspaceKind};

Expand Down Expand Up @@ -564,11 +564,66 @@ fn test_generic_c() {
.unwrap();
assert_eq!(project.kind, WorkspaceKind::Generic);
assert_eq!(project.package_info.len(), 1);
assert!(project.manifest_path.exists());

let package = &project.package_info[0];
assert_eq!(package.name, "testprog");
assert_eq!(package.binaries.len(), 1);
assert!(project.manifest_path.exists());

let binary = &package.binaries[0];
assert_eq!(binary, "main");
}

#[test]
fn test_generic_workspace_root() {
generic_workspace_check("tests/projects/generic-workspace")
}

#[test]
fn test_generic_workspace_subdir() {
generic_workspace_check("tests/projects/generic-workspace/generic1/")
}

fn generic_workspace_check<'a>(path: impl Into<&'a Utf8Path>) {
let project = crate::get_workspaces(path.into(), None)
.best()
.unwrap();
assert_eq!(project.kind, WorkspaceKind::Generic);
assert_eq!(project.package_info.len(), 2);
assert!(project.manifest_path.exists());
check_file(project.root_auto_includes.readme.as_deref().unwrap(), "root fake readme!");
check_file(&project.root_auto_includes.licenses[0], "root fake license!");
check_file(project.root_auto_includes.changelog.as_deref().unwrap(), "root fake changelog!");

{
let package = &project.package_info[0];
assert_eq!(package.name, "generic1");
assert_eq!(package.binaries.len(), 1);
let binary = &package.binaries[0];
assert_eq!(binary, "main");
assert!(package.manifest_path.exists());
assert!(package.manifest_path != project.manifest_path);
check_file(package.readme_file.as_deref().unwrap(), "inner fake readme!");
check_file(&package.license_files[0], "inner fake license!");
check_file(package.changelog_file.as_deref().unwrap(), "inner fake changelog!");
}

{
let package = &project.package_info[1];
assert_eq!(package.name, "generic2");
assert_eq!(package.binaries.len(), 1);
let binary = &package.binaries[0];
assert_eq!(binary, "main");
assert!(package.manifest_path.exists());
assert!(package.manifest_path != project.manifest_path);
check_file(package.readme_file.as_deref().unwrap(), "root fake readme!");
check_file(&package.license_files[0], "root fake license!");
check_file(package.changelog_file.as_deref().unwrap(), "root fake changelog!");
}
}

#[track_caller]
fn check_file(file: &Utf8Path, val: &str) {
assert!(axoasset::LocalAsset::load_string(file).unwrap().trim() == val)
}
1 change: 1 addition & 0 deletions tests/projects/generic-workspace/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root fake changelog!
1 change: 1 addition & 0 deletions tests/projects/generic-workspace/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root fake license!
1 change: 1 addition & 0 deletions tests/projects/generic-workspace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root fake readme!
2 changes: 2 additions & 0 deletions tests/projects/generic-workspace/dist-workspace.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[workspace]
members = ["generic1", "generic2"]
1 change: 1 addition & 0 deletions tests/projects/generic-workspace/generic1/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inner fake changelog!
1 change: 1 addition & 0 deletions tests/projects/generic-workspace/generic1/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inner fake license!
13 changes: 13 additions & 0 deletions tests/projects/generic-workspace/generic1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CC := gcc
RM := rm
EXEEXT :=

all: main$(EXEEXT)

main$(EXEEXT):
$(CC) main.c -o main$(EXEEXT)

clean:
$(RM) -f main$(EXEEXT)

.PHONY: all clean
1 change: 1 addition & 0 deletions tests/projects/generic-workspace/generic1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inner fake readme!
47 changes: 47 additions & 0 deletions tests/projects/generic-workspace/generic1/dist.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[package]
name = "generic1"
description = "A test of a C program for cargo-dist"
version = "0.0.1"
license = "WTFPL"
repository = "https://github.com/mistydemeo/testprog"
binaries = ["main"]
build-command = ["make"]

# Config for 'cargo dist'
[workspace.metadata.dist]
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
cargo-dist-version = "0.4.2"
# CI backends to support
ci = ["github"]
# The installers to generate for each app
installers = ["shell", "homebrew"]
# Target platforms to build apps for (Rust target-triple syntax)
targets = ["x86_64-unknown-linux-gnu", "aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-musl"]
# The archive format to use for windows builds (defaults .zip)
windows-archive = ".tar.gz"
# The archive format to use for non-windows builds (defaults .tar.xz)
unix-archive = ".tar.gz"
# A namespace to use when publishing this package to the npm registry
npm-scope = "@axodotdev"
# A GitHub repo to push Homebrew formulas to
tap = "mistydemeo/homebrew-cargodisttest"
# Publish jobs to run in CI
publish-jobs = ["homebrew"]
# Whether cargo-dist should create a Github Release or use an existing draft
create-release = false
# Whether to publish prereleases to package managers
publish-prereleases = true
# Publish jobs to run in CI
pr-run-mode = "plan"

[workspace.metadata.dist.dependencies.homebrew]
cmake = { targets = ["x86_64-apple-darwin"] }
libcue = { version = "2.2.1", targets = ["x86_64-apple-darwin"] }

[workspace.metadata.dist.dependencies.apt]
cmake = '*'
libcue-dev = { version = "2.2.1-2" }

[workspace.metadata.dist.dependencies.chocolatey]
lftp = '*'
cmake = '3.27.6'
3 changes: 3 additions & 0 deletions tests/projects/generic-workspace/generic1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <stdio.h>

int main() { puts("Hello, cargo-dist!"); }
13 changes: 13 additions & 0 deletions tests/projects/generic-workspace/generic2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CC := gcc
RM := rm
EXEEXT :=

all: main$(EXEEXT)

main$(EXEEXT):
$(CC) main.c -o main$(EXEEXT)

clean:
$(RM) -f main$(EXEEXT)

.PHONY: all clean
47 changes: 47 additions & 0 deletions tests/projects/generic-workspace/generic2/dist.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[package]
name = "generic2"
description = "A test of a C program for cargo-dist"
version = "0.0.1"
license = "WTFPL"
repository = "https://github.com/mistydemeo/testprog"
binaries = ["main"]
build-command = ["make"]

# Config for 'cargo dist'
[workspace.metadata.dist]
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
cargo-dist-version = "0.4.2"
# CI backends to support
ci = ["github"]
# The installers to generate for each app
installers = ["shell", "homebrew"]
# Target platforms to build apps for (Rust target-triple syntax)
targets = ["x86_64-unknown-linux-gnu", "aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-musl"]
# The archive format to use for windows builds (defaults .zip)
windows-archive = ".tar.gz"
# The archive format to use for non-windows builds (defaults .tar.xz)
unix-archive = ".tar.gz"
# A namespace to use when publishing this package to the npm registry
npm-scope = "@axodotdev"
# A GitHub repo to push Homebrew formulas to
tap = "mistydemeo/homebrew-cargodisttest"
# Publish jobs to run in CI
publish-jobs = ["homebrew"]
# Whether cargo-dist should create a Github Release or use an existing draft
create-release = false
# Whether to publish prereleases to package managers
publish-prereleases = true
# Publish jobs to run in CI
pr-run-mode = "plan"

[workspace.metadata.dist.dependencies.homebrew]
cmake = { targets = ["x86_64-apple-darwin"] }
libcue = { version = "2.2.1", targets = ["x86_64-apple-darwin"] }

[workspace.metadata.dist.dependencies.apt]
cmake = '*'
libcue-dev = { version = "2.2.1-2" }

[workspace.metadata.dist.dependencies.chocolatey]
lftp = '*'
cmake = '3.27.6'
3 changes: 3 additions & 0 deletions tests/projects/generic-workspace/generic2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <stdio.h>

int main() { puts("Hello, cargo-dist!"); }

0 comments on commit d296a2c

Please sign in to comment.