Path: blob/main/tests/integration_tests/style/test_rust.py
1958 views
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.1# SPDX-License-Identifier: Apache-2.02"""Tests ensuring codebase style compliance for Rust."""34import framework.utils as utils567def test_rust_style():8"""Fail if there's misbehaving Rust style in this repo."""9# Check that the output is empty.10_, stdout, _ = utils.run_cmd(11'cargo fmt --all -- --check')1213# rustfmt prepends `"Diff in"` to the reported output.14assert "Diff in" not in stdout151617def test_ensure_mod_tests():18"""Check that files containing unit tests have a 'tests' module defined."""19# List all source files containing rust #[test] attribute,20# (excluding generated files and integration test directories).21# Take the list and check each file contains 'mod tests {', output file22# name if it doesn't.23cmd = (24'/bin/bash '25'-c '26'"grep '27'--files-without-match '28'\'mod tests {\' '29'\\$(grep '30'--files-with-matches '31'--recursive '32'--exclude-dir=src/*_gen/* '33'\'\\#\\[test\\]\' ../src/*/src)" '34)3536# The outer grep returns 0 even if it finds files without the match, so we37# ignore the return code.38result = utils.run_cmd(cmd, no_shell=False, ignore_return_code=True)3940error_msg = (41'Tests found in files without a "tests" module:\n {}'42'To ensure code coverage is reported correctly, please check that '43'your tests are in a module named "tests".'.format(result.stdout)44)4546assert not result.stdout, error_msg474849