test_pkgs.sh raw

   1  #!/bin/bash
   2  set -e
   3  cd /home/mleku/s/moxie
   4  PASS=0
   5  FAIL=0
   6  SKIP=0
   7  
   8  test_pkg() {
   9      local pkg="$1"
  10      local code="$2"
  11      cat > _test_tier0/main.mx << EOF
  12  package main
  13  
  14  import "$pkg"
  15  
  16  func main() {
  17      $code
  18  }
  19  EOF
  20      if MOXIEROOT=. ./moxie build -a -o _test_tier0/out ./_test_tier0 2>/tmp/mxc_err; then
  21          if ./_test_tier0/out 2>&1; then
  22              echo "PASS: $pkg"
  23              PASS=$((PASS+1))
  24          else
  25              echo "FAIL(run): $pkg"
  26              FAIL=$((FAIL+1))
  27          fi
  28      else
  29          echo "FAIL(build): $pkg"
  30          cat /tmp/mxc_err | tail -5
  31          FAIL=$((FAIL+1))
  32      fi
  33      rm -f _test_tier0/out
  34  }
  35  
  36  # Tier 0 packages with actual compilable source
  37  test_pkg "errors" 'e := errors.New("x"); _ = e'
  38  test_pkg "unicode/utf8" '_ = utf8.RuneCountInString("hi")'
  39  test_pkg "unicode/utf16" 'b := utf16.Encode([]int32{0x48}); _ = b'
  40  test_pkg "unicode" '_ = unicode.IsLetter(int32(65))'
  41  test_pkg "internal/bytealg" '_ = bytealg.IndexByte([]byte("abc"), byte(98))'
  42  test_pkg "internal/byteorder" '_ = byteorder.LEUint32([]byte{1,0,0,0})'
  43  test_pkg "internal/itoa" '_ = itoa.Itoa(42)'
  44  test_pkg "internal/binary" '_ = binary.LittleEndian.Uint32([]byte{1,0,0,0})'
  45  test_pkg "structs" '_ = structs.HostLayout[int32]{}'
  46  
  47  echo ""
  48  echo "Results: $PASS pass, $FAIL fail, $SKIP skip"
  49