]>
git.proxmox.com Git - rustc.git/blob - src/bootstrap/bootstrap_test.py
3 from __future__
import absolute_import
, division
, print_function
11 from shutil
import rmtree
16 class VerifyTestCase(unittest
.TestCase
):
17 """Test Case for verify"""
19 self
.container
= tempfile
.mkdtemp()
20 self
.src
= os
.path
.join(self
.container
, "src.txt")
21 self
.bad_src
= os
.path
.join(self
.container
, "bad.txt")
22 content
= "Hello world"
24 self
.expected
= hashlib
.sha256(content
.encode("utf-8")).hexdigest()
26 with
open(self
.src
, "w") as src
:
28 with
open(self
.bad_src
, "w") as bad
:
32 rmtree(self
.container
)
34 def test_valid_file(self
):
35 """Check if the sha256 sum of the given file is valid"""
36 self
.assertTrue(bootstrap
.verify(self
.src
, self
.expected
, False))
38 def test_invalid_file(self
):
39 """Should verify that the file is invalid"""
40 self
.assertFalse(bootstrap
.verify(self
.bad_src
, self
.expected
, False))
43 class ProgramOutOfDate(unittest
.TestCase
):
44 """Test if a program is out of date"""
46 self
.container
= tempfile
.mkdtemp()
47 os
.mkdir(os
.path
.join(self
.container
, "stage0"))
48 self
.build
= bootstrap
.RustBuild()
49 self
.build
.date
= "2017-06-15"
50 self
.build
.build_dir
= self
.container
51 self
.rustc_stamp_path
= os
.path
.join(self
.container
, "stage0",
53 self
.key
= self
.build
.date
+ str(None)
56 rmtree(self
.container
)
58 def test_stamp_path_does_not_exists(self
):
59 """Return True when the stamp file does not exists"""
60 if os
.path
.exists(self
.rustc_stamp_path
):
61 os
.unlink(self
.rustc_stamp_path
)
62 self
.assertTrue(self
.build
.program_out_of_date(self
.rustc_stamp_path
, self
.key
))
64 def test_dates_are_different(self
):
65 """Return True when the dates are different"""
66 with
open(self
.rustc_stamp_path
, "w") as rustc_stamp
:
67 rustc_stamp
.write("2017-06-14None")
68 self
.assertTrue(self
.build
.program_out_of_date(self
.rustc_stamp_path
, self
.key
))
70 def test_same_dates(self
):
71 """Return False both dates match"""
72 with
open(self
.rustc_stamp_path
, "w") as rustc_stamp
:
73 rustc_stamp
.write("2017-06-15None")
74 self
.assertFalse(self
.build
.program_out_of_date(self
.rustc_stamp_path
, self
.key
))
77 if __name__
== '__main__':
78 SUITE
= unittest
.TestSuite()
79 TEST_LOADER
= unittest
.TestLoader()
80 SUITE
.addTest(doctest
.DocTestSuite(bootstrap
))
82 TEST_LOADER
.loadTestsFromTestCase(VerifyTestCase
),
83 TEST_LOADER
.loadTestsFromTestCase(ProgramOutOfDate
)])
85 RUNNER
= unittest
.TextTestRunner(stream
=sys
.stdout
, verbosity
=2)
86 result
= RUNNER
.run(SUITE
)
87 sys
.exit(0 if result
.wasSuccessful() else 1)