From eaf5b23730b5737d20dad31e08c4809af930eaef Mon Sep 17 00:00:00 2001 From: Philipp Kewisch Date: Mon, 15 Apr 2024 10:28:20 +0200 Subject: [PATCH] Update ICALTester to make it useable again --- eslint.config.js | 3 +- tools/ICALTester/Makefile | 14 +++++--- tools/ICALTester/compare.js | 38 ++++++++++---------- tools/ICALTester/lib/ICALTester.js | 57 +++++++++++++++--------------- 4 files changed, 59 insertions(+), 53 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 2b9e762f..5d603b2a 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -9,6 +9,7 @@ export default [ "!lib/ical/**/*.{js,cjs}", "!test/**/*.{js,cjs}", "!tools/scriptutils.js", + "!tools/ICALTester/**/*.js", "!eslint.config.js", "!rollup.config.js", "!karma.conf.cjs" @@ -360,7 +361,7 @@ export default [ } }, { - files: ["tools/scriptutils.js", "test/support/perfReporter.cjs", "karma.conf.cjs"], + files: ["tools/scriptutils.js", "test/support/perfReporter.cjs", "karma.conf.cjs", "tools/ICALTester/**/*.js"], languageOptions: { globals: globals.node } diff --git a/tools/ICALTester/Makefile b/tools/ICALTester/Makefile index 04e9919f..ed45a2e5 100644 --- a/tools/ICALTester/Makefile +++ b/tools/ICALTester/Makefile @@ -5,15 +5,17 @@ LIBICAL_BASE ?= $(CURDIR)/../libical LIBICAL_BUILD = $(LIBICAL_BASE)/build -LDFLAGS = -L $(LIBICAL_BUILD)/lib -lical +LDFLAGS = $(LIBICAL_BUILD)/lib/libical.a CFLAGS = -I $(LIBICAL_BUILD)/src -g +LIBICAL_DEFINES = -DSTATIC_ONLY=True -DENABLE_GTK_DOC=OFF + LIBICAL_SOURCES = support/libical-recur.c LIBICAL_PROG = support/libical-recur all: libical -libical: $(LIBICAL_BUILD) +libical: $(LIBICAL_BUILD)/lib/libical.a $(CC) -o $(LIBICAL_PROG) $(LIBICAL_SOURCES) $(LDFLAGS) $(CFLAGS) clean: @@ -22,7 +24,9 @@ clean: run: node index.js -$(LIBICAL_BUILD): +$(LIBICAL_BASE): cd $(dir $(LIBICAL_BASE)) && git clone https://github.com/libical/libical - mkdir $(LIBICAL_BUILD) - cd $(LIBICAL_BUILD) && cmake .. && make + +$(LIBICAL_BUILD)/lib/libical.a: $(LIBICAL_BASE) + mkdir -p $(LIBICAL_BUILD) + cd $(LIBICAL_BUILD) && cmake $(LIBICAL_DEFINES) .. && make diff --git a/tools/ICALTester/compare.js b/tools/ICALTester/compare.js index c5bba71f..6f0dd901 100644 --- a/tools/ICALTester/compare.js +++ b/tools/ICALTester/compare.js @@ -3,22 +3,21 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. * Portions Copyright (C) Philipp Kewisch, 2015 */ -var fs = require('fs'); -var spawn = require('child_process').spawn; - -var diff = require('difflet')({ indent: true, comments: true }); -var Tester = require('./lib/ICALTester'); -var ICAL = require('../..'); +import fs from "fs"; +import { spawn } from "child_process"; +import difflet from "difflet"; +import Tester from "./lib/ICALTester.js"; +import ICAL from "../../lib/ical/module.js"; function setupHandlers(binPath) { Tester.addHandler("icaljs", function(rule, dtstart, max, callback) { - var iter = rule.iterator(dtstart); - var occ = 0; - var start = new Date(); + let iter = rule.iterator(dtstart); + let occ = 0; + let start = new Date(); - var results = []; + let results = []; (function loop() { - var next, diff; + let next, diff; if (++occ > max) { return callback(results); @@ -46,9 +45,9 @@ function setupHandlers(binPath) { }); Tester.addHandler("other", function(rule, dtstart, max, callback) { - var results = []; - var ptimer = null; - var recur = spawn(binPath, [rule.toString(), dtstart.toICALString(), max]); + let results = []; + let ptimer = null; + let recur = spawn(binPath, [rule.toString(), dtstart.toICALString(), max]); recur.stdout.on('data', function(data) { Array.prototype.push.apply(results, data.toString().split("\n").slice(0, -1)); @@ -88,16 +87,17 @@ function main() { usage(); } - var rulesFile = fs.statSync(process.argv[2]) && process.argv[2]; - var binPath = fs.statSync(process.argv[3]) && process.argv[3]; - var ruleData = JSON.parse(fs.readFileSync(rulesFile)); + let rulesFile = fs.statSync(process.argv[2]) && process.argv[2]; + let binPath = fs.statSync(process.argv[3]) && process.argv[3]; + let ruleData = JSON.parse(fs.readFileSync(rulesFile)); - var dtstart = ICAL.Time.fromString("2014-11-11T08:00:00"); - var max = 10; + let dtstart = ICAL.Time.fromString("2014-11-11T08:00:00"); + let max = 10; setupHandlers(binPath); Tester.run(ruleData, dtstart, max, function(err, results) { + let diff = difflet({ indent: true, comments: true }); console.log(diff.compare(results.other, results.icaljs)); }); } diff --git a/tools/ICALTester/lib/ICALTester.js b/tools/ICALTester/lib/ICALTester.js index 3f90e988..13592c45 100644 --- a/tools/ICALTester/lib/ICALTester.js +++ b/tools/ICALTester/lib/ICALTester.js @@ -9,12 +9,12 @@ * @module ICALTester */ -var ICAL = require('../../..'); -var async = require('async'); +import ICAL from "../../../lib/ical/module.js"; +import async from "async"; function range(min, max, nozero) { - var res = []; - for (var i = min; i <= max; i++) { + let res = []; + for (let i = min; i <= max; i++) { if (i == 0 && nozero) { continue; } @@ -32,8 +32,8 @@ function randInt(min, max) { } function randList(list, count) { - var vals = list.slice(); - var res = []; + let vals = list.slice(); + let res = []; while (count--) { res.push(vals.splice(randInt(0, vals.length), 1)[0]); @@ -42,14 +42,15 @@ function randList(list, count) { } function randValues(designdata) { - var count = randInt(1, designdata.length); + let count = randInt(1, designdata.length); return randList(designdata, count); } function sortByday(aRules, aWeekStart) { - var thisobj = { + let thisobj = { ruleDayOfWeek: ICAL.RecurIterator.prototype.ruleDayOfWeek, - sort_byday_rules: ICAL.RecurIterator.prototype.sort_byday_rules + sort_byday_rules: ICAL.RecurIterator.prototype.sort_byday_rules, + rule: { wkst: "MO" } }; return thisobj.sort_byday_rules(aRules, aWeekStart || ICAL.Time.MONDAY); @@ -61,7 +62,7 @@ function sortNumeric(a, b) { function substitute(rules) { return rules.map(function(r) { - for (var key in r) { + for (let key in r) { if (r[key] == "%") { r[key] = generators[key](r); } @@ -75,7 +76,7 @@ function addHandler(name, callback) { } function runHandler(handler, rules, dtstart, max, callback) { - var res = {}; + let res = {}; async.eachLimit(rules, CONCURRENCY, function(rule, eachcb) { handler(rule, dtstart, max, function(err, result) { res[rule] = err || result; @@ -87,22 +88,22 @@ function runHandler(handler, rules, dtstart, max, callback) { } function run(ruleData, dtstart, max, callback) { - var runner = (CONCURRENCY == 1 ? async.series : async.parallel); - var boundAsyncHandler = {}; - var rules = substitute(ruleData); + let runner = (CONCURRENCY == 1 ? async.series : async.parallel); + let boundAsyncHandler = {}; + let rules = substitute(ruleData); Object.keys(asyncHandler).forEach(function(k) { boundAsyncHandler[k] = runHandler.bind(null, asyncHandler[k], rules, dtstart, max); }); runner(boundAsyncHandler, callback); } -var CONCURRENCY = 2; -var MAX_EXECUTION_TIME = 1000; -var asyncHandler = {}; +let CONCURRENCY = 2; +let MAX_EXECUTION_TIME = 1000; +let asyncHandler = {}; -var day_names = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU']; -var freq_values = ['SECONDLY', 'MINUTELY', 'HOURLY', 'DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY']; -var design = { +let day_names = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU']; +let freq_values = ['SECONDLY', 'MINUTELY', 'HOURLY', 'DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY']; +let design = { FREQ: freq_values, BYSECOND: range(0, 60), @@ -124,13 +125,13 @@ var design = { WKST: day_names }; -var generators = { +let generators = { byday: function(rule) { - var designdata = design.BYDAY[rule.freq]; + let designdata = design.BYDAY[rule.freq]; - var daycount = randInt(1, designdata[1].length); - var days = randList(designdata[1], daycount); - var prefix = randList(designdata[0], daycount); + let daycount = randInt(1, designdata[1].length); + let days = randList(designdata[1], daycount); + let prefix = randList(designdata[0], daycount); sortByday(days, rule.wkst); @@ -151,20 +152,20 @@ var generators = { * gjslint complains about missing docs * @ignore */ -module.exports = { +export default { /** * The number of concurrent threads to use * @type {Number} */ get CONCURRENCY() { return CONCURRENCY; }, - set CONCURRENCY(v) { return (CONCURRENCY = v); }, + set CONCURRENCY(v) { CONCURRENCY = v; }, /** * The maximum execution time * @type {Number} */ get MAX_EXECUTION_TIME() { return MAX_EXECUTION_TIME; }, - set MAX_EXECUTION_TIME(v) { return (MAX_EXECUTION_TIME = v); }, + set MAX_EXECUTION_TIME(v) { MAX_EXECUTION_TIME = v; }, generators: generators, addHandler: addHandler,