3个稳定版本

2.0.2 2023年10月26日
2.0.1 2023年4月8日
2.0.0 2023年3月24日

#162测试

每月 39 次下载

MIT 许可证

26KB
553

vaneglis

crates ci

example

此软件接受测试文件作为参数,包含要运行的命令列表、预期的标准输出、标准错误、退出状态,并告知用户测试是否成功、失败或崩溃。

⭐ Don't忘记给项目加星if你喜欢这个项目!

💻 安装

您可以在以下链接找到适用于 linuxmacOSWindows 的预构建 版本

否则,您可以使用以下命令使用 cargo 从源安装 vangelis

cargo install vangelis

⭐ Don't忘记给项目加星if你喜欢这个项目!

📒 使用方法

A functional testing framework

Usage: vangelis [OPTIONS] <TEST_FILE>...

Arguments:
  <TEST_FILE>...  Path to one or multiple test file(s) to be executed

Options:
      --diff     Display the got/expected difference for each failed test in the shell
      --ci       Stop the execution and display the got/expected difference if a test didn't succeed
  -h, --help     Print help
  -V, --version  Print version

🗂 测试文件

测试文件必须在 toml 中具有以下模式

// Definitions

Default {
    exit_status: Option<Integer>,
    timeout: Option<Float>,
    working_dir: Option<String>,
    runs_on: Option<Array<String>>,
    unix_shell: Option<String>,
    windows_shell: Option<String>,
}

Test {
    cmd: String,
    stdin: Option<String>,
    stdout: Option<String>,
    stderr: Option<String>,
    exit_status: Option<Integer>,
    timeout: Option<Float>,
    working_dir: Option<String>,
    runs_on: Option<Array<String>>,
    unix_shell: Option<String>,
    windows_shell: Option<String>,
}

// Test file content

TestFile {
    default: Option<Default>,
    test: Map<String, Test>,
}

📝 示例

# testfile.toml

[default]
# use powershell as default shell on windows
windows_shell = "powershell"

[test.echo]
cmd = "echo hello"
stdout = "hello\n"

[test.power]
# this test can only run under unix systems
runs_on = ["linux", "macos"]
cmd = "whoami"
stdout = "root\n"

[test.sleep]
# this test will timeout
timeout = 5
cmd = "sleep 10"
stdout = ""
stderr = ""

[test."print args"]
cmd = "python3 print_args.py hey brother"
stdout = """
hey
brother
"""
stderr = ""

[test."print stdin"]
cmd = "python3 print_stdin.py"
stdin = """
hey
brother
"""
stdout = """
hey

brother

"""
stderr = ""

要运行此示例,请输入以下命令

vangelis examples/testfile.toml

⚙️ 参数

[cmd]

# Command to run (mandatory value)

# Example:
# Build a software and ensure the build takes less that 300 seconds:
cmd = "make"
timeout = 300
[stdout]

# Expected stdout of the command

# Example:
# I want to check if I have root privileges:
cmd = "whoami"
stdout = "root\n"
[stderr]

# Expected stderr of the command

# Example:
# I Expect this error message for the following command:
cmd = "ls /root"
# expected stderr
stderr = "ls: cannot open directory '/root': Permission denied\n"
[stdin]

# stdin content to be forwarded to the command

# Example:
cmd = "cat"
# stdin content
stdin = "hello"
# expected stdout
stdout = "hello"
[exit_status]

# Set the expected exit status of a command

# Default value:
exit_status = 0

# Example:
# The test will expect a return value of 1
exit_status = 1
cmd = "git"
[timeout]

# Set the timeout of a command (in seconds)

# Default value:
timeout = 60

# Example:
# The command must not exceed 5 seconds
timeout = 5
cmd = "sleep 10"
[runs_on]

# An array of strings that defines on witch os the test is allowed to run

# Default value:
runs_on = ["linux", "windows", "macos"]

# Example:
# The test will only run under linux
runs_on = ["linux"]
[unix_shell]

# Set the shell to use to run commands under unix systems

# Default value:
unix_shell = "sh"

# Example:
# The command will run under "zsh" instead of "sh" under linux
unix_shell = "zsh"
[windows_shell]

# Set the shell to use to run commands under windows

# Default value:
windows_shell = "cmd"

# Example:
# The command will run under "powershell" instead of "cmd" under windows
windows_shell = "powershell"
[working_dir]

# Set the working directory of a test
# by default, the path is set where the testfile is located
# working_dir value can be a relative or a full path

# Default value
working_dir = "."

# Examples:
# Set the working directory of the command to "/tmp"
working_dir = "/tmp"
cmd = "ls"
# Set the working directory of the command to the parent folder of the testfile
working_dir = ".."
cmd = "ls"

许可证

此项目在 MIT 许可证下发布。

贡献

欢迎拉取请求。对于重大更改,请首先提交问题以讨论您想要更改的内容。

依赖项

~4–12MB
~127K SLoC