FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cli/tests/ProjectMutationTests.cpp at main · vixcpp/cli · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
vixcpp
/
cli
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
10
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cli
/
tests
/
ProjectMutationTests.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
15 lines (15 loc) · 1.74 KB
Breadcrumbs
cli
/
tests
/
ProjectMutationTests.cpp
Copy path
File metadata and controls
15 lines (15 loc) · 1.74 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
#
include
<
vix/cli/util/ProjectMutation.hpp
>
#
include
<
cassert
>
#
include
<
filesystem
>
#
include
<
fstream
>
namespace
fs
=
std::filesystem;
static
std::string
read
(
const
fs::path&p){std::ifstream
in
(p,std::ios::binary);
return
std::string
((std::istreambuf_iterator<
char
>(in)),{});}
int
main
(){
const
fs::path root=
fs::temp_directory_path
()/
"
vix mutation test
"
;
fs::remove_all
(root);
fs::create_directories
(root);
std::ofstream
(root/
"
a
"
)<<
"
old
\n
"
;std::string e;
{vix::cli::util::ProjectMutationTransaction
t
(root);
assert
(t.
stage_write
(root/
"
a
"
,
"
new
"
,e));
assert
(t.
stage_write
(root/
"
b
"
,
"
two
"
,e));
assert
(t.
commit
(e));
assert
(
read
(root/
"
a
"
)==
"
new
"
&&
read
(root/
"
b
"
)==
"
two
"
);}
{vix::cli::util::ProjectMutationTransaction
t
(root);
assert
(t.
stage_write
(root/
"
a
"
,
"
bad
"
,e));
assert
(t.
stage_write
(root/
"
c
"
,
"
three
"
,e));t.
fail_publish_at_for_test
(
1
);
assert
(!t.
commit
(e));
assert
(
read
(root/
"
a
"
)==
"
new
"
&&!
fs::exists
(root/
"
c
"
));}
{vix::cli::util::ProjectMutationTransaction
t
(root);
assert
(t.
stage_delete
(root/
"
b
"
,e));t.
rollback
();
assert
(
read
(root/
"
b
"
)==
"
two
"
);}
{
std::ofstream
(root/
"
unrelated
"
,std::ios::binary)<<
"
keep
"
;vix::cli::util::ProjectMutationTransaction
t
(root);
assert
(t.
stage_write
(root/
"
a
"
,
"
interrupted
"
,e));
assert
(t.
stage_write
(root/
"
missing
"
,
"
created
"
,e));t.
abandon_publish_at_for_test
(
1
);
assert
(!t.
commit
(e));
assert
(
read
(root/
"
a
"
)==
"
interrupted
"
);
assert
(!
fs::exists
(root/
"
missing
"
));}
{vix::cli::util::ProjectMutationLock
recovery
(root);
assert
(recovery.
acquired
());
assert
(
read
(root/
"
a
"
)==
"
new
"
);
assert
(!
fs::exists
(root/
"
missing
"
));
assert
(
read
(root/
"
unrelated
"
)==
"
keep
"
);}
{vix::cli::util::ProjectMutationLock
a
(root);
assert
(a.
acquired
());vix::cli::util::ProjectMutationLock
b
(root);
assert
(!b.
acquired
());}
{vix::cli::util::ProjectMutationLock
b
(root);
assert
(b.
acquired
());}
fs::remove_all
(root);}
Back
|
FazBrowse Home
|
New Git URL