<commit_before>var shell = require('..');

var assert = require('assert'),
    fs = require('fs');

shell.config.silent = true;

shell.rm('-rf', 'tmp');
shell.mkdir('tmp');

// Prepare tmp/
shell.cp('resources/*', 'tmp');

//
// Invalids
//

shell.ln();
assert.ok(shell.error());

shell.ln('file');
assert.ok(shell.error());

shell.ln('-f');
assert.ok(shell.error());

shell.ln('tmp/file1', 'tmp/file2');
assert.ok(shell.error());

shell.ln('tmp/noexist', 'tmp/linkfile1');
assert.ok(shell.error());

//
// Valids
//

shell.ln('tmp/file1', 'tmp/linkfile1');
assert(fs.existsSync('tmp/linkfile1'));
assert.equal(
  fs.readFileSync('tmp/file1').toString(),
  fs.readFileSync('tmp/linkfile1').toString()
);
fs.writeFileSync('tmp/file1', 'new content 1');
assert.equal(
  fs.readFileSync('tmp/linkfile1').toString(),
  'new content 1'
);

shell.ln('-s', 'tmp/file2', 'tmp/linkfile2');
assert(fs.existsSync('tmp/linkfile2'));
assert.equal(
  fs.readFileSync('tmp/file2').toString(),
  fs.readFileSync('tmp/linkfile2').toString()
);
fs.writeFileSync('tmp/file2', 'new content 2');
assert.equal(
  fs.readFileSync('tmp/linkfile2').toString(),
  'new content 2'
);

shell.ln('-f', 'tmp/file1.js', 'tmp/file2.js');
assert(fs.existsSync('tmp/file2.js'));
assert.equal(
  fs.readFileSync('tmp/file1.js').toString(),
  fs.readFileSync('tmp/file2.js').toString()
);
fs.writeFileSync('tmp/file1.js', 'new content js');
assert.equal(
  fs.readFileSync('tmp/file2.js').toString(),
  'new content js'
);

shell.ln('-sf', 'tmp/file1.txt', 'tmp/file2.txt');
assert(fs.existsSync('tmp/file2.txt'));
assert.equal(
  fs.readFileSync('tmp/file1.txt').toString(),
  fs.readFileSync('tmp/file2.txt').toString()
);
fs.writeFileSync('tmp/file1.txt', 'new content txt');
assert.equal(
  fs.readFileSync('tmp/file2.txt').toString(),
  'new content txt'
);

shell.exit(123);<commit_msg>Add a regression test for ln treating abspaths badly.<commit_after>var shell = require('..');

var assert = require('assert'),
    fs = require('fs'),
    path = require('path');

shell.config.silent = true;

shell.rm('-rf', 'tmp');
shell.mkdir('tmp');

// Prepare tmp/
shell.cp('resources/*', 'tmp');

//
// Invalids
//

shell.ln();
assert.ok(shell.error());

shell.ln('file');
assert.ok(shell.error());

shell.ln('-f');
assert.ok(shell.error());

shell.ln('tmp/file1', 'tmp/file2');
assert.ok(shell.error());

shell.ln('tmp/noexist', 'tmp/linkfile1');
assert.ok(shell.error());

//
// Valids
//

shell.ln('tmp/file1', 'tmp/linkfile1');
assert(fs.existsSync('tmp/linkfile1'));
assert.equal(
  fs.readFileSync('tmp/file1').toString(),
  fs.readFileSync('tmp/linkfile1').toString()
);
fs.writeFileSync('tmp/file1', 'new content 1');
assert.equal(
  fs.readFileSync('tmp/linkfile1').toString(),
  'new content 1'
);

shell.ln('-s', 'tmp/file2', 'tmp/linkfile2');
assert(fs.existsSync('tmp/linkfile2'));
assert.equal(
  fs.readFileSync('tmp/file2').toString(),
  fs.readFileSync('tmp/linkfile2').toString()
);
fs.writeFileSync('tmp/file2', 'new content 2');
assert.equal(
  fs.readFileSync('tmp/linkfile2').toString(),
  'new content 2'
);

shell.ln('-f', 'tmp/file1.js', 'tmp/file2.js');
assert(fs.existsSync('tmp/file2.js'));
assert.equal(
  fs.readFileSync('tmp/file1.js').toString(),
  fs.readFileSync('tmp/file2.js').toString()
);
fs.writeFileSync('tmp/file1.js', 'new content js');
assert.equal(
  fs.readFileSync('tmp/file2.js').toString(),
  'new content js'
);

shell.ln('-sf', 'tmp/file1.txt', 'tmp/file2.txt');
assert(fs.existsSync('tmp/file2.txt'));
assert.equal(
  fs.readFileSync('tmp/file1.txt').toString(),
  fs.readFileSync('tmp/file2.txt').toString()
);
fs.writeFileSync('tmp/file1.txt', 'new content txt');
assert.equal(
  fs.readFileSync('tmp/file2.txt').toString(),
  'new content txt'
);

// Abspath regression
shell.ln('-sf', 'tmp/file1', path.resolve('tmp/abspath'));
assert(fs.existsSync('tmp/abspath'));
assert.equal(
  fs.readFileSync('tmp/file1').toString(),
  fs.readFileSync('tmp/abspath').toString()
);
fs.writeFileSync('tmp/file1', 'new content 3');
assert.equal(
  fs.readFileSync('tmp/abspath').toString(),
  'new content 3'
);

shell.exit(123);
{'fraction_non_alphanumeric': 0.23789932236205227, 'fraction_numerical': 0.019603097773475315, 'mean_word_length': 5.19640179910045, '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': '5056573', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1568, 'n_words': 217}