1 # Unix SMB/CIFS implementation.
5 # Copyright (C) David Mulder <dmulder@samba.org> 2024
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 """Cargo tests for Rust sources"""
23 from samba
.tests
import TestCase
, BlackboxProcessError
25 from subprocess
import Popen
, PIPE
26 from samba
import is_rust_built
29 class RustCargoTests(TestCase
):
33 # Locate the rust source directory
34 self
.rust_dir
= os
.path
.abspath(
37 os
.path
.dirname(__file__
)
43 # Locate the bin directory
44 self
.target_dir
= os
.path
.abspath(
47 os
.path
.dirname(__file__
)
54 def check_cargo_test(self
, crate_toml
):
55 # Execute the cargo test command
56 cmd
= 'cargo test --target-dir=%s --manifest-path=%s' % (self
.target_dir
, crate_toml
)
57 p
= Popen(cmd
, stdout
=PIPE
, stderr
=PIPE
, shell
=True)
58 stdoutdata
, stderrdata
= p
.communicate()
59 retcode
= p
.returncode
61 msg
= "cargo test failed; return code %s" % retcode
62 raise BlackboxProcessError(retcode
,
64 stdoutdata
.decode('utf-8'),
65 stderrdata
.decode('utf-8'),
69 if not is_rust_built():
70 self
.skipTest('Cannot test Samba Rust if not built')
73 for root
, dirs
, files
in os
.walk(self
.rust_dir
):
75 if os
.path
.basename(file) == 'Cargo.toml':
76 if root
!= self
.rust_dir
:
77 crates
.append(os
.path
.join(root
, file))
79 for crate_toml
in crates
:
80 with self
.subTest(crate_toml
):
81 self
.check_cargo_test(crate_toml
)