From 87832c6e1f8d2ed7bc3673e17e840ae2fb26a1ef Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 5 Dec 2022 09:23:37 -0800 Subject: [PATCH] Enable Windows tests on CI (#846) --- .github/workflows/test.yaml | 5 -- src/options.rs | 91 +++++++++++++++++++++++++------ src/subcommand/server.rs | 9 ++- src/subcommand/wallet/identify.rs | 3 +- tests/command_builder.rs | 3 +- tests/test_server.rs | 1 - tests/wallet.rs | 4 +- 7 files changed, 87 insertions(+), 29 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 97c0f06ed7..7112f67aef 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -38,9 +38,4 @@ jobs: - uses: Swatinem/rust-cache@v1 - name: Test - if: ${{ matrix.os != 'windows-latest' }} run: cargo test --all - - - name: Build Tests - if: ${{ matrix.os == 'windows-latest' }} - run: cargo build --tests diff --git a/src/options.rs b/src/options.rs index feab9b80e0..dbf4f5b612 100644 --- a/src/options.rs +++ b/src/options.rs @@ -178,7 +178,11 @@ mod tests { .unwrap() .display() .to_string() - .ends_with("/signet/.cookie")) + .ends_with(if cfg!(windows) { + r"\signet\.cookie" + } else { + "/signet/.cookie" + })); } #[test] @@ -191,11 +195,13 @@ mod tests { .display() .to_string(); - if cfg!(target_os = "linux") { - assert!(cookie_file.ends_with("/.bitcoin/.cookie")); + assert!(cookie_file.ends_with(if cfg!(target_os = "linux") { + "/.bitcoin/.cookie" + } else if cfg!(windows) { + r"\Bitcoin\.cookie" } else { - assert!(cookie_file.ends_with("/Bitcoin/.cookie")); - } + "/Bitcoin/.cookie" + })) } #[test] @@ -209,11 +215,13 @@ mod tests { .display() .to_string(); - if cfg!(target_os = "linux") { - assert!(cookie_file.ends_with("/.bitcoin/signet/.cookie")); + assert!(cookie_file.ends_with(if cfg!(target_os = "linux") { + "/.bitcoin/signet/.cookie" + } else if cfg!(windows) { + r"\Bitcoin\signet\.cookie" } else { - assert!(cookie_file.ends_with("/Bitcoin/signet/.cookie")); - } + "/Bitcoin/signet/.cookie" + })); } #[test] @@ -229,7 +237,11 @@ mod tests { .display() .to_string(); - assert!(cookie_file.ends_with("foo/signet/.cookie")); + assert!(cookie_file.ends_with(if cfg!(windows) { + r"foo\signet\.cookie" + } else { + "foo/signet/.cookie" + })); } #[test] @@ -241,7 +253,10 @@ mod tests { .unwrap() .display() .to_string(); - assert!(data_dir.ends_with("/ord"), "{data_dir}"); + assert!( + data_dir.ends_with(if cfg!(windows) { r"\ord" } else { "/ord" }), + "{data_dir}" + ); } #[test] @@ -253,7 +268,14 @@ mod tests { .unwrap() .display() .to_string(); - assert!(data_dir.ends_with("/ord/signet"), "{data_dir}"); + assert!( + data_dir.ends_with(if cfg!(windows) { + r"\ord\signet" + } else { + "/ord/signet" + }), + "{data_dir}" + ); } #[test] @@ -266,7 +288,14 @@ mod tests { .unwrap() .display() .to_string(); - assert!(data_dir.ends_with("foo/signet"), "{data_dir}"); + assert!( + data_dir.ends_with(if cfg!(windows) { + r"foo\signet" + } else { + "foo/signet" + }), + "{data_dir}" + ); } #[test] @@ -285,10 +314,38 @@ mod tests { check_network_alias("main", "ord"); check_network_alias("mainnet", "ord"); - check_network_alias("regtest", "ord/regtest"); - check_network_alias("signet", "ord/signet"); - check_network_alias("test", "ord/testnet3"); - check_network_alias("testnet", "ord/testnet3"); + check_network_alias( + "regtest", + if cfg!(windows) { + r"ord\regtest" + } else { + "ord/regtest" + }, + ); + check_network_alias( + "signet", + if cfg!(windows) { + r"ord\signet" + } else { + "ord/signet" + }, + ); + check_network_alias( + "test", + if cfg!(windows) { + r"ord\testnet3" + } else { + "ord/testnet3" + }, + ); + check_network_alias( + "testnet", + if cfg!(windows) { + r"ord\testnet3" + } else { + "ord/testnet3" + }, + ); } #[test] diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index e90d521572..d9d29c5857 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -903,7 +903,14 @@ mod tests { .unwrap() .display() .to_string(); - assert!(acme_cache.contains("foo/acme-cache"), "{acme_cache}") + assert!( + acme_cache.contains(if cfg!(windows) { + r"foo\acme-cache" + } else { + "foo/acme-cache" + }), + "{acme_cache}" + ) } #[test] diff --git a/src/subcommand/wallet/identify.rs b/src/subcommand/wallet/identify.rs index daa65428d5..1bd2735338 100644 --- a/src/subcommand/wallet/identify.rs +++ b/src/subcommand/wallet/identify.rs @@ -19,7 +19,8 @@ impl Identify { if let Some(path) = &self.ordinals { for (output, ordinal) in identify_from_tsv( utxos, - &fs::read_to_string(path).with_context(|| "I/O error reading `{path}`")?, + &fs::read_to_string(path) + .with_context(|| format!("I/O error reading `{}`", path.display()))?, )? { println!("{output}\t{ordinal}"); } diff --git a/tests/command_builder.rs b/tests/command_builder.rs index acba29961b..2a66f256f9 100644 --- a/tests/command_builder.rs +++ b/tests/command_builder.rs @@ -108,8 +108,9 @@ impl CommandBuilder { .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) - .env("HOME", self.tempdir.path()) .current_dir(&self.tempdir) + .arg("--data-dir") + .arg(self.tempdir.path()) .args(&self.args); command diff --git a/tests/test_server.rs b/tests/test_server.rs index 8aa740643e..cd2697dacb 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -28,7 +28,6 @@ impl TestServer { tempdir.path().display(), args.join(" "), ).to_args()) - .env("HOME", tempdir.path()) .env("ORD_DISABLE_PROGRESS_BAR", "1") .current_dir(&tempdir) .spawn().unwrap(); diff --git a/tests/wallet.rs b/tests/wallet.rs index 88bebdce37..e95b1333c6 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -61,9 +61,7 @@ fn identify_from_tsv_file_not_found() { CommandBuilder::new("wallet identify --ordinals foo.tsv") .rpc_server(&rpc_server) .expected_exit_code(1) - .expected_stderr( - "error: I/O error reading `{path}`\nbecause: No such file or directory (os error 2)\n", - ) + .stderr_regex("error: I/O error reading `.*`\nbecause: .*\n") .run(); }