Welcome to mirror list, hosted at ThFree Co, Russian Federation.

run.sh « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7d9d2803861f4b2689a8e6e195c13e166f74235d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash

# the "npm" command is set to a custom function here so that we can
# test the code in this repo, rather than whichever version of npm
# happens to be installed.

main () {
  # setup
  FAILURES=0
  npm install "$NPMPKG"

  # TODO: add more tests here.
  # Run node programs by doing node some-thing.js

  npm install "$TESTDIR"/packages/mjsunit.runner
  npm install jsdom
  npm rm jsdom
  npm rm mjsunit.runner

  # teardown
  npm rm npm

  if [ $FAILURES -eq 0 ]; then
    # rm -rf "$ROOTDIR"
    # rm -rf "$BINDIR"
    rm -rf "$ROOTDIR/.npm/.cache"
    rm -rf "$ROOTDIR/.npm/.tmp"
    echo_err "ok"
  else
    rm -rf "$ROOTDIR/.npm/.cache"
    rm -rf "$ROOTDIR/.npm/.tmp"
    echo_err "FAILED: $FAILURES"
  fi
  exit $FAILURES
}



####################
# Test Harness below

# fake functions
npm () {
  "$NPMCLI" --binroot "$TESTDIR/bin" --root "$TESTDIR/root" "$@" \
    &>output.log \
    || fail npm "$@"
  rm output.log
}
node () {
  local prog="$TESTDIR/$1"
  PATH="$PATH":"$TESTDIR/bin" NODE_PATH="$TESTDIR/root" $(which node) "$prog" \
    &>output.log \
    || fail node "$@"
}

# get the absolute path of the executable
SELF_PATH="$0"
if [ "${SELF_PATH:0:1}" != "." ] && [ "${SELF_PATH:0:1}" != "/" ]; then
  SELF_PATH=./"$SELF_PATH"
fi
SELF_PATH=$( cd -P -- "$(dirname -- "$SELF_PATH")" \
          && pwd -P \
          ) && SELF_PATH=$SELF_PATH/$(basename -- "$0")
# resolve symlinks
while [ -h "$SELF_PATH" ]; do
  DIR=$(dirname -- "$SELF_PATH")
  SYM=$(readlink -- "$SELF_PATH")
  SELF_PATH=$( cd -- "$DIR" \
            && cd -- $(dirname -- "$SYM") \
            && pwd \
            )/$(basename -- "$SYM")
done
NPMPKG="$(dirname -- "$(dirname -- "$SELF_PATH")")"
NPMCLI="$NPMPKG/cli.js"
TESTDIR="$NPMPKG/test/"
ROOTDIR="$TESTDIR/root"
BINDIR="$TESTDIR/bin"

[ -d "$ROOTDIR" ] && rm -rf -- "$ROOTDIR"
[ -d "$BINDIR" ] && rm -rf -- "$BINDIR"
mkdir -p -- "$ROOTDIR"
mkdir -p -- "$BINDIR"

echo_err () {
  echo "$@" >&2
}
fail () {
  let 'FAILURES += 1'
  cat output.log
  echo_err ""
  echo_err -e "\033[33mFailure: $@\033[m"
}

main