<commit_before>var fs = require('fs')
var os = require('os')
var path = require('path')
var test = require('tape')
var spawn = require('tape-spawn')
var helpers = require('./helpers')

var tmp = os.tmpdir()
var dat = path.resolve(__dirname + '/../cli.js')
var dat1 = path.join(tmp, 'dat-cli-1')

test('cli: dat -v (version)', function (t) {
  var st = spawn(t, dat + ' -v')
  var pkg = require('../package.json')
  st.stdout.match(pkg.version + '\n')
  st.stderr.empty()
  st.end()
})

test('cli: dat --version (version)', function (t) {
  var st = spawn(t, dat + ' --version')
  var pkg = require('../package.json')
  st.stdout.match(pkg.version + '\n')
  st.stderr.empty()
  st.end()
})

test('cli: dat (usage)', function (t) {
  var st = spawn(t, dat)
  st.stderr.match(fs.readFileSync(path.join('usage', 'root.txt')).toString() + '\n', 'usage matched')
  st.stdout.empty()
  st.end()
})

test('cli: dat init -h (init usage)', function (t) {
  var st = spawn(t, dat + ' init -h')
  st.stderr.match(fs.readFileSync(path.join('usage', 'init.txt')).toString() + '\n', 'usage matched')
  st.stdout.empty()
  st.end()
})

test('cli: invalid command', function (t) {
  var st = spawn(t, dat + ' pizza')
  st.stderr.match('dat: pizza is not a valid command\n', 'usage matched')
  st.stdout.empty()
  st.end()
})

var cleanup = helpers.onedat(dat1)

// sanity: make sure cwd isn't in a repo
test('cli: dat status (cwd)', function (t) {
  var st = spawn(t, dat + ' status')
  st.stderr.match(/This is not a dat repository/)
  st.stdout.empty()
  st.end()
})

test('cli: dat -p (path)', function (t) {
  var st = spawn(t, dat + ' status -p ' + dat1)
  st.stderr.match(/This dat is empty/)
  st.stdout.empty()
  st.end()
})

test('cli: dat --path (path)', function (t) {
  var st = spawn(t, dat + ' status --path=' + dat1)
  st.stderr.match(/This dat is empty/)
  st.stdout.empty()
  st.end()
})

test('cli: dat status --json', function (t) {
  var st = spawn(t, dat + ' status --json --path=' + dat1)
  st.stdout.match('{"error":true,"message":"This dat is empty"}\n')
  st.stderr.empty()
  st.end()
})

test('cli: dat status --json --verbose', function (t) {
  var st = spawn(t, dat + ' status --json --verbose --path=' + dat1)
  st.stdout.match(new RegExp('"error":true,"message":"This dat is empty","stack":"Error:'))
  st.stderr.empty()
  st.end()
})

test('cli: dat status --verbose', function (t) {
  var st = spawn(t, dat + ' status --verbose --path=' + dat1)
  st.stderr.match(/This dat is empty\nError/)
  st.stdout.empty()
  st.end()
})

test('cli: cleanup', function (t) {
  cleanup()
  t.end()
})<commit_msg>tests shouldn't depend on local directory -- create a tmp dir for status tests<commit_after>var fs = require('fs')
var os = require('os')
var path = require('path')
var test = require('tape')
var spawn = require('tape-spawn')
var helpers = require('./helpers')

var tmp = os.tmpdir()
var dat = path.resolve(__dirname + '/../cli.js')
var dat1 = path.join(tmp, 'dat-cli-1')

test('cli: dat -v (version)', function (t) {
  var st = spawn(t, dat + ' -v')
  var pkg = require('../package.json')
  st.stdout.match(pkg.version + '\n')
  st.stderr.empty()
  st.end()
})

test('cli: dat --version (version)', function (t) {
  var st = spawn(t, dat + ' --version')
  var pkg = require('../package.json')
  st.stdout.match(pkg.version + '\n')
  st.stderr.empty()
  st.end()
})

test('cli: dat (usage)', function (t) {
  var st = spawn(t, dat)
  st.stderr.match(fs.readFileSync(path.join('usage', 'root.txt')).toString() + '\n', 'usage matched')
  st.stdout.empty()
  st.end()
})

test('cli: dat init -h (init usage)', function (t) {
  var st = spawn(t, dat + ' init -h')
  st.stderr.match(fs.readFileSync(path.join('usage', 'init.txt')).toString() + '\n', 'usage matched')
  st.stdout.empty()
  st.end()
})

test('cli: invalid command', function (t) {
  var st = spawn(t, dat + ' pizza')
  st.stderr.match('dat: pizza is not a valid command\n', 'usage matched')
  st.stdout.empty()
  st.end()
})

var cleanup = helpers.onedat(dat1)

var tmp = os.tmpdir()

// sanity: make sure cwd isn't in a repo
test('cli: dat status (cwd)', function (t) {
  var st = spawn(t, dat + ' status', {cwd: tmp})
  st.stderr.match(/This is not a dat repository/)
  st.stdout.empty()
  st.end()
})

test('cli: dat -p (path)', function (t) {
  var st = spawn(t, dat + ' status -p ' + dat1, {cwd: tmp})
  st.stderr.match(/This dat is empty/)
  st.stdout.empty()
  st.end()
})

test('cli: dat --path (path)', function (t) {
  var st = spawn(t, dat + ' status --path=' + dat1, {cwd: tmp})
  st.stderr.match(/This dat is empty/)
  st.stdout.empty()
  st.end()
})

test('cli: dat status --json', function (t) {
  var st = spawn(t, dat + ' status --json --path=' + dat1, {cwd: tmp})
  st.stdout.match('{"error":true,"message":"This dat is empty"}\n')
  st.stderr.empty()
  st.end()
})

test('cli: dat status --json --verbose', function (t) {
  var st = spawn(t, dat + ' status --json --verbose --path=' + dat1, {cwd: tmp})
  st.stdout.match(new RegExp('"error":true,"message":"This dat is empty","stack":"Error:'))
  st.stderr.empty()
  st.end()
})

test('cli: dat status --verbose', function (t) {
  var st = spawn(t, dat + ' status --verbose --path=' + dat1)
  st.stderr.match(/This dat is empty\nError/)
  st.stdout.empty()
  st.end()
})

test('cli: cleanup', function (t) {
  cleanup()
  t.end()
})
{'fraction_non_alphanumeric': 0.21678451804986976, 'fraction_numerical': 0.00297729810197246, 'mean_word_length': 3.4421487603305785, 'pattern_counts': {'":': 10, '<': 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': '7408785', 'n_tokens_mistral': 1994, 'n_tokens_neox': 1990, 'n_words': 545}