<commit_before>
should = require 'should'
mecano = if process.env.MECANO_COV then require '../lib-cov/mecano' else require '../lib/mecano'
misc = if process.env.MECANO_COV then require '../lib-cov/misc' else require '../lib/misc'
test = require './test'

describe 'mecano', ->

  scratch = test.scratch @

  it 'should chain with error and end', (next) ->
    result = mecano
    .mkdir
      content: 'hello'
      destination: "#{scratch}/chain"
    .write
      content: 'hello'
      destination: "#{scratch}/chain/file"
    .write
      content: 'world'
      destination: "#{scratch}/chain/file"
      append: true
    .on 'error', ->
      false.should.be.ok
    .on 'end', ->
      misc.file.readFile null, "#{scratch}/chain/file", (err, content) ->
        return next err if err
        content.should.eql 'helloworld'
        next()

  it 'should chain with both', (next) ->
    result = mecano
    .mkdir
      content: 'hello'
      destination: "#{scratch}/chain"
    .write
      content: 'hello'
      destination: "#{scratch}/chain/file"
    .write
      content: 'world'
      destination: "#{scratch}/chain/file"
      append: true
    .on 'both', ->
      misc.file.readFile null, "#{scratch}/chain/file", (err, content) ->
        return next err if err
        content.should.eql 'helloworld'
        next()

  it 'should handle error with error and end', (next) ->
    result = mecano
    .mkdir
      content: 'hello'
      destination: "#{scratch}/chain"
    .execute
      content: 'hello'
      cmd: "cd #{scratch}/should_not_exist"
    .write
      content: 'world'
      destination: "#{scratch}/chain/file"
      append: true
    .on 'error', (err) ->
      next()
    .on 'end', ->
      false.should.be.ok

  it 'should handle error with both', (next) ->
    result = mecano
    .mkdir<commit_msg>Update mecano test to pass encoding argument<commit_after>
should = require 'should'
mecano = if process.env.MECANO_COV then require '../lib-cov/mecano' else require '../lib/mecano'
misc = if process.env.MECANO_COV then require '../lib-cov/misc' else require '../lib/misc'
test = require './test'

describe 'mecano', ->

  scratch = test.scratch @

  it 'should chain with error and end', (next) ->
    result = mecano
    .mkdir
      content: 'hello'
      destination: "#{scratch}/chain"
    .write
      content: 'hello'
      destination: "#{scratch}/chain/file"
    .write
      content: 'world'
      destination: "#{scratch}/chain/file"
      append: true
    .on 'error', ->
      false.should.be.ok
    .on 'end', ->
      misc.file.readFile null, "#{scratch}/chain/file", 'utf8', (err, content) ->
        return next err if err
        content.should.eql 'helloworld'
        next()

  it 'should chain with both', (next) ->
    result = mecano
    .mkdir
      content: 'hello'
      destination: "#{scratch}/chain"
    .write
      content: 'hello'
      destination: "#{scratch}/chain/file"
    .write
      content: 'world'
      destination: "#{scratch}/chain/file"
      append: true
    .on 'both', ->
      misc.file.readFile null, "#{scratch}/chain/file", 'utf8', (err, content) ->
        return next err if err
        content.should.eql 'helloworld'
        next()

  it 'should handle error with error and end', (next) ->
    result = mecano
    .mkdir
      content: 'hello'
      destination: "#{scratch}/chain"
    .execute
      content: 'hello'
      cmd: "cd #{scratch}/should_not_exist"
    .write
      content: 'world'
      destination: "#{scratch}/chain/file"
      append: true
    .on 'error', (err) ->
      next()
    .on 'end', ->
      false.should.be.ok

  it 'should handle error with both', (next) ->
    result = mecano
    .mkdir
{'fraction_non_alphanumeric': 0.15006747638326587, 'fraction_numerical': 0.0005398110661268556, 'mean_word_length': 2.2767462422634837, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '1311936', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1187, 'n_words': 327}