github.com/goplus/gox@v1.14.13-0.20240308130321-6ff7f61cfae8/packages/imp_test.go (about)

     1  /*
     2   Copyright 2022 The GoPlus Authors (goplus.org)
     3   Licensed under the Apache License, Version 2.0 (the "License");
     4   you may not use this file except in compliance with the License.
     5   You may obtain a copy of the License at
     6       http://www.apache.org/licenses/LICENSE-2.0
     7   Unless required by applicable law or agreed to in writing, software
     8   distributed under the License is distributed on an "AS IS" BASIS,
     9   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    10   See the License for the specific language governing permissions and
    11   limitations under the License.
    12  */
    13  
    14  package packages
    15  
    16  import (
    17  	"os"
    18  	"testing"
    19  )
    20  
    21  func TestImporterNormal(t *testing.T) {
    22  	p := NewImporter(nil)
    23  	pkg, err := p.Import("fmt")
    24  	if err != nil || pkg.Path() != "fmt" {
    25  		t.Fatal("Import failed:", pkg, err)
    26  	}
    27  	if _, err = p.Import("not-found"); err == nil {
    28  		t.Fatal("Import not-found: no error?")
    29  	}
    30  	if pkg2, err := p.Import("fmt"); err != nil || pkg2 != pkg {
    31  		t.Fatal("Import reuse fail:", pkg, pkg2)
    32  	}
    33  }
    34  
    35  func TestImporterRecursive(t *testing.T) {
    36  	p := NewImporter(nil, "..")
    37  	pkg, err := p.Import("github.com/goplus/gox/internal/foo")
    38  	if err != nil {
    39  		t.Fatal("Import failed:", pkg, err)
    40  	}
    41  }
    42  
    43  func TestImportBuiltin(t *testing.T) {
    44  	p := NewImporter(nil, "..")
    45  	pkg, err := p.Import("github.com/goplus/gox/internal/builtin")
    46  	if err != nil {
    47  		t.Fatal("Import failed:", pkg, err)
    48  	}
    49  }
    50  
    51  func Test_loadByExport(t *testing.T) {
    52  	p := NewImporter(nil)
    53  	if _, err := p.loadByExport("/not-found", "notfound"); !os.IsNotExist(err) {
    54  		t.Fatal("Test_loadByExport: no error?")
    55  	}
    56  	FindExport(".", "C")
    57  }
    58  
    59  // ----------------------------------------------------------------------------