Skip to content

Commit 9333ae4

Browse files
authored
Merge pull request #767 from 0xMiden/greenhat/i764-new-mpt-test
chore: add a smoke test for `cargo miden new`
2 parents ca6ae73 + d7095ed commit 9333ae4

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-1
lines changed

.github/workflows/ci.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,39 @@ jobs:
197197
cargo install cargo-make --force
198198
fi
199199
- name: Test
200+
# Skip running the `new_project_integration_tests_pass` test since it
201+
# is a disc space hog.
200202
run: |
201-
cargo make test -E 'package(cargo-miden)'
203+
cargo make test -E 'package(cargo-miden) - test(new_project_integration_tests_pass)'
204+
205+
cargo_miden_tests_mpt:
206+
name: cargo-miden test Miden project template
207+
runs-on: ubuntu-latest
208+
# We only want to run the integration tests if the unit tests pass, and that has the added
209+
# benefit that we can re-use the cache from the unit test job for all integration tests
210+
needs: [unit_tests]
211+
steps:
212+
- uses: actions/checkout@v5
213+
- name: Install Rust
214+
run: |
215+
rustup update --no-self-update
216+
rustc --version
217+
- name: Cache Cargo
218+
uses: Swatinem/rust-cache@v2
219+
with:
220+
shared-key: ${{ github.workflow }}-shared-tests
221+
prefix-key: ${{ env.RUST_CACHE_KEY }}
222+
# Do not persist the cache, leave that to the unit tests, we just use the cache here
223+
save-if: false
224+
- name: Install cargo-make
225+
run: |
226+
if ! cargo make --version 2>/dev/null; then
227+
cargo install cargo-make --force
228+
fi
229+
- name: Test
230+
run: |
231+
cargo make test -E 'test(new_project_integration_tests_pass)'
232+
202233
203234
miden_integration_node_tests:
204235
name: miden integration node tests

tools/cargo-miden/tests/build.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,3 +433,74 @@ fn build_new_project_from_template(template: &str) -> Package {
433433
fs::remove_dir_all(new_project_path).unwrap();
434434
package
435435
}
436+
437+
#[test]
438+
fn new_project_integration_tests_pass() {
439+
let _ = env_logger::Builder::from_env("MIDENC_TRACE")
440+
.is_test(true)
441+
.format_timestamp(None)
442+
.try_init();
443+
env::set_var("TEST", "1");
444+
445+
let restore_dir = env::current_dir().unwrap();
446+
let temp_dir = env::temp_dir().join(format!(
447+
"cargo_miden_integration_{}",
448+
std::time::SystemTime::now()
449+
.duration_since(std::time::UNIX_EPOCH)
450+
.unwrap()
451+
.as_millis()
452+
));
453+
if temp_dir.exists() {
454+
fs::remove_dir_all(&temp_dir).unwrap();
455+
}
456+
fs::create_dir_all(&temp_dir).unwrap();
457+
env::set_current_dir(&temp_dir).unwrap();
458+
459+
let project_name = format!(
460+
"integration_project_{}",
461+
std::time::SystemTime::now()
462+
.duration_since(std::time::UNIX_EPOCH)
463+
.unwrap()
464+
.as_micros()
465+
);
466+
let args = new_project_args(&project_name, "");
467+
468+
let output = run(args.into_iter(), OutputType::Masm)
469+
.expect("Failed to create project with `cargo miden new`")
470+
.expect("'cargo miden new' should return Some(CommandOutput)");
471+
let project_path = match output {
472+
cargo_miden::CommandOutput::NewCommandOutput { project_path } => {
473+
project_path.canonicalize().unwrap()
474+
}
475+
other => panic!("Expected NewCommandOutput, got {other:?}"),
476+
};
477+
assert!(project_path.exists());
478+
479+
let integration_dir = project_path.join("integration");
480+
assert!(
481+
integration_dir.exists(),
482+
"expected integration workspace at {}",
483+
integration_dir.display()
484+
);
485+
486+
let output = std::process::Command::new("cargo")
487+
.arg("test")
488+
.current_dir(&integration_dir)
489+
.output()
490+
.expect("failed to spawn `cargo test` inside integration directory");
491+
if !output.status.success() {
492+
panic!(
493+
"`cargo test` failed in {} with status {:?}\nstdout:\n{}\nstderr:\n{}",
494+
integration_dir.display(),
495+
output.status.code(),
496+
String::from_utf8_lossy(&output.stdout),
497+
String::from_utf8_lossy(&output.stderr)
498+
);
499+
}
500+
501+
env::set_current_dir(restore_dir).unwrap();
502+
fs::remove_dir_all(&project_path).unwrap();
503+
if temp_dir.exists() {
504+
fs::remove_dir_all(&temp_dir).unwrap();
505+
}
506+
}

0 commit comments

Comments
 (0)