From a893f3f5c1f2e7bc553a26634fcf1561f4de5dee Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Fri, 3 Sep 2021 14:31:11 +0200 Subject: [PATCH] Fixed: The tool ojtest now works with the new Node version. --- CommonJS/bin/ojtest | 13 +++++++++++++ Jakefile | 15 +++++++-------- Objective-J/Constants.js | 8 ++++---- Tests/AppKit/CPButtonTest.j | 2 ++ Tests/Foundation/CPArrayPerformanceTest.j | 5 +++-- Tests/Objective-J/CFPropertyListTest.j | 19 +++++++++++-------- package.json | 5 +++-- 7 files changed, 43 insertions(+), 24 deletions(-) create mode 100755 CommonJS/bin/ojtest diff --git a/CommonJS/bin/ojtest b/CommonJS/bin/ojtest new file mode 100755 index 000000000..a73ca8be6 --- /dev/null +++ b/CommonJS/bin/ojtest @@ -0,0 +1,13 @@ +#!/usr/bin/env node + +ObjectiveJ = require("@objj/runtime"); +//CAPPUCCINO = require("@objj/cappuccino"); + +var ojtest = require("@objj/ojtest"); + +// Inject path to the OJTest main Objective-J file into the arguments so it is the file to be executed. +var args = process.argv.slice(); // Copy +args.splice(1, 1, ojtest.pathToOJTest); + +// Compile, load and run it +ObjectiveJ.run(args); diff --git a/Jakefile b/Jakefile index 7f6d52f43..9fddc05cb 100644 --- a/Jakefile +++ b/Jakefile @@ -2,7 +2,7 @@ require("./common.jake"); var fs = require('fs'); var path = require('path'); -var child_process = require("child_process"); +var childProcess = require("child_process"); const term = ObjectiveJ.term; const utilsFile = ObjectiveJ.utils.file; @@ -10,8 +10,8 @@ const utilsFile = ObjectiveJ.utils.file; var subprojects = ["Objective-J", "CommonJS", "Foundation", "AppKit", "Tools"]; task ("build", function() { - child_process.execSync("mkdir -p $CAPP_BUILD", {stdio: 'inherit'}); - child_process.execSync("ln -sf $PWD/node_modules $CAPP_BUILD/node_modules", {stdio: 'inherit'}); + childProcess.execSync("mkdir -p $CAPP_BUILD", {stdio: 'inherit'}); + childProcess.execSync("ln -sf $PWD/node_modules $CAPP_BUILD/node_modules", {stdio: 'inherit'}); }); ["build", "clean", "clobber"].forEach(function(aTaskName) @@ -338,12 +338,11 @@ task("test", ["CommonJS", "test-only"]); task("test-only", function() { - var tests = new FileList('Tests/**/*Test.j'), - cmd = ["ojtest"].concat(tests.items()), - code = OS.system(serializedENV() + " " + cmd.map(OS.enquote).join(" ")); + var tests = new FileList('Tests/**/*Test.j'); + var cmd = ["ojtest"].concat(tests.items()); + var cmdString = cmd.map(utilsFile.enquote).join(" "); - if (code !== 0) - OS.exit(code); + childProcess.execSync(cmdString); }); task("check-missing-imports", function() diff --git a/Objective-J/Constants.js b/Objective-J/Constants.js index a7aee6bad..60839ca4f 100644 --- a/Objective-J/Constants.js +++ b/Objective-J/Constants.js @@ -24,10 +24,10 @@ var undefined; if (typeof window !== "undefined") { - window.setNativeTimeout = window.setTimeout; - window.clearNativeTimeout = window.clearTimeout; - window.setNativeInterval = window.setInterval; - window.clearNativeInterval = window.clearInterval; + window.setNativeTimeout = window.setTimeout || setTimeout; + window.clearNativeTimeout = window.clearTimeout || clearTimeout; + window.setNativeInterval = window.setInterval || setInterval; + window.clearNativeInterval = window.clearInterval || clearInterval; } // Objective-J Constants diff --git a/Tests/AppKit/CPButtonTest.j b/Tests/AppKit/CPButtonTest.j index 73315f103..19c0172fb 100644 --- a/Tests/AppKit/CPButtonTest.j +++ b/Tests/AppKit/CPButtonTest.j @@ -1,6 +1,8 @@ @import @import @import +@import +@import @implementation CPButtonTest : OJTestCase { diff --git a/Tests/Foundation/CPArrayPerformanceTest.j b/Tests/Foundation/CPArrayPerformanceTest.j index 368a1aecb..220a1c81a 100644 --- a/Tests/Foundation/CPArrayPerformanceTest.j +++ b/Tests/Foundation/CPArrayPerformanceTest.j @@ -1,4 +1,5 @@ -var FILE = require("file"); +var fs = require("fs"); +var path = require("path"); @import @import @@ -173,7 +174,7 @@ var ELEMENTS = 100, - (CPArray)makeRandomText { - var the_big_sort = FILE.read(FILE.join(FILE.dirname(module.path), "the_big_sort.txt"), { charset:"UTF-8" }), + var the_big_sort = fs.readFileSync(path.join(path.dirname(__filename), "the_big_sort.txt"), {encoding: 'utf-8'}), words = the_big_sort.split(" ", ELEMENTS), wordcount = words.length, array = []; diff --git a/Tests/Objective-J/CFPropertyListTest.j b/Tests/Objective-J/CFPropertyListTest.j index 94efd4156..780da024f 100644 --- a/Tests/Objective-J/CFPropertyListTest.j +++ b/Tests/Objective-J/CFPropertyListTest.j @@ -1,24 +1,26 @@ @global module -var FILE = require("file"), - FileList = require("jake").FileList; +var fs = require("fs"), + path = require("path"), + FileList = ObjectiveJ.utils.filelist.FileList; @implementation CFPropertyListTest : OJTestCase - (void)testFormatSniffing { - var XMLPropertyLists = new FileList(FILE.join(FILE.dirname(module.path), "PropertyLists", "XML-*.plist")); + debugger; + var XMLPropertyLists = new FileList(path.join(path.dirname(__filename), "PropertyLists", "XML-*.plist")); XMLPropertyLists.forEach(function(/*String*/ aPath) { - [self assert:CFPropertyList.FormatXML_v1_0 equals:CFPropertyList.sniffedFormatOfString(FILE.read(aPath))]; + [self assert:CFPropertyList.FormatXML_v1_0 equals:CFPropertyList.sniffedFormatOfString(fs.readFileSync(aPath).toString())]; }); } - (void)testDateDeserialization { - var path = FILE.join(FILE.dirname(module.path), "PropertyLists/XMLDate.plist"), - object = CFPropertyList.readPropertyListFromFile(path), + var p = path.join(path.dirname(__filename), "PropertyLists/XMLDate.plist"), + object = CFPropertyList.readPropertyListFromFile(p), date = [object objectForKey:@"date"]; [self assert:[CPDate class] equals:[date class]]; @@ -45,7 +47,8 @@ var FILE = require("file"), } } -- (void)testPropertyListFromXMLShouldHandleEmptiestXMLGracefully { +// This is removed as the Node module xmldom/xmldom will print out an error (will not fail) when the xml string is empty +/*- (void)testPropertyListFromXMLShouldHandleEmptiestXMLGracefully { // rhino can't parse empty XML documents if (system.engine !== "rhino") { var XML = "", @@ -53,7 +56,7 @@ var FILE = require("file"), [self assert:object equals:null]; } -} +}*/ - (void)testPropertyListFromXMLShouldParseNiceAndCleanXML { var XML = "Main cib file base nameMainMenu.cibCPBundleNameCopyAndPasteCPBundleVersion1.0CPHumanReadableCopyrightCopyright \u00a9 2013, SlevenBits, Ltd. All rights reserved.", diff --git a/package.json b/package.json index 0726c000e..4d272bffe 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,14 @@ { "name": "@objj/cappuccino", - "version": "1.1.1", + "version": "1.1.3", "devDependencies": { "terser": "^5.7.0", "@objj/cappuccino": "file:." }, "dependencies": { "@objj/jake": "latest", - "@objj/runtime": "latest" + "@objj/runtime": "latest", + "@objj/ojtest": "latest" }, "files": [ "dist",