Changeset 41893 in webkit for trunk/JavaScriptCore/API


Ignore:
Timestamp:
Mar 21, 2009, 6:40:22 PM (16 years ago)
Author:
[email protected]
Message:

Improve testapi by making it report failures in a way we can pick up
from our test scripts.

Reviewed by Mark Rowe.

Location:
trunk/JavaScriptCore/API/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/tests/testapi.c

    r41846 r41893  
    4242
    4343static JSGlobalContextRef context = 0;
    44 
     44static int failed = 0;
    4545static void assertEqualsAsBoolean(JSValueRef value, bool expectedValue)
    4646{
    47     if (JSValueToBoolean(context, value) != expectedValue)
     47    if (JSValueToBoolean(context, value) != expectedValue) {
    4848        fprintf(stderr, "assertEqualsAsBoolean failed: %p, %d\n", value, expectedValue);
     49        failed = 1;
     50    }
    4951}
    5052
     
    5658    // causing a build break with -Wshorten-64-to-32 enabled.  The issue is known by the appropriate team.
    5759    // After that's resolved, we can remove these casts
    58     if (number != expectedValue && !(isnan((float)number) && isnan((float)expectedValue)))
     60    if (number != expectedValue && !(isnan((float)number) && isnan((float)expectedValue))) {
    5961        fprintf(stderr, "assertEqualsAsNumber failed: %p, %lf\n", value, expectedValue);
     62        failed = 1;
     63    }
    6064}
    6165
     
    6973   
    7074    unsigned i;
    71     for (i = 0; jsBuffer[i]; i++)
    72         if (jsBuffer[i] != expectedValue[i])
     75    for (i = 0; jsBuffer[i]; i++) {
     76        if (jsBuffer[i] != expectedValue[i]) {
    7377            fprintf(stderr, "assertEqualsAsUTF8String failed at character %d: %c(%d) != %c(%d)\n", i, jsBuffer[i], jsBuffer[i], expectedValue[i], expectedValue[i]);
    74        
    75     if (jsSize < strlen(jsBuffer) + 1)
     78            failed = 1;
     79        }
     80    }
     81
     82    if (jsSize < strlen(jsBuffer) + 1) {
    7683        fprintf(stderr, "assertEqualsAsUTF8String failed: jsSize was too small\n");
     84        failed = 1;
     85    }
    7786
    7887    free(jsBuffer);
     
    95104    CFRelease(expectedValueAsCFString);
    96105
    97     if (memcmp(jsBuffer, cfBuffer, cfLength * sizeof(UniChar)) != 0)
     106    if (memcmp(jsBuffer, cfBuffer, cfLength * sizeof(UniChar)) != 0) {
    98107        fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsBuffer != cfBuffer\n");
    99    
    100     if (jsLength != (size_t)cfLength)
     108        failed = 1;
     109    }
     110   
     111    if (jsLength != (size_t)cfLength) {
    101112        fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength);
    102    
     113        failed = 1;
     114    }
     115
    103116    free(cfBuffer);
    104117    JSStringRelease(valueAsString);
     
    847860   
    848861    string = JSValueToStringCopy(context, function, NULL);
    849     assertEqualsAsUTF8String(JSValueMakeString(context, string), "function foo(foo) {return foo;}");
     862    assertEqualsAsUTF8String(JSValueMakeString(context, string), "function foo(foo) {\nreturn foo;\n}");
    850863    JSStringRelease(string);
    851864
     
    10081021    printf("PASS: Infinite prototype chain does not occur.\n");
    10091022
     1023    if (failed) {
     1024        printf("FAIL: Some tests failed.\n");
     1025        return 1;
     1026    }
     1027
    10101028    printf("PASS: Program exited normally.\n");
    10111029    return 0;
  • trunk/JavaScriptCore/API/tests/testapi.js

    r35900 r41893  
    2323 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
     25var failed = false;
     26function pass(msg)
     27{
     28    print("PASS: " + msg, "green");
     29}
     30
     31function fail(msg)
     32{
     33    print("FAIL: " + msg, "red");
     34    failed = true;
     35}
    2536
    2637function shouldBe(a, b)
     
    3445   
    3546    if (evalA == b || isNaN(evalA) && typeof evalA == 'number' && isNaN(b) && typeof b == 'number')
    36         print("PASS: " + a + " should be " + b + " and is.", "green");
     47        pass(a + " should be " + b + " and is.");
    3748    else
    38         print("__FAIL__: " + a + " should be " + b + " but instead is " + evalA + ".", "red");
     49        fail(a + " should be " + b + " but instead is " + evalA + ".");
    3950}
    4051
    4152function shouldThrow(a)
    4253{
    43     var result = "__FAIL__: " + a + " did not throw an exception.";
    44    
    4554    var evalA;
    4655    try {
    4756        eval(a);
    4857    } catch(e) {
    49         result = "PASS: " + a + " threw: " + e;
     58        pass(a + " threw: " + e);
     59        return;
    5060    }
    51    
    52     print(result);
     61
     62    fail(a + " did not throw an exception.");
    5363}
    5464
     
    8393        foundRegularType = true;
    8494}
    85 print(foundMyPropertyName
    86       ? "PASS: MyObject.myPropertyName was enumerated"
    87       : "__FAIL__: MyObject.myPropertyName was not enumerated");
    88 print(foundRegularType
    89       ? "PASS: MyObject.regularType was enumerated"
    90       : "__FAIL__: MyObject.regularType was not enumerated");
     95
     96if (foundMyPropertyName)
     97    pass("MyObject.myPropertyName was enumerated");
     98else
     99    fail("MyObject.myPropertyName was not enumerated");
     100
     101if (foundRegularType)
     102    pass("MyObject.regularType was enumerated");
     103else
     104    fail("MyObject.regularType was not enumerated");
    91105
    92106myObject = new MyObject();
     
    131145shouldBe("derived.derivedOnly = 0", 2)
    132146shouldBe("derived.protoDup = 0", 2);
     147
     148if (failed)
     149    throw "Some tests failed";
     150
Note: See TracChangeset for help on using the changeset viewer.