如何在没有 Rust 编译器的情况下在另一台机器上运行货物测试? [英] How can I run cargo tests on another machine without the Rust compiler?

查看:42
本文介绍了如何在没有 Rust 编译器的情况下在另一台机器上运行货物测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道编译器可以直接在arm-linux-androideabi上运行,但是Android模拟器(我的意思是在x86/amd64上模拟ARM)很慢,所以我不想在模拟器上使用 cargorustc ,我只想在上面运行测试.

I know that the compiler can run directly on arm-linux-androideabi, but the Android emulator (I mean emulation of ARM on x86/amd64) is slow, so I don't want to use cargo and rustc on the emulator, I only want to run tests on it.

我想在我的 PC 上交叉编译测试(cargo test --target=arm-linux-androideabi --no-run?),然后上传并在模拟器上运行,希望能发现像 this 之类的错误.

I want to cross-compile tests on my PC (cargo test --target=arm-linux-androideabi --no-run?), and then upload and run them on emulator, hoping to catch bugs like this.

如何在不运行 cargo test 的情况下运行 cargo test?是否像运行所有使用 cargo test --no-run 构建的二进制文件一样简单?

How can I run cargo test without running cargo test? Is it as simple as running all binaries that were built with cargo test --no-run?

推荐答案

cargo test 支持两种测试,一种是普通测试(#[test] fns 和 tests/ 中的文件),另一个是 doc 测试.

There are two kinds of tests supported by cargo test, one is the normal tests (#[test] fns and files inside tests/), the other is the doc tests.

普通测试就像运行所有二进制文件一样简单.如果以错误代码 0 退出,则测试成功.

The normal tests are as simple as running all binaries. The test is considered successful if it exits with error code 0.

文档测试不能交叉测试.Doc 测试由 rustdoc 使用编译器库直接编译和执行,因此编译器必须安装在 ARM 机器上才能运行 doc 测试.事实上,当 HOST ≠ TARGET 时运行 cargo test --doc 将什么都不做.

Doc tests cannot be cross-tested. Doc tests are compiled and executed directly by rustdoc using the compiler libraries, so the compiler must be installed on the ARM machine to run the doc tests. In fact, running cargo test --doc when HOST ≠ TARGET will do nothing.

因此,您最后一个问题的答案是,只要您不依赖文档测试来覆盖.

So, the answer to your last question is yes as long as you don't rely on doc-tests for coverage.

从 Rust 1.19 开始,cargo 支持 目标特定的跑步者,它允许你指定一个脚本在ARM机器上上传和执行测试程序.

Starting from Rust 1.19, cargo supports target specific runners, which allows you to specify a script to upload and execute the test program on the ARM machine.

#!/bin/sh
set -e
adb push "$1" "/sdcard/somewhere/$1"
adb shell "chmod 755 /sdcard/somewhere/$1 && /sdcard/somewhere/$1" 
# ^ note: may need to change this line, see https://stackoverflow.com/q/9379400

把它放到你的.cargo/config:

Put this to your .cargo/config:

[target.arm-linux-androideabi]
runner = ["/path/to/your/run/script.sh"]

然后 cargo test --target=arm-linux-androideabi 应该 Just Work™.

then cargo test --target=arm-linux-androideabi should Just Work™.

如果您的项目托管在 GitHub 上并使用 Travis CI,您可能还想查看 trust.它提供了一个预先打包的解决方案,用于在许多架构上进行测试,包括 CI 上的 ARMv7 Linux(不幸的是没有 Android).

If your project is hosted on GitHub and uses Travis CI, you may also want to check out trust. It provides a pre-packaged solution for testing on many architectures including ARMv7 Linux on the CI (no Android unfortunately).

这篇关于如何在没有 Rust 编译器的情况下在另一台机器上运行货物测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆