<commit_before>###
Run the binary and check results returned by example build.yml test cases
###

expect = require 'expect.js'
{exec, done} = require 'mocha-sprinkles'

Q = require 'q'
fs = require 'fs'

binubs = "#{process.cwd()}/bin/ubs"

describe 'Bootstrap tests', ->
  it "responds to --help", (done) ->
    exec("#{binubs} --help").then (p) ->
      expect(p.stderr.toString()).to.be ''
      expect(p.stdout.toString()).to.match /usage:/
      expect(p.stdout.toString()).to.match /options:/
      done()

  it 'should error if build file is not found', (done) ->
    exec("#{binubs} -b test/notfound.yml").then (p) ->
      done new Error "Should not be here!"
    , (p) ->
      expect(p.stderr.toString()).to.match /ENOENT/
      done()

  it 'should be able to output log messages', (done) ->
    exec("#{binubs} -b test/helloworld.yml test").then (p) ->
      expect(p.stderr.toString()).to.be 'WARN: warning level\nERROR: error level\n'
      expect(p.stdout.toString()).to.match /Hello World!/
      expect(p.stdout.toString()).to.match /Done\./
      expect(p.stdout.toString()).to.not.match /Bam!/
      done()

  it 'should be able to get and set environment variables', (done) ->
    exec("#{binubs} -b test/test_env.yml test", env: WTF: "works!").then (p) ->
      expect(p.stdout.toString()).to.match /bbq still works!/
      expect(p.stdout.toString()).to.match /Done\./
      done()

  # Call another instance of ourselves from build script to ensure we correctly
  # propagate environment variables both ways (parent -> child and child->parent).
  # We also override settings from command line to specify ubs instead of setting
  # "_" environment variable which might not be possible under some testing environments.
  it 'should be able to run nested instance and back propagate status', (done) ->
    exec("#{binubs} -b test/test_ipc_child.yml test bin=#{binubs}").then (p) ->
      expect(p.stdout.toString()).to.match /Expecting test to be working!/
      done()

describe 'Plugins', ->
  describe 'Package JSON', ->
    it 'should be able to output version from packagejson', (done) ->
      exec("#{binubs} -b test/test_plugin_packagejson.yml test").then (p) ->
        expect(p.stdout.toString()).to.match /version [0-9]+\.[0-9]+/
        expect(p.stdout.toString()).to.match /Done\./
        done()

  describe 'Grab', ->
    it 'should be able to retrieve this package\'s master zip file', (done) ->
      exec("#{binubs} -v -b test/test_plugin_grab.yml test").then (p) ->
        expect(p.stdout.toString()).to.match /Retrieving/
        expect(p.stdout.toString()).to.match /statusCode:\ 200\./
        expect(p.stdout.toString()).to.match /Done\./
        expect(fs.existsSync 'test/master.zip').to.be.ok()
        done()

  after ->
    # We completed our task, remove created files
    fs.unlinkSync 'test/master.zip'
<commit_msg>Added callback for better timeout/failure detection.<commit_after>###
Run the binary and check results returned by example build.yml test cases
###

expect = require 'expect.js'
{exec, done} = require 'mocha-sprinkles'

Q = require 'q'
fs = require 'fs'

binubs = "#{process.cwd()}/bin/ubs"

describe 'Bootstrap tests', ->
  it "responds to --help", (done) ->
    exec("#{binubs} --help").then (p) ->
      expect(p.stderr.toString()).to.be ''
      expect(p.stdout.toString()).to.match /usage:/
      expect(p.stdout.toString()).to.match /options:/
      done()
    , done

  it 'should error if build file is not found', (done) ->
    exec("#{binubs} -b test/notfound.yml").then (p) ->
      done new Error "Should not be here!"
    , (p) ->
      expect(p.stderr.toString()).to.match /ENOENT/
      done()

  it 'should be able to output log messages', (done) ->
    exec("#{binubs} -b test/helloworld.yml test").then (p) ->
      expect(p.stderr.toString()).to.be 'WARN: warning level\nERROR: error level\n'
      expect(p.stdout.toString()).to.match /Hello World!/
      expect(p.stdout.toString()).to.match /Done\./
      expect(p.stdout.toString()).to.not.match /Bam!/
      done()
    , done

  it 'should be able to get and set environment variables', (done) ->
    exec("#{binubs} -b test/test_env.yml test").then (p) ->
      expect(p.stdout.toString()).to.match /composite\: still works!/
      expect(p.stdout.toString()).to.match /Done\./
      done()
    , done

  # Call another instance of ourselves from build script to ensure we correctly
  # propagate environment variables both ways (parent -> child and child->parent).
  it 'should be able to run nested instance and back propagate status', (done, error) ->
    exec("#{binubs} -b test/test_ipc_child.yml test").then (p) ->
      expect(p.stdout.toString()).to.match /Expecting test to be working!/
      done()
    , error

describe 'Plugins', ->
  describe 'Package JSON', ->
    it 'should be able to output version from packagejson', (done, error) ->
      exec("#{binubs} -b test/test_plugin_packagejson.yml test").then (p) ->
        expect(p.stdout.toString()).to.match /version [0-9]+\.[0-9]+/
        expect(p.stdout.toString()).to.match /Done\./
        done()
      , error

  describe 'Grab', ->
    it 'should be able to retrieve this package\'s master zip file', (done, error) ->
      exec("#{binubs} -b test/test_plugin_grab.yml test").then (p) ->
        expect(p.stdout.toString()).to.match /Retrieving/
        expect(p.stdout.toString()).to.match /Done\./
        expect(fs.existsSync 'test/master.zip').to.be.ok()
        done()
      , error

  after ->
    # We completed our task, remove created files
    fs.unlinkSync 'test/master.zip'

{'fraction_non_alphanumeric': 0.16690467690110675, 'fraction_numerical': 0.0019635844341306676, 'mean_word_length': 2.858815426997245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, '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': '5032603', 'n_tokens_mistral': 1813, 'n_tokens_neox': 1740, 'n_words': 504}