Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
rtk/tests/native_test_expression_test.rs at develop · rtk-ai/rtk · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
rtk-ai
rtk
Repository navigation
Code
Issues
892
(892)
Pull requests
691
(691)
Discussions
Actions
Projects
Security and quality
3
(3)
Insights
More
items
Files
Expand file tree
develop
Breadcrumbs
rtk
/
tests
/
native_test_expression_test.rs
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
92 lines (77 loc) · 3.24 KB
develop
Breadcrumbs
rtk
/
tests
/
native_test_expression_test.rs
Copy path
Top
File metadata and controls
Code
Blame
92 lines (77 loc) · 3.24 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!
[
cfg
(
unix
)
]
//! End-to-end coverage for `Commands::Test` routing.
//!
//! `rtk test` doubles as a wrapper around a test runner and as the POSIX `test`
//! utility. The unit tests in `main.rs` cover `is_native_test_expression` on its
//! own; these run the binary so an inverted or removed branch in the `Commands::Test`
//! arm fails here instead of shipping.
use
std
::
path
::
Path
;
use
tempfile
::
TempDir
;
mod
common
;
fn
exit_code
(
cwd
:
&
Path
,
args
:
&
[
&
str
]
)
->
i32
{
common
::
rtk_command
(
)
.
env
(
"LC_ALL"
,
"C"
)
.
env
(
"HOME"
,
cwd
.
join
(
"home"
)
)
.
args
(
args
)
.
current_dir
(
cwd
)
.
output
(
)
.
expect
(
"spawn rtk"
)
.
status
.
code
(
)
.
expect
(
"rtk exited via signal"
)
}
fn
fixture
(
)
->
TempDir
{
let
dir =
TempDir
::
new
(
)
.
expect
(
"create tempdir"
)
;
std
::
fs
::
create_dir
(
dir
.
path
(
)
.
join
(
"home"
)
)
.
expect
(
"create home"
)
;
std
::
fs
::
create_dir
(
dir
.
path
(
)
.
join
(
"adir"
)
)
.
expect
(
"create adir"
)
;
std
::
fs
::
write
(
dir
.
path
(
)
.
join
(
"afile"
)
,
b""
)
.
expect
(
"create afile"
)
;
dir
}
/// A native expression must reach the system `test`, whose exit code is the answer.
/// Routing it through the shell wrapper instead yields `sh: 0: Illegal option -d`
/// and exit 2 for every one of these.
#
[
test
]
fn
native_expressions_carry_the_test_exit_code
(
)
{
let
dir =
fixture
(
)
;
let
cwd = dir
.
path
(
)
;
assert_eq
!
(
exit_code
(
cwd
,
&
[
"test"
,
"-d"
,
"adir"
]
)
,
0
)
;
assert_eq
!
(
exit_code
(
cwd
,
&
[
"test"
,
"-d"
,
"nodir"
]
)
,
1
)
;
assert_eq
!
(
exit_code
(
cwd
,
&
[
"test"
,
"-f"
,
"afile"
]
)
,
0
)
;
assert_eq
!
(
exit_code
(
cwd
,
&
[
"test"
,
"-f"
,
"nofile"
]
)
,
1
)
;
assert_eq
!
(
exit_code
(
cwd
,
&
[
"test"
,
"-e"
,
"adir"
]
)
,
0
)
;
}
/// `!` negates, so these are the cases the shell wrapper answered backwards
/// rather than loudly: it reported "not a directory" as true for a directory
/// that exists, because `-d` was a missing command and `!` inverted its 127.
#
[
test
]
fn
negated_expressions_are_not_answered_backwards
(
)
{
let
dir =
fixture
(
)
;
let
cwd = dir
.
path
(
)
;
assert_eq
!
(
exit_code
(
cwd
,
&
[
"test"
,
"!"
,
"-d"
,
"adir"
]
)
,
1
)
;
assert_eq
!
(
exit_code
(
cwd
,
&
[
"test"
,
"!"
,
"-d"
,
"nodir"
]
)
,
0
)
;
}
/// `!` and `(` are shell syntax as well as `test` syntax. They mark a native
/// expression only when what they apply to is one, so a command behind `!` still
/// runs under the shell and keeps the exit code negation it had before.
#
[
test
]
fn
bang_before_a_command_still_runs_the_command
(
)
{
let
dir =
fixture
(
)
;
let
cwd = dir
.
path
(
)
;
assert_eq
!
(
exit_code
(
cwd
,
&
[
"test"
,
"!"
,
"false"
]
)
,
0
)
;
assert_eq
!
(
exit_code
(
cwd
,
&
[
"test"
,
"!"
,
"true"
]
)
,
1
)
;
}
/// Argument boundaries survive: the passthrough passes argv through, where the
/// shell wrapper re-split a joined string and saw three arguments here.
#
[
test
]
fn
native_expressions_keep_argument_boundaries
(
)
{
let
dir =
fixture
(
)
;
std
::
fs
::
write
(
dir
.
path
(
)
.
join
(
"a file"
)
,
b""
)
.
expect
(
"create spaced file"
)
;
assert_eq
!
(
exit_code
(
dir
.
path
(
)
,
&
[
"test"
,
"-f"
,
"a file"
]
)
,
0
)
;
}
/// The other direction: a command to run under the test filter still goes to the
/// filter, not to the system `test`, which would reject it as too many arguments.
#
[
test
]
fn
commands_still_reach_the_test_runner
(
)
{
let
dir =
fixture
(
)
;
assert_eq
!
(
exit_code
(
dir
.
path
(
)
,
&
[
"test"
,
"echo"
,
"hello"
]
)
,
0
)
;
}
You can’t perform that action at this time.