Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ICALTester to make it useable again #664

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 9 additions & 5 deletions tools/ICALTester/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
38 changes: 19 additions & 19 deletions tools/ICALTester/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
});
}
Expand Down
57 changes: 29 additions & 28 deletions tools/ICALTester/lib/ICALTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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]);
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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;
Expand All @@ -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),
Expand All @@ -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);

Expand All @@ -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,
Expand Down