1####################################################### 2# 3# Test readstringarrayidx(), introduce a non-parsed comment 4# 5# The 4xx tests are all related, and 400-419 are the readstringarray tests, 6# 420-439 the same for readstringarrayidx, 440-459 parsestringarray, and 7# 460-479 parsestringarrayidx 8# 9####################################################### 10 11body common control 12{ 13 inputs => { "../../default.cf.sub" }; 14 bundlesequence => { "g", default("$(this.promise_filename)") }; 15 version => "1.0"; 16} 17 18bundle common g 19{ 20 vars: 21 "testfile" string => "/tmp/TEST.cfengine"; 22} 23 24####################################################### 25 26bundle agent init 27{ 28 files: 29 "$(G.testfile)" 30 delete => init_delete; 31 32 "$(G.testfile)" 33 create => "true", 34 edit_line => init_fill_in; 35} 36 37bundle edit_line init_fill_in 38{ 39 insert_lines: 40 41 "0:1:2 42# Not parsed as a comment 43this:is:a:test 441:2:3"; 45 46} 47 48body delete init_delete 49{ 50 dirlinks => "delete"; 51 rmdirs => "true"; 52} 53 54####################################################### 55 56bundle agent test 57{ 58 vars: 59 "cnt" int => readstringarrayidx("ary", "$(G.testfile)","NoComment",":",10,1000); 60 "num" int => "4"; 61} 62 63####################################################### 64 65bundle agent check 66{ 67 vars: 68 "idx" slist => getindices("test.ary"); 69 70 classes: 71 "good" and => { 72 strcmp("$(test.num)", "$(test.cnt)"), 73 74 strcmp("$(test.ary[0][0])", "0"), 75 strcmp("$(test.ary[0][1])", "1"), 76 strcmp("$(test.ary[0][2])", "2"), 77 78 strcmp("$(test.ary[1][0])", "# Not parsed as a comment"), 79 80 strcmp("$(test.ary[2][0])", "this"), 81 strcmp("$(test.ary[2][1])", "is"), 82 strcmp("$(test.ary[2][2])", "a"), 83 strcmp("$(test.ary[2][3])", "test"), 84 85 strcmp("$(test.ary[3][0])", "1"), 86 strcmp("$(test.ary[3][1])", "2"), 87 strcmp("$(test.ary[3][2])", "3"), 88 }; 89 90 # Make sure there are no trailing elements 91 "bad" or => { 92 isvariable("test.ary[0][3]"), 93 isvariable("test.ary[1][1]"), 94 isvariable("test.ary[2][4]"), 95 isvariable("test.ary[3][3]"), 96 }; 97 98 "ok" expression => "good&!bad"; 99 100 reports: 101 DEBUG:: 102 "expected $(test.num) entries, saw $(test.cnt)"; 103 104 "saw array indices '$(idx)'"; 105 106 "expected test.ary[0][0] = '0', saw '$(test.ary[0][0])'"; 107 "expected test.ary[0][1] = '1', saw '$(test.ary[0][1])'"; 108 "expected test.ary[0][2] = '2', saw '$(test.ary[0][2])'"; 109 110 "expected test.ary[this][0] = 'this', saw '$(test.ary[this][0])'"; 111 "expected test.ary[this][1] = 'is', saw '$(test.ary[this][1])'"; 112 "expected test.ary[this][2] = 'a', saw '$(test.ary[this][2])'"; 113 "expected test.ary[this][3] = 'test', saw '$(test.ary[this][3])'"; 114 115 "expected test.ary[1][0] = '1', saw '$(test.ary[1][0])'"; 116 "expected test.ary[1][1] = '2', saw '$(test.ary[1][1])'"; 117 "expected test.ary[1][2] = '3', saw '$(test.ary[1][2])'"; 118 119 ok:: 120 "$(this.promise_filename) Pass"; 121 122 !ok:: 123 "$(this.promise_filename) FAIL"; 124} 125