Skip to content

Commit 2e6beb2

Browse files
author
Will
committed
watcher/cli: fix json for assoc
1 parent 55abfa7 commit 2e6beb2

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ if(NOT WIN32 AND NOT IS_CC_MSVC)
7575
"-fno-rtti"
7676
"-fstrict-enums"
7777
"-fstrict-overflow")
78-
if(NOT IS_CC_APPLECLANG)
78+
if(NOT IS_CC_APPLECLANG AND NOT ANDROID)
7979
set(COMPILE_OPTIONS
8080
"${COMPILE_OPTIONS}"
8181
"-fexpensive-optimizations"

src/wtr/watcher/main.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,26 @@ struct Args {
9494

9595
auto json(event const& e) -> string
9696
{
97-
auto s = [](auto a)
98-
{ return '"' + to<string>(a) + '"'; };
97+
auto s = [](auto a) { return to<string>(a); };
98+
auto q = [&](auto a) { return '"' + s(a) + '"'; };
9999
return
100-
"{\"path_type\":" + s(e.path_type)
101-
+ ",\"path_name\":" + s(e.path_name)
102-
+ ",\"effect_type\":" + s(e.effect_type)
103-
+ ",\"effect_time\":" + s(e.effect_time)
104-
+ (e.associated ? "," + json(*e.associated) : "")
105-
+ "}"
106-
;
100+
"{\"path_type\":" + q(e.path_type)
101+
+ ",\"path_name\":" + q(e.path_name)
102+
+ ",\"effect_type\":" + q(e.effect_type)
103+
+ ",\"effect_time\":" + s(e.effect_time)
104+
+ ",\"associated\":" + ( e.associated
105+
? json(*e.associated)
106+
: "null" )
107+
+ "}"
108+
;
107109
}
108110

109111
/* Watch a path for some time.
110112
Or watch a path forever.
111113
Show what happens, or show help. */
112114
int main(int const argc, char const* const* const argv)
113115
{
114-
auto cb = [](event ev) { cout << json(ev) << endl; };
116+
auto cb = [](event const& ev) { cout << json(ev) << endl; };
115117
auto args = Args::try_parse(argc, argv);
116118
return ! args.has_value() ? (cerr << Args::help, 1)
117119
: args->is_help ? (cout << Args::help, 0)

tool/test/.ctx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ show-output() {
4747
, path_name: .path_name
4848
, effect_type: .effect_type
4949
, effect_time: .effect_time
50+
, associated: .associated
5051
}' \
51-
| jq --slurp --sort-keys
52+
| jq --slurp -S
5253
}
5354
export -f show-output
5455

@@ -66,10 +67,11 @@ check-result() {
6667
[[ -z "$1" || -z "$2" ]] && return 1
6768
expect=$1
6869
actual=$2
69-
if diff <(echo "$expect") <(echo "$actual") &> /dev/null
70+
lhs() { echo "$expect" | jq -S; }
71+
rhs() { echo "$actual" | jq -S | sed '/"associated": null,/d'; }
72+
if diff <(lhs) <(rhs) &> /dev/null
7073
then echo ':) ok'
71-
else echo 'oops :('
72-
diff --side-by-side <(echo "$expect") <(echo "$actual")
74+
else echo 'oops :(' && diff --side-by-side <(lhs) <(rhs)
7375
fi
7476
}
7577
export -f check-result

tool/test/rename-file-accuracy

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ ec=0
1818
"path_type": "file"
1919
},
2020
{
21+
"effect_type": "rename",
22+
"path_name": "d/a",
23+
"path_type": "file",
2124
"associated": {
2225
"effect_type": "rename",
2326
"path_name": "d/b",
2427
"path_type": "file"
25-
},
26-
"effect_type": "rename",
27-
"path_name": "d/a",
28-
"path_type": "file"
28+
}
2929
},
3030
{
3131
"effect_type": "destroy",
@@ -71,14 +71,14 @@ ec=$((ec + $?))
7171
"path_type": "file"
7272
},
7373
{
74+
"effect_type": "rename",
75+
"path_name": "d/a",
76+
"path_type": "file",
7477
"associated": {
7578
"effect_type": "rename",
7679
"path_name": "d/b",
7780
"path_type": "file"
78-
},
79-
"effect_type": "rename",
80-
"path_name": "d/a",
81-
"path_type": "file"
81+
}
8282
},
8383
{
8484
"effect_type": "destroy",

0 commit comments

Comments
 (0)