Changeset 1728 for trunk/src/kmk


Ignore:
Timestamp:
Sep 5, 2008, 5:27:06 AM (17 years ago)
Author:
bird
Message:

kmk/expreval/ifcond: fixed the target operator and string parsing; wrote the remaining tests

Location:
trunk/src/kmk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/expreval.c

    r1726 r1728  
    903903            pFile = NULL;
    904904    }
    905     if (pFile)
     905    if (!pFile)
    906906#endif
    907907    {
     
    18281828         * push it onto the stack.
    18291829         */
    1830         const char *pszStart = psz;
     1830        const char *pszStart;
    18311831
    18321832        rc = kExprRet_Ok;
    18331833        if (*psz == '"')
    18341834        {
    1835             pszStart++;
     1835            pszStart = ++psz;
    18361836            while (*psz && *psz != '"')
    18371837                psz++;
    18381838            expr_var_init_substring(&pThis->aVars[++pThis->iVar], pszStart, psz - pszStart, kExprVar_QuotedString);
     1839            if (*psz)
     1840                psz++;
    18391841        }
    18401842        else if (*psz == '\'')
    18411843        {
    1842             pszStart++;
     1844            pszStart = ++psz;
    18431845            while (*psz && *psz != '\'')
    18441846                psz++;
    18451847            expr_var_init_substring(&pThis->aVars[++pThis->iVar], pszStart, psz - pszStart, kExprVar_QuotedSimpleString);
     1848            if (*psz)
     1849                psz++;
    18461850        }
    18471851        else
     
    18521856            char    ch;
    18531857
     1858            pszStart = psz;
    18541859            while ((ch = *psz) != '\0')
    18551860            {
  • trunk/src/kmk/testcase-ifcond.kmk

    r1727 r1728  
    2929include $(KBUILD_PATH)/header.kmk
    3030
    31 ifeq (1,0)
    32 #
    33 # Some very basic tests.
    34 #
     31#
     32# Note! The testcase are ordered by ascending operator precedence
     33#       with the exception of equal and not-equal because these
     34#       are kind of useful for performing tests on non-logical ops.
     35#
     36
     37#
     38# Parenthesis
     39#
     40$(warning unary operators: ( and ) )
     41if (1)
     42else
     43$(error )
     44endif
     45
     46if ((((1))))
     47else
     48$(error )
     49endif
     50
     51
     52#
     53# Equal and Not Equal w/ some fundamental bits thrown in.
     54#
     55$(warning binary operators: == and != )
     56
     57if 1 == 1
     58else
     59$(error )
     60endif
     61
     62if 2 == 3
     63$(error )
     64else
     65endif
     66
     67if 2 != 3
     68else
     69$(error )
     70endif
     71
     72if a != b
     73else
     74$(error )
     75endif
     76
     77if asdf == asdf
     78else
     79$(error )
     80endif
     81
     82if "asdf" == asdf
     83else
     84$(error )
     85endif
     86
     87if 'asdf' == asdf
     88else
     89$(error )
     90endif
     91
     92if 'asdf' == "asdf"
     93else
     94$(error )
     95endif
     96
     97if 'asdf' == 'asdf'
     98else
     99$(error )
     100endif
     101
     102if "asdf" == "asdf"
     103else
     104$(error )
     105endif
     106
     107if 0x1 == 1
     108else
     109$(error )
     110endif
     111
     112if 0xfff == 4095
     113else
     114$(error )
     115endif
     116
     117if 0xfff == 4095
     118else
     119$(error )
     120endif
     121
     122if 0d10 == 10
     123else
     124$(error )
     125endif
     126
     127if 0d10 == 10
     128else
     129$(error )
     130endif
     131
     132if 0xa == 012
     133else
     134$(error )
     135endif
     136
     137if 0b1110 == 016
     138else
     139$(error )
     140endif
     141
     142
     143#
     144# Logical OR
     145#
     146$(warning binary operator: || )
    35147if 1
    36 $(warning works)
    37148else
    38149$(error busted)
     
    40151
    41152if 1 || 1
    42 $(warning works)
    43153else
    44154$(error )
     
    48158$(error )
    49159else
    50 $(warning works)
    51160endif
    52161
    53162if 1 || 0
    54 $(warning works)
    55163else
    56164$(error )
     
    58166
    59167if 0 || 1
    60 $(warning works)
    61168else
    62169$(error )
     
    66173$(error )
    67174else
    68 $(warning works)
    69175endif
    70176
    71177if 0 || 0 || 0 || 1 || 0 || 0 || 0
    72 $(warning works)
    73 else
    74 $(error )
    75 endif
    76 
    77 if 0 && 1
    78 $(error )
    79 else
    80 $(warning works)
    81 endif
    82 
    83 if 0 || 1 && 1
    84 $(warning works)
    85 else
    86 $(error )
    87 endif
    88 endif # all
    89 
    90 #
    91 # Parenthesis
    92 #
    93 if (1)
    94 $(warning works)
    95 else
    96 $(error )
    97 endif
    98 
    99 if ((((1))))
    100 $(warning works)
    101 else
    102 $(error )
    103 endif
    104 
    105 
    106 #
    107 # Equal and Not Equal.
    108 #
    109 if 1 == 1
    110 $(warning works)
    111 else
    112 $(error )
    113 endif
    114 
    115 if 2 == 3
    116 $(error )
    117 else
    118 $(warning works)
    119 endif
    120 
    121 if 2 != 3
    122 $(warning works)
    123 else
    124 $(error )
    125 endif
    126 
    127 
    128 #
    129 # XOR
    130 #
     178else
     179$(error )
     180endif
     181
     182if "asdf" || 0
     183else
     184$(error )
     185endif
     186
     187if 0 || "asdf"
     188else
     189$(error )
     190endif
     191
     192if 'asdf' || 0
     193else
     194$(error )
     195endif
     196
     197if "" || 0
     198$(error )
     199endif
     200if "" || 1
     201else
     202$(error )
     203endif
     204if '' || 0
     205$(error )
     206endif
     207if '' || 1
     208else
     209$(error )
     210endif
     211
     212if "" || ''
     213$(error )
     214endif
     215if "1" || ''
     216else
     217$(error )
     218endif
     219if "1" || '1'
     220else
     221$(error )
     222endif
     223if "" || '1'
     224else
     225$(error )
     226endif
     227
     228
     229#
     230# Logical AND
     231#
     232$(warning binary operator: && )
     233if 1 && 1
     234else
     235$(error )
     236endif
     237if 1 && 0
     238$(error )
     239endif
     240if 1234 && 0
     241$(error )
     242endif
     243if 123434 && 0 && 123435 && 1
     244$(error )
     245endif
     246
     247if "" && 1
     248$(error )
     249endif
     250if ("asdf" && 1) != 1
     251$(error )
     252endif
     253if "1" && 'asdf'
     254else
     255$(error )
     256endif
     257if "1" && 'asdf' && 0
     258$(error )
     259endif
     260
     261if 0 || 1 && 0
     262$(error )
     263endif
     264
     265
     266#
     267# Bitwise OR
     268#
     269$(warning binary operator: | )
     270if 1 | 0
     271else
     272$(error )
     273endif
     274if 1 | 1
     275else
     276$(error )
     277endif
     278if 11234 | 343423
     279else
     280$(error )
     281endif
     282if (1|2)!=3
     283$(error )
     284endif
     285if 1|2 != 3
     286else
     287$(error )
     288endif
     289if (1|2|4|8)!=0xf
     290$(error )
     291endif
     292
     293
     294#
     295# Bitwise XOR
     296#
     297$(warning binary operator: ^ )
    131298if 1 ^ 1
    132299$(error )
    133 else
    134 $(warning works)
    135 endif
    136 
    137 if 2 ^ 1 == 3
    138 $(warning works)
    139 else
    140 $(error )
    141 endif
    142 
    143 if 7 == 2 ^ 1 ^ 4
    144 $(warning works)
    145 else
     300endif
     301
     302if (2 ^ 1) != 3
     303$(error )
     304endif
     305
     306if 7 != (2 ^ 1 ^ 4)
     307$(error )
     308endif
     309
     310if (2 ^ 1 | 2) != 3
     311$(error )
     312endif
     313
     314
     315#
     316# Bitwise AND
     317#
     318$(warning binary operator: & )
     319if (4097 & 1) != 1
     320$(error )
     321endif
     322if (0xfff & 0x0f0) != 0xf0
     323$(error )
     324endif
     325if (0x1e3 & 0x100 | 3) != 0x103
     326$(error )
     327endif
     328
     329
     330#
     331# Greater than
     332#
     333$(warning binary operator: > )
     334if 1 > 0
     335else
     336$(error )
     337endif
     338
     339if 1024 > 1023
     340else
     341$(error )
     342endif
     343
     344if 999 > 1023
     345$(error )
     346endif
     347
     348if (5 > 4 | 2) != 3
     349$(error )
     350endif
     351
     352if (1 & 8 > 4) != 1
     353$(error )
     354endif
     355
     356if (8 > 4 ^ 16) != 17
     357$(error )
     358endif
     359
     360if "b" > 'a'
     361else
     362$(error )
     363endif
     364if "abcdef" > 'ffdas'
     365$(error )
     366endif
     367if abcdef > ffdas
     368$(error )
     369endif
     370
     371
     372#
     373# Greater or equal than
     374#
     375$(warning binary operator: >= )
     376if 20 > 0
     377else
     378$(error )
     379endif
     380
     381if 20 >= 20
     382else
     383$(error )
     384endif
     385
     386if 19 >= 20
     387$(error )
     388endif
     389
     390if (1 & 8 >= 4) != 1
     391$(error )
     392endif
     393
     394if "x" >= 'x'
     395else
     396$(error )
     397endif
     398if "abdc" >= 'abcd'
     399else
     400$(error )
     401endif
     402if "ffdaaa" >= 'ffdasd'
     403$(error )
     404endif
     405if asdf >= asdf
     406else
     407$(error )
     408endif
     409
     410
     411#
     412# Less than
     413#
     414if 1 < 1
     415$(error )
     416endif
     417if -123 < -134
     418$(error )
     419endif
     420if 123 <= 7777
     421else
     422$(error )
     423endif
     424
     425if "b" < 'a'
     426$(error )
     427endif
     428if b < a
     429$(error )
     430endif
     431if 'foobar' < 'a$'
     432$(error )
     433endif
     434if hhhh < ggggg
     435$(error )
     436endif
     437if qwerty < qwerty0
     438else
     439$(error )
     440endif
     441
     442
     443#
     444# Less or equal than
     445#
     446$(warning binary operator: >> )
     447if 1 <= 0
     448$(error )
     449endif
     450if 1 <= 1
     451else
     452$(error )
     453endif
     454if 123 <= 123 != 1
     455$(error )
     456endif
     457if 560 <= 456
     458$(error )
     459endif
     460
     461if "a" <= 'a'
     462else
     463$(error )
     464endif
     465if "abcdef" <= 'abcdef'
     466else
     467$(error )
     468endif
     469if q12345z6 <= q12345z
     470$(error )
     471endif
     472if QWERTY <= ABCDE
     473$(error )
     474endif
     475
     476
     477#
     478# Shift right
     479#
     480$(warning binary operator: >> )
     481if 1 >> 0 != 1
     482$(error )
     483endif
     484if 1024 >> 2 != 256
     485$(error )
     486endif
     487if 102435 >> 4 > 1234 != 1
     488$(error )
     489endif
     490
     491
     492#
     493# Shift left
     494#
     495$(warning binary operator: << )
     496if 1 << 0 != 1
     497$(error )
     498endif
     499if 1 << 1 != 2
     500$(error )
     501endif
     502if 1 << 4 != 16
     503$(error )
     504endif
     505if 1 << 10 != 1024
     506$(error )
     507endif
     508if 34 << 10 != 0x8800
     509$(error )
     510endif
     511if 1099511627776 << 21 != 2305843009213693952
     512$(error )
     513endif
     514if 1 << 61 != 2305843009213693952
     515$(error )
     516endif
     517
     518if 2 << 60 > 123434323 != 1
     519$(error )
     520endif
     521
     522
     523#
     524# Subtraction
     525#
     526$(warning binary operator: - )
     527if 1-1 != 0
     528$(error )
     529endif
     530if 1023-511 != 512
     531$(error )
     532endif
     533if 4 - 3 << 3 != 8
     534$(error )
     535endif
     536
     537
     538#
     539# Addition
     540#
     541$(warning binary operator: + )
     542if 1+1 != 2
     543$(error )
     544endif
     545if 1234+1000 != 2234
     546$(error )
     547endif
     548if 2 + 2 << 4 != 64
     549$(error )
     550endif
     551
     552
     553#
     554# Modulus
     555#
     556$(warning binary operator: % )
     557if 0%2 != 0
     558$(error )
     559endif
     560if 10%7 != 3
     561$(error )
     562endif
     563if 10 + 100%70 - 3 != 37
     564$(error )
     565endif
     566
     567
     568#
     569# Division
     570#
     571$(warning binary operator: / )
     572if 0/1 != 0
     573$(error )
     574endif
     575if 1000/2 != 500
     576$(error )
     577endif
     578if 1000/2 + 4 != 504
     579$(error )
     580endif
     581if 5 + 1000/4 != 255
     582$(error )
     583endif
     584
     585
     586#
     587# Multiplication
     588#
     589$(warning binary operator: * )
     590if 1*1 != 1
     591$(error )
     592endif
     593if 10*10 != 100
     594$(error )
     595endif
     596if 1024*64 != 65536
     597$(error )
     598endif
     599if 10*10 - 10 != 90
     600$(error )
     601endif
     602if 1000 - 10*10 != 900
    146603$(error )
    147604endif
     
    151608# Logical NOT
    152609#
     610$(warning unary operator: ! )
    153611if !1
    154612$(error )
    155 else
    156 $(warning works)
    157613endif
    158614
    159615if !42 == 0
    160 $(warning works)
    161616else
    162617$(error )
     
    164619
    165620if !0 == 1
    166 $(warning works)
    167621else
    168622$(error )
     
    170624
    171625if !!0 == 0
    172 $(warning works)
    173 else
    174 $(error )
    175 endif
    176 
    177 
    178 #
    179 # Greater than
    180 #
    181 if 1 > 0
    182 $(warning works)
    183 else
    184 $(error )
    185 endif
    186 
    187 if 1024 > 1023
    188 $(warning works)
    189 else
    190 $(error )
    191 endif
    192 
    193 if 999 > 1023
    194 $(error )
    195 else
    196 $(warning works)
    197 endif
    198 
    199 
    200 #
    201 # Greater or equal than
    202 #
    203 if 20 > 0
    204 $(warning works)
    205 else
    206 $(error )
    207 endif
    208 
    209 if 20 >= 20
    210 $(warning works)
    211 else
    212 $(error )
    213 endif
    214 
    215 if 19 >= 20
    216 $(error )
    217 else
    218 $(warning works)
    219 endif
    220 
    221 
    222 #
    223 # target()
    224 #
    225 if 0
     626else
     627$(error )
     628endif
     629
     630if !0 * 123 != 123
     631$(error )
     632endif
     633if !!!0 * 512 != 512
     634$(error )
     635endif
     636
     637
     638#
     639# Bitwise NOT
     640#
     641$(warning unary operator: ~ )
     642if ~0xfff != 0xfffffffffffff000
     643$(error )
     644endif
     645
     646
     647#
     648# Pluss
     649#
     650$(warning unary operator: + )
     651if +2 != 2
     652$(error )
     653endif
     654if 1++++++++++++2134 != 2135
     655$(error )
     656endif
     657
     658
     659#
     660# Minus (negation)
     661#
     662$(warning unary operator: - )
     663if --2 != 2
     664$(error )
     665endif
     666
     667if 1 - -2 != 3
     668$(error )
     669endif
     670
     671
     672#
     673# target
     674#
    226675trg_deps_only: foobar
    227676trg_with_cmds: foobar
    228677        echo $@
    229678
     679$(warning unary operator: target ) # This flushes stuff in read.c
     680
    230681if target trg_with_cmds
    231 $(warning works)
    232 else
    233 $(error target)
    234 endif
    235 
    236 if target trg_deps_only
    237 $(error target)
    238 else
    239 $(warning works)
    240 endif
    241 
    242 if target foobar
    243 $(error target)
    244 else
    245 $(warning works)
    246 endif
    247 endif
    248 
    249 
    250 #
    251 # defined()
    252 #
     682else
     683$(error target trg_with_cmds)
     684endif
     685if target(trg_deps_only)
     686$(error target trg_deps_only)
     687endif
     688if target ( foobar )
     689$(error target foobar)
     690endif
     691
     692
     693#
     694# defined
     695#
     696$(warning unary operator: defined )
    253697var_defined := 1
    254698var_not_defined :=
    255699
    256700if defined var_defined
    257 $(warning works)
    258 else
    259 $(error )
    260 endif
    261 
     701else
     702$(error )
     703endif
    262704if defined(var_defined)
    263 $(warning works)
    264 else
    265 $(error )
    266 endif
    267 
     705else
     706$(error )
     707endif
    268708if defined (var_defined)
    269 $(warning works)
    270 else
    271 $(error )
    272 endif
    273 
     709else
     710$(error )
     711endif
     712if !defined(var_defined)
     713$(error )
     714endif
    274715if defined (var_not_defined)
    275716$(error )
    276 else
    277 $(warning works)
    278 endif
     717endif
     718
     719
     720#
     721# bool
     722#
     723
     724
     725#
     726# string
     727#
     728
    279729
    280730
     
    282732# Quick check of $(if-expr ) and $(expr ).
    283733#
     734$(warning $$(if-expr ,,) )
    284735ifeq ($(if-expr 0 || 2,42,500),42)
    285 $(warning if-expr test 1 succeeded)
    286 else
    287 $(error )
    288 endif
    289 
     736else
     737$(error )
     738endif
    290739ifeq ($(if-expr 5+3 == 231,42,500),42)
    291740$(error )
    292 else
    293 $(warning if-expr test 2 succeeded)
    294 endif
    295 
     741endif
     742
     743$(warning $$(expr ) ) 
    296744ifeq ($(expr 5+3),8)
    297 $(warning expr test 1 succeeded)
    298745else
    299746$(error expr:$(expr 5+3) expected 8)
    300747endif
    301 
    302748ifeq ($(expr 25*25),625)
    303 $(warning expr test 2 succeeded)
    304749else
    305750$(error expr:$(expr 25*25) expected 625)
    306751endif
    307 
    308752ifeq ($(expr 100/3),3)
    309753$(error )
    310 else
    311 $(warning expr test 3 succeeded)
    312754endif
    313755
Note: See TracChangeset for help on using the changeset viewer.