Skip to content

Commit 673bb69

Browse files
committed
Ignore tests that need Administrator privileges on Windows.
This patch allows you to run them when wanted with ``--ignored`` on Windows.
1 parent 6195924 commit 673bb69

File tree

4 files changed

+69
-19
lines changed

4 files changed

+69
-19
lines changed

ci/azure-test-all.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ steps:
2626
# fix the link errors.
2727
- bash: cargo test --features 'deny-warnings curl/force-system-lib-on-osx'
2828
displayName: "cargo test"
29+
30+
# Run any tests that have been marked ignore.
31+
#
32+
# `--include-ignored` is only supported on nightly so far, so we have to call
33+
# this separately for now.
34+
- bash: cargo test --features 'deny-warnings curl/force-system-lib-on-osx' -- --ignored
35+
displayName: "cargo test -- --ignored"

tests/testsuite/build.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,12 +1495,12 @@ package `test v0.0.0 ([CWD])`",
14951495
}
14961496

14971497
#[cargo_test]
1498+
#[cfg_attr(windows, ignore)]
1499+
/// Make sure ignored symlinks don't break the build
1500+
///
1501+
/// This test is marked ``ignore`` on Windows because it needs admin permissions.
1502+
/// Run it with ``--ignored``.
14981503
fn ignore_broken_symlinks() {
1499-
// windows and symlinks don't currently agree that well
1500-
if cfg!(windows) {
1501-
return;
1502-
}
1503-
15041504
let p = project()
15051505
.file("Cargo.toml", &basic_bin_manifest("foo"))
15061506
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))

tests/testsuite/package.rs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -505,25 +505,39 @@ fn package_git_submodule() {
505505
}
506506

507507
#[cargo_test]
508+
#[cfg_attr(windows, ignore)]
509+
/// Tests if a symlink to a git submodule is properly handled.
510+
///
511+
/// This test is ignored on Windows, because it needs Administrator
512+
/// permissions to run. If you do want to run this test, please
513+
/// run the tests with ``--ignored``, e.g.
514+
///
515+
/// ```text
516+
/// cargo test -- --ignored
517+
/// ```
508518
fn package_symlink_to_submodule() {
509519
#[cfg(unix)]
510-
use std::os::unix::fs::symlink as symlink;
520+
use std::os::unix::fs::symlink;
511521
#[cfg(windows)]
512522
use std::os::windows::fs::symlink_dir as symlink;
513523

514524
let project = git::new("foo", |project| {
515-
project
516-
.file("src/lib.rs", "pub fn foo() {}")
517-
}).unwrap();
525+
project.file("src/lib.rs", "pub fn foo() {}")
526+
})
527+
.unwrap();
518528

519529
let library = git::new("submodule", |library| {
520530
library.no_manifest().file("Makefile", "all:")
521-
}).unwrap();
531+
})
532+
.unwrap();
522533

523534
let repository = git2::Repository::open(&project.root()).unwrap();
524535
let url = path2url(library.root()).to_string();
525536
git::add_submodule(&repository, &url, Path::new("submodule"));
526-
t!(symlink(&project.root().join("submodule"), &project.root().join("submodule-link")));
537+
t!(symlink(
538+
&project.root().join("submodule"),
539+
&project.root().join("submodule-link")
540+
));
527541
git::add(&repository);
528542
git::commit(&repository);
529543

@@ -532,8 +546,9 @@ fn package_symlink_to_submodule() {
532546
.reset(
533547
&repository.revparse_single("HEAD").unwrap(),
534548
git2::ResetType::Hard,
535-
None
536-
).unwrap();
549+
None,
550+
)
551+
.unwrap();
537552

538553
project
539554
.cargo("package --no-verify -v")
@@ -697,9 +712,19 @@ See [..]
697712
}
698713

699714
#[cargo_test]
715+
#[cfg_attr(windows, ignore)]
716+
/// Tests if a broken symlink is properly handled when packaging.
717+
///
718+
/// This test is ignored on Windows, because it needs Administrator
719+
/// permissions to run. If you do want to run this test, please
720+
/// run the tests with ``--ignored``, e.g.
721+
///
722+
/// ```text
723+
/// cargo test -- --ignored
724+
/// ```
700725
fn broken_symlink() {
701726
#[cfg(unix)]
702-
use std::os::unix::fs::symlink as symlink;
727+
use std::os::unix::fs::symlink;
703728
#[cfg(windows)]
704729
use std::os::windows::fs::symlink_dir as symlink;
705730

@@ -739,6 +764,16 @@ Caused by:
739764
}
740765

741766
#[cargo_test]
767+
#[cfg_attr(windows, ignore)]
768+
/// Tests if a symlink to a directory is proberly included.
769+
///
770+
/// This test is ignored on Windows, because it needs Administrator
771+
/// permissions to run. If you do want to run this test, please
772+
/// run the tests with ``--ignored``, e.g.
773+
///
774+
/// ```text
775+
/// cargo test -- --ignored
776+
/// ```
742777
fn package_symlink_to_dir() {
743778
project()
744779
.file("src/main.rs", r#"fn main() { println!("hello"); }"#)

tests/testsuite/support/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,19 @@ struct SymlinkBuilder {
183183

184184
impl SymlinkBuilder {
185185
pub fn new(dst: PathBuf, src: PathBuf) -> SymlinkBuilder {
186-
SymlinkBuilder { dst, src, src_is_dir: false }
186+
SymlinkBuilder {
187+
dst,
188+
src,
189+
src_is_dir: false,
190+
}
187191
}
188192

189193
pub fn new_dir(dst: PathBuf, src: PathBuf) -> SymlinkBuilder {
190-
SymlinkBuilder { dst, src, src_is_dir: true }
194+
SymlinkBuilder {
195+
dst,
196+
src,
197+
src_is_dir: true,
198+
}
191199
}
192200

193201
#[cfg(unix)]
@@ -273,9 +281,9 @@ impl ProjectBuilder {
273281
/// Create a symlink to a directory
274282
pub fn symlink_dir<T: AsRef<Path>>(mut self, dst: T, src: T) -> Self {
275283
self.symlinks.push(SymlinkBuilder::new_dir(
276-
self.root.root().join(dst),
277-
self.root.root().join(src),
278-
));
284+
self.root.root().join(dst),
285+
self.root.root().join(src),
286+
));
279287
self
280288
}
281289

0 commit comments

Comments
 (0)