<commit_before>
var env = require('env');
var config;

try {
  config = require('config');
}
catch (e) {
  config = require('config.sample');
}

var win = Ti.UI.createWindow({});

var list = Ti.UI.createScrollView({
  width: Ti.UI.SIZE,
  height: Ti.UI.SIZE,
  layout: 'vertical'
});

var bar = Ti.UI.createProgressBar({
  top: 0,
  right: 0,
  left: 0,
  min: 0,
  max: 1,
  value: 0
});

bar.hide();

win.add(list);
win.add(bar);

var ACTIONS = [
  {
    title: 'Errors Test',
    handle: require('tests/errors')
  },
  {
    title: 'Callback Test',
    handle: require('tests/once')
  },
  {
    title: 'Timeout Test',
    handle: require('tests/timeout')
  },
  {
    title: 'Failure Test',
    handle: require('tests/failure')
  },
  {
    title: 'Stress Test',
    handle: require('tests/stress')
  },
  {
    all: true,
    title: '» All «',
    handle: launchAll
  }
];

var BUTTONS = ACTIONS.map(function (action) {

  action.button = Ti.UI.createButton({
    title: action.title
  });

  action.running = false;

  action.button.addEventListener('click', function () {
    if (action.button.disabled) {
      return;
    }

    var buttons;

    if (action.all) {
      buttons = BUTTONS;
    }
    else {
      buttons = [ action.button ];
    }

    action.running = true;
    buttons.forEach(disableButton);
    action.handle(config, function (err) {
      action.running = false;
      buttons.forEach(enableButton);
      informUser(action.title, err);
    });
  });

  list.add(action.button);

  return action.button;
});

if (config.AUTO_LAUNCH || env.TRAVIS === 'true') {
  launchAll(function (err) {
    notifyBuildSystem(err);
  });
}

function notifyBuildSystem(err) {
  if (err) {
    Ti.API.error("NOTOK");
    Ti.API.error(err);
  }
  else {
    Ti.API.info("ALLOK");
  }
}

function informUser(message, err) {
  if (err) {
    alert(message + ": NOT OK\n" + err);
    throw err;
  }
  else {
    alert(message + ": Done");
  }
}

function launchAll(config, callback) {
  bar.show();
  bar.value = 0;
  launch(0, function () {
    bar.value = 1;
    bar.hide();
    return callback.apply(this, arguments);
  });
}

function launch(i, callback) {
  bar.value = (1 / (ACTIONS.length - 1)) * i;
  var action = ACTIONS[i];
  if (action && !action.all) action.handle(config, function (err) {
    if (action.running) callback(new Error("Already running"));
    else if (err) callback(err);
    else setTimeout(function () {
      launch(i + 1, callback)
    }, 0);
  });
  else callback();
}

function enableButton(button) {
  button.enabled = true;
  button.disabled = false;
}

function disableButton(button) {
  button.enabled = false;
  button.disabled = true;
}

win.open();
<commit_msg>I need to pass config to launchAll too...<commit_after>
var env = require('env');
var config;

try {
  config = require('config');
}
catch (e) {
  config = require('config.sample');
}

var win = Ti.UI.createWindow({});

var list = Ti.UI.createScrollView({
  width: Ti.UI.SIZE,
  height: Ti.UI.SIZE,
  layout: 'vertical'
});

var bar = Ti.UI.createProgressBar({
  top: 0,
  right: 0,
  left: 0,
  min: 0,
  max: 1,
  value: 0
});

bar.hide();

win.add(list);
win.add(bar);

var ACTIONS = [
  {
    title: 'Errors Test',
    handle: require('tests/errors')
  },
  {
    title: 'Callback Test',
    handle: require('tests/once')
  },
  {
    title: 'Timeout Test',
    handle: require('tests/timeout')
  },
  {
    title: 'Failure Test',
    handle: require('tests/failure')
  },
  {
    title: 'Stress Test',
    handle: require('tests/stress')
  },
  {
    all: true,
    title: '» All «',
    handle: launchAll
  }
];

var BUTTONS = ACTIONS.map(function (action) {

  action.button = Ti.UI.createButton({
    title: action.title
  });

  action.running = false;

  action.button.addEventListener('click', function () {
    if (action.button.disabled) {
      return;
    }

    var buttons;

    if (action.all) {
      buttons = BUTTONS;
    }
    else {
      buttons = [ action.button ];
    }

    action.running = true;
    buttons.forEach(disableButton);
    action.handle(config, function (err) {
      action.running = false;
      buttons.forEach(enableButton);
      informUser(action.title, err);
    });
  });

  list.add(action.button);

  return action.button;
});

if (config.AUTO_LAUNCH || env.TRAVIS === 'true') {
  launchAll(config, function (err) {
    notifyBuildSystem(err);
  });
}

function notifyBuildSystem(err) {
  if (err) {
    Ti.API.error("NOTOK");
    Ti.API.error(err);
  }
  else {
    Ti.API.info("ALLOK");
  }
}

function informUser(message, err) {
  if (err) {
    alert(message + ": NOT OK\n" + err);
    throw err;
  }
  else {
    alert(message + ": Done");
  }
}

function launchAll(config, callback) {
  bar.show();
  bar.value = 0;
  launch(0, function () {
    bar.value = 1;
    bar.hide();
    return callback.apply(this, arguments);
  });
}

function launch(i, callback) {
  bar.value = (1 / (ACTIONS.length - 1)) * i;
  var action = ACTIONS[i];
  if (action && !action.all) action.handle(config, function (err) {
    if (action.running) callback(new Error("Already running"));
    else if (err) callback(err);
    else setTimeout(function () {
      launch(i + 1, callback)
    }, 0);
  });
  else callback();
}

function enableButton(button) {
  button.enabled = true;
  button.disabled = false;
}

function disableButton(button) {
  button.enabled = false;
  button.disabled = true;
}

win.open();

{'fraction_non_alphanumeric': 0.1692927812385489, 'fraction_numerical': 0.004763649688530597, 'mean_word_length': 2.855225988700565, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '753467', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1915, 'n_words': 420}