@@ -36,6 +36,7 @@ use syntax::diagnostic;
36
36
use target:: * ;
37
37
use package_source:: PkgSrc ;
38
38
use source_control:: { CheckedOutSources , DirToUse , safe_git_clone} ;
39
+ use exit_codes:: { BAD_FLAG_CODE , COPY_FAILED_CODE } ;
39
40
use util:: datestamp;
40
41
41
42
fn fake_ctxt ( sysroot : Path , workspace : & Path ) -> BuildContext {
@@ -244,14 +245,26 @@ fn rustpkg_exec() -> Path {
244
245
fn command_line_test ( args : & [ ~str ] , cwd : & Path ) -> ProcessOutput {
245
246
match command_line_test_with_env ( args, cwd, None ) {
246
247
Success ( r) => r,
247
- _ => fail2 ! ( "Command line test failed" )
248
+ Fail ( error ) => fail2 ! ( "Command line test failed with error {}" , error )
248
249
}
249
250
}
250
251
251
252
fn command_line_test_partial ( args : & [ ~str ] , cwd : & Path ) -> ProcessResult {
252
253
command_line_test_with_env ( args, cwd, None )
253
254
}
254
255
256
+ fn command_line_test_expect_fail ( args : & [ ~str ] ,
257
+ cwd : & Path ,
258
+ env : Option < ~[ ( ~str , ~str ) ] > ,
259
+ expected_exitcode : int ) {
260
+ match command_line_test_with_env ( args, cwd, env) {
261
+ Success ( _) => fail2 ! ( "Should have failed with {}, but it succeeded" , expected_exitcode) ,
262
+ Fail ( error) if error == expected_exitcode => ( ) , // ok
263
+ Fail ( other) => fail2 ! ( "Expected to fail with {}, but failed with {} instead" ,
264
+ expected_exitcode, other)
265
+ }
266
+ }
267
+
255
268
enum ProcessResult {
256
269
Success ( ProcessOutput ) ,
257
270
Fail ( int ) // exit code
@@ -1448,11 +1461,11 @@ fn compile_flag_fail() {
1448
1461
let p_id = PkgId :: new ( "foo" ) ;
1449
1462
let workspace = create_local_package ( & p_id) ;
1450
1463
let workspace = workspace. path ( ) ;
1451
- command_line_test ( [ test_sysroot ( ) . to_str ( ) ,
1464
+ command_line_test_expect_fail ( [ test_sysroot ( ) . to_str ( ) ,
1452
1465
~"install",
1453
1466
~"--no-link",
1454
1467
~"foo"] ,
1455
- workspace) ;
1468
+ workspace, None , BAD_FLAG_CODE ) ;
1456
1469
assert ! ( !built_executable_exists( workspace, "foo" ) ) ;
1457
1470
assert ! ( !object_file_exists( workspace, "foo" ) ) ;
1458
1471
}
@@ -1488,14 +1501,11 @@ fn notrans_flag_fail() {
1488
1501
let flags_to_test = [ ~"--no-trans", ~"--parse-only",
1489
1502
~"--pretty", ~"-S "] ;
1490
1503
for flag in flags_to_test. iter ( ) {
1491
- command_line_test ( [ test_sysroot ( ) . to_str ( ) ,
1504
+ command_line_test_expect_fail ( [ test_sysroot ( ) . to_str ( ) ,
1492
1505
~"install",
1493
1506
flag. clone ( ) ,
1494
1507
~"foo"] ,
1495
- workspace) ;
1496
- // Ideally we'd test that rustpkg actually fails, but
1497
- // since task failure doesn't set the exit code properly,
1498
- // we can't tell
1508
+ workspace, None , BAD_FLAG_CODE ) ;
1499
1509
assert ! ( !built_executable_exists( workspace, "foo" ) ) ;
1500
1510
assert ! ( !object_file_exists( workspace, "foo" ) ) ;
1501
1511
assert ! ( !lib_exists( workspace, & Path ( "foo" ) , NoVersion ) ) ;
@@ -1522,11 +1532,11 @@ fn dash_S_fail() {
1522
1532
let p_id = PkgId :: new ( "foo" ) ;
1523
1533
let workspace = create_local_package ( & p_id) ;
1524
1534
let workspace = workspace. path ( ) ;
1525
- command_line_test ( [ test_sysroot ( ) . to_str ( ) ,
1535
+ command_line_test_expect_fail ( [ test_sysroot ( ) . to_str ( ) ,
1526
1536
~"install",
1527
1537
~"-S ",
1528
1538
~"foo"] ,
1529
- workspace) ;
1539
+ workspace, None , BAD_FLAG_CODE ) ;
1530
1540
assert ! ( !built_executable_exists( workspace, "foo" ) ) ;
1531
1541
assert ! ( !object_file_exists( workspace, "foo" ) ) ;
1532
1542
assert ! ( !assembly_file_exists( workspace, "foo" ) ) ;
@@ -1587,11 +1597,13 @@ fn test_emit_llvm_S_fail() {
1587
1597
let p_id = PkgId :: new ( "foo" ) ;
1588
1598
let workspace = create_local_package ( & p_id) ;
1589
1599
let workspace = workspace. path ( ) ;
1590
- command_line_test ( [ test_sysroot ( ) . to_str ( ) ,
1600
+ command_line_test_expect_fail ( [ test_sysroot ( ) . to_str ( ) ,
1591
1601
~"install",
1592
1602
~"-S ", ~"--emit-llvm",
1593
1603
~"foo"] ,
1594
- workspace) ;
1604
+ workspace,
1605
+ None ,
1606
+ BAD_FLAG_CODE ) ;
1595
1607
assert ! ( !built_executable_exists( workspace, "foo" ) ) ;
1596
1608
assert ! ( !object_file_exists( workspace, "foo" ) ) ;
1597
1609
assert ! ( !llvm_assembly_file_exists( workspace, "foo" ) ) ;
@@ -1620,11 +1632,13 @@ fn test_emit_llvm_fail() {
1620
1632
let p_id = PkgId :: new ( "foo" ) ;
1621
1633
let workspace = create_local_package ( & p_id) ;
1622
1634
let workspace = workspace. path ( ) ;
1623
- command_line_test ( [ test_sysroot ( ) . to_str ( ) ,
1635
+ command_line_test_expect_fail ( [ test_sysroot ( ) . to_str ( ) ,
1624
1636
~"install",
1625
1637
~"--emit-llvm",
1626
1638
~"foo"] ,
1627
- workspace) ;
1639
+ workspace,
1640
+ None ,
1641
+ BAD_FLAG_CODE ) ;
1628
1642
assert ! ( !built_executable_exists( workspace, "foo" ) ) ;
1629
1643
assert ! ( !object_file_exists( workspace, "foo" ) ) ;
1630
1644
assert ! ( !llvm_bitcode_file_exists( workspace, "foo" ) ) ;
@@ -1665,11 +1679,10 @@ fn test_build_install_flags_fail() {
1665
1679
~[ ~"--target", host_triple ( ) ] ,
1666
1680
~[ ~"--target-cpu", ~"generic"] ,
1667
1681
~[ ~"-Z ", ~"--time-passes"] ] ;
1682
+ let cwd = os:: getcwd ( ) ;
1668
1683
for flag in forbidden. iter ( ) {
1669
- let output = command_line_test_output ( [ test_sysroot ( ) . to_str ( ) ,
1670
- ~"list"] + * flag) ;
1671
- assert ! ( output. len( ) > 1 ) ;
1672
- assert ! ( output[ 1 ] . find_str( "can only be used with" ) . is_some( ) ) ;
1684
+ command_line_test_expect_fail ( [ test_sysroot ( ) . to_str ( ) ,
1685
+ ~"list"] + * flag, & cwd, None , BAD_FLAG_CODE ) ;
1673
1686
}
1674
1687
}
1675
1688
@@ -1686,6 +1699,7 @@ fn test_optimized_build() {
1686
1699
assert ! ( built_executable_exists( workspace, "foo" ) ) ;
1687
1700
}
1688
1701
1702
+ #[ test]
1689
1703
fn pkgid_pointing_to_subdir( ) {
1690
1704
// The actual repo is mockgithub.com/mozilla/some_repo
1691
1705
// rustpkg should recognize that and treat the part after some_repo/ as a subdir
@@ -1717,6 +1731,7 @@ fn pkgid_pointing_to_subdir() {
1717
1731
assert_executable_exists(workspace, " testpkg");
1718
1732
}
1719
1733
1734
+ #[test]
1720
1735
fn test_recursive_deps() {
1721
1736
let a_id = PkgId::new(" a");
1722
1737
let b_id = PkgId::new(" b");
@@ -1762,6 +1777,7 @@ fn test_install_to_rust_path() {
1762
1777
assert!(!executable_exists(second_workspace, " foo"));
1763
1778
}
1764
1779
1780
+ #[test]
1765
1781
fn test_target_specific_build_dir() {
1766
1782
let p_id = PkgId::new(" foo");
1767
1783
let workspace = create_local_package(&p_id);
@@ -1870,8 +1886,9 @@ fn correct_package_name_with_rust_path_hack() {
1870
1886
let rust_path = Some(~[(~" RUST_PATH ", format!(" { } : { } ", dest_workspace.to_str(),
1871
1887
foo_workspace.push_many([" src", " foo-0.1 "]).to_str()))]);
1872
1888
// bar doesn't exist, but we want to make sure rustpkg doesn't think foo is bar
1873
- command_line_test_with_env([~" install", ~" --rust-path-hack", ~" bar"],
1874
- dest_workspace, rust_path);
1889
+ command_line_test_expect_fail([~" install", ~" --rust-path-hack", ~" bar"],
1890
+ // FIXME #3408: Should be NONEXISTENT_PACKAGE_CODE
1891
+ dest_workspace, rust_path, COPY_FAILED_CODE);
1875
1892
assert!(!executable_exists(dest_workspace, " bar"));
1876
1893
assert!(!lib_exists(dest_workspace, &bar_id.path.clone(), bar_id.version.clone()));
1877
1894
assert!(!executable_exists(dest_workspace, " foo"));
@@ -2050,6 +2067,23 @@ fn test_7402() {
2050
2067
assert_executable_exists(dest_workspace, " foo");
2051
2068
}
2052
2069
2070
+ #[test]
2071
+ fn test_compile_error() {
2072
+ let foo_id = PkgId::new(" foo");
2073
+ let foo_workspace = create_local_package(&foo_id);
2074
+ let foo_workspace = foo_workspace.path();
2075
+ let main_crate = foo_workspace.push_many([" src", " foo-0.1 ", " main. rs"]);
2076
+ // Write something bogus
2077
+ writeFile(&main_crate, " pub fn main( ) { if 42 != ~\" the answer\" { fail!( ) ; } } ");
2078
+ let result = command_line_test_partial([~" build", ~" foo"], foo_workspace);
2079
+ match result {
2080
+ Success(*) => fail2!(" Failed by succeeding!"), // should be a compile error
2081
+ Fail(status) => {
2082
+ debug2!(" Failed with status { : ?} ... that' s good, right?" , status) ;
2083
+ }
2084
+ }
2085
+ }
2086
+
2053
2087
/// Returns true if p exists and is executable
2054
2088
fn is_executable( p: & Path ) -> bool {
2055
2089
use std:: libc:: consts:: os:: posix88:: { S_IXUSR } ;
0 commit comments