(self, state: 'ModuleState', args: T.Tuple[str, BuildTarget], kwargs: 'FuncTest')
return ModuleReturnValue(None, [new_target, test])
Generate a rust test target from a given rust target.

        Rust puts it's unitests inside it's main source files, unlike most
        languages that put them in external files. This means that normally
        you have to define two separate targets with basically the same
        arguments to get tests:

        ```meson
        rust_lib_sources = [...]
        rust_lib = static_library(
            'rust_lib',
            rust_lib_sources,
        )

        rust_lib_test = executable(
            'rust_lib_test',
            rust_lib_sources,
            rust_args : ['--test'],
        )

        test(
            'rust_lib_test',
            rust_lib_test,
            protocol : 'rust',
        )
        ```

        This is all fine, but not very DRY. This method makes it much easier
        to define rust tests:

        ```meson
        rust = import('unstable-rust')

        rust_lib = static_library(
            'rust_lib',
            [sources],
        )

        rust.test('rust_lib_test', rust_lib)
        ```
Generate a rust test target from a given rust target.
Generate a rust test target from a given rust target .
def test(self, state: 'ModuleState', args: T.Tuple[str, BuildTarget], kwargs: 'FuncTest') -> ModuleReturnValue:
        """Generate a rust test target from a given rust target.

        Rust puts it's unitests inside it's main source files, unlike most
        languages that put them in external files. This means that normally
        you have to define two separate targets with basically the same
        arguments to get tests:

        ```meson
        rust_lib_sources = [...]
        rust_lib = static_library(
            'rust_lib',
            rust_lib_sources,
        )

        rust_lib_test = executable(
            'rust_lib_test',
            rust_lib_sources,
            rust_args : ['--test'],
        )

        test(
            'rust_lib_test',
            rust_lib_test,
            protocol : 'rust',
        )
        ```

        This is all fine, but not very DRY. This method makes it much easier
        to define rust tests:

        ```meson
        rust = import('unstable-rust')

        rust_lib = static_library(
            'rust_lib',
            [sources],
        )

        rust.test('rust_lib_test', rust_lib)
        ```
        """
        name = args[0]
        base_target: BuildTarget = args[1]
        if not base_target.uses_rust():
            raise InterpreterException('Second positional argument to rustmod.test() must be a rust based target')
        extra_args = kwargs['args']

        # Delete any arguments we don't want passed
        if '--test' in extra_args:
            mlog.warning('Do not add --test to rustmod.test arguments')
            extra_args.remove('--test')
        if '--format' in extra_args:
            mlog.warning('Do not add --format to rustmod.test arguments')
            i = extra_args.index('--format')
            # Also delete the argument to --format
            del extra_args[i + 1]
            del extra_args[i]
        for i, a in enumerate(extra_args):
            if isinstance(a, str) and a.startswith('--format='):
                del extra_args[i]
                break

        dependencies = [d for d in kwargs['dependencies']]

        # We need to cast here, as currently these don't have protocol in them, but test itself does.
        tkwargs = T.cast('_kwargs.FuncTest', kwargs.copy())

        tkwargs['args'] = extra_args + ['--test', '--format', 'pretty']
        tkwargs['protocol'] = 'rust'

        new_target_kwargs = base_target.kwargs.copy()
        # Don't mutate the shallow copied list, instead replace it with a new
        # one
        new_target_kwargs['rust_args'] = new_target_kwargs.get('rust_args', []) + ['--test']
        new_target_kwargs['install'] = False
        new_target_kwargs['dependencies'] = new_target_kwargs.get('dependencies', []) + dependencies

        new_target = Executable(
            name, base_target.subdir, state.subproject,
            base_target.for_machine, base_target.sources,
            base_target.objects, base_target.environment,
            new_target_kwargs
        )

        test = self.interpreter.make_test(
            self.interpreter.current_node, (name, new_target), tkwargs)

        return ModuleReturnValue(None, [new_target, test])
def test ( self , state : 'ModuleState' , args : T . Tuple [ str , BuildTarget ] , kwargs : 'FuncTest' ) -> ModuleReturnValue : name = args [ 0 ] base_target : BuildTarget = args [ 1 ] if not base_target . uses_rust ( ) : raise InterpreterException ( 'Second positional argument to rustmod.test() must be a rust based target' ) extra_args = kwargs [ 'args' ] # Delete any arguments we don't want passed if '--test' in extra_args : mlog . warning ( 'Do not add --test to rustmod.test arguments' ) extra_args . remove ( '--test' ) if '--format' in extra_args : mlog . warning ( 'Do not add --format to rustmod.test arguments' ) i = extra_args . index ( '--format' ) # Also delete the argument to --format del extra_args [ i + 1 ] del extra_args [ i ] for i , a in enumerate ( extra_args ) : if isinstance ( a , str ) and a . startswith ( '--format=' ) : del extra_args [ i ] break dependencies = [ d for d in kwargs [ 'dependencies' ] ] # We need to cast here, as currently these don't have protocol in them, but test itself does. tkwargs = T . cast ( '_kwargs.FuncTest' , kwargs . copy ( ) ) tkwargs [ 'args' ] = extra_args + [ '--test' , '--format' , 'pretty' ] tkwargs [ 'protocol' ] = 'rust' new_target_kwargs = base_target . kwargs . copy ( ) # Don't mutate the shallow copied list, instead replace it with a new # one new_target_kwargs [ 'rust_args' ] = new_target_kwargs . get ( 'rust_args' , [ ] ) + [ '--test' ] new_target_kwargs [ 'install' ] = False new_target_kwargs [ 'dependencies' ] = new_target_kwargs . get ( 'dependencies' , [ ] ) + dependencies new_target = Executable ( name , base_target . subdir , state . subproject , base_target . for_machine , base_target . sources , base_target . objects , base_target . environment , new_target_kwargs ) test = self . interpreter . make_test ( self . interpreter . current_node , ( name , new_target ) , tkwargs ) return ModuleReturnValue ( None , [ new_target , test ] )