<commit_before>var test = require("tap").test
  , path = require("path")
  , fs = require("graceful-fs")
  , crypto = require("crypto")
  , rimraf = require("rimraf")
  , osenv = require("osenv")
  , mkdirp = require("mkdirp")
  , npm = require("../../")
  , locker = require("../../lib/utils/locker.js")
  , lock = locker.lock
  , unlock = locker.unlock

var pkg = path.join(__dirname, "/locker")
  , cache = path.join(pkg, "/cache")
  , tmp = path.join(pkg, "/tmp")
  , nm = path.join(pkg, "/node_modules")

function cleanup () {
  process.chdir(osenv.tmpdir())
  rimraf.sync(pkg)
}

test("setup", function (t) {
  cleanup()
  mkdirp.sync(cache)
  mkdirp.sync(tmp)
  t.end()
})

test("locking file puts lock in correct place", function (t) {
  npm.load({cache: cache, tmpdir: tmp, loglevel: "silly"}, function (er) {
    t.ifError(er, "npm bootstrapped OK")

    var n = "correct"
      , c = n.replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "")
      , p = path.resolve(nm, n)
      , h = crypto.createHash("sha1").update(p).digest("hex")
      , l = c.substr(0, 24)+"-"+h.substr(0, 16)+".lock"
      , v = path.join(cache, "_locks",  l)

    lock(nm, n, function (er) {
      t.ifError(er, "locked path")

      fs.exists(v, function (found) {
        t.ok(found, "lock found OK")

        unlock(nm, n, function (er) {
          t.ifError(er, "unlocked path")

          fs.exists(v, function (found) {
            t.notOk(found, "lock deleted OK")
            t.end()
          })
        })
      })
    })<commit_msg>shh little test, be quiet<commit_after>var test = require("tap").test
  , path = require("path")
  , fs = require("graceful-fs")
  , crypto = require("crypto")
  , rimraf = require("rimraf")
  , osenv = require("osenv")
  , mkdirp = require("mkdirp")
  , npm = require("../../")
  , locker = require("../../lib/utils/locker.js")
  , lock = locker.lock
  , unlock = locker.unlock

var pkg = path.join(__dirname, "/locker")
  , cache = path.join(pkg, "/cache")
  , tmp = path.join(pkg, "/tmp")
  , nm = path.join(pkg, "/node_modules")

function cleanup () {
  process.chdir(osenv.tmpdir())
  rimraf.sync(pkg)
}

test("setup", function (t) {
  cleanup()
  mkdirp.sync(cache)
  mkdirp.sync(tmp)
  t.end()
})

test("locking file puts lock in correct place", function (t) {
  npm.load({cache: cache, tmpdir: tmp}, function (er) {
    t.ifError(er, "npm bootstrapped OK")

    var n = "correct"
      , c = n.replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "")
      , p = path.resolve(nm, n)
      , h = crypto.createHash("sha1").update(p).digest("hex")
      , l = c.substr(0, 24)+"-"+h.substr(0, 16)+".lock"
      , v = path.join(cache, "_locks",  l)

    lock(nm, n, function (er) {
      t.ifError(er, "locked path")

      fs.exists(v, function (found) {
        t.ok(found, "lock found OK")

        unlock(nm, n, function (er) {
          t.ifError(er, "unlocked path")

          fs.exists(v, function (found) {
            t.notOk(found, "lock deleted OK")
            t.end()
          })
        })
      })
    })
{'fraction_non_alphanumeric': 0.20812848246476565, 'fraction_numerical': 0.0058997050147492625, 'mean_word_length': 2.577960140679953, 'pattern_counts': {'":': 0, '<': 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': '6300220', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1111, 'n_words': 234}