tests: add test cases for -P and -p options.
[project/uci.git] / test / tests.d / 090_cli_options
1 test_add_delta() {
2         local new_savedir="$TMP_DIR/new_savedir"
3         local config_delta="$CONFIG_DIR/delta"
4
5         # add normal changes
6         touch "$config_delta"
7         $UCI set delta.sec0=sectype
8         $UCI add_list delta.sec0.li0=0
9
10         # save new changes in "$new_savedir"
11         mkdir -p "$new_savedir"
12         touch "$new_savedir/delta"
13         $UCI -P "$new_savedir" set delta.sec0=sectype
14         $UCI -P "$new_savedir" add_list delta.sec0.li0=1
15
16         assertEquals "delta.sec0='sectype'
17 delta.sec0.li0+='0'" "$($UCI changes)"
18
19         # check combined changes.  order matters here.
20         assertEquals "delta.sec0='sectype'
21 delta.sec0.li0+='1'
22 delta.sec0='sectype'
23 delta.sec0.li0+='0'" "$($UCI -P "$new_savedir" changes)"
24
25         # check CLI_FLAG_NOCOMMIT with -P option.
26         $UCI -P "$new_savedir" commit
27         assertTrue "$?"
28         assertEquals "" "$(cat $config_delta)"
29
30         # check normal commit.
31         $UCI -p "$new_savedir" commit
32         assertTrue "$?"
33         assertSameFile "$REF_DIR/options.delta.result" "$config_delta"
34
35         rm -rf "$new_savedir"
36         rm -f "$config_delta"
37 }
38