Skip to content

Commit

Permalink
fixed tests not specifying full args for build due to default config …
Browse files Browse the repository at this point in the history
…merge being removed
  • Loading branch information
Southclaws committed Dec 18, 2017
1 parent 19db64b commit 4fcf04e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type Config struct {
}

// GetDefaultConfig defines and returns a default compiler configuration
func GetDefaultConfig() Config {
return Config{
func GetDefaultConfig() *Config {
return &Config{
Args: []string{"-d3", "-;+", "-(+", "-\\+", "-Z+"},
Version: "3.10.4",
}
Expand Down
23 changes: 10 additions & 13 deletions rook/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (

// Build compiles a package, dependencies are ensured and a list of paths are sent to the compiler.
func (pkg Package) Build(build string, ensure bool) (output string, err error) {
config, err := pkg.GetBuildConfig(build)
if err != nil {
err = errors.Wrap(err, "failed to get build config")
config := pkg.GetBuildConfig(build)
if config == nil {
err = errors.Errorf("no build config named '%s'", build)
return
}

Expand Down Expand Up @@ -49,7 +49,7 @@ func (pkg Package) Build(build string, ensure bool) (output string, err error) {

fmt.Println("building", pkg, "with", config.Version)

err = compiler.CompileSource(pkg.local, cacheDir, config)
err = compiler.CompileSource(pkg.local, cacheDir, *config)
if err != nil {
err = errors.Wrap(err, "failed to compile package entry")
return
Expand All @@ -63,19 +63,16 @@ func (pkg Package) Build(build string, ensure bool) (output string, err error) {
// GetBuildConfig returns a matching build by name from the package build list. If no name is
// specified, the first build is returned. If the package has no build definitions, a default
// configuration is returned.
func (pkg Package) GetBuildConfig(name string) (config compiler.Config, err error) {
func (pkg Package) GetBuildConfig(name string) (config *compiler.Config) {
if len(pkg.Builds) == 0 || name == "" {
config = compiler.GetDefaultConfig()
return
}

for _, cfg := range pkg.Builds {
if cfg.Name == name {
return cfg, nil
} else {
for _, cfg := range pkg.Builds {
if cfg.Name == name {
config = &cfg
}
}
}

err = errors.Errorf("build '%s' not found in config", name)

return
}
4 changes: 1 addition & 3 deletions rook/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ func TestPackage_Build(t *testing.T) {
"Southclaws/samp-stdlib:0.3.7-R2-2-1",
"ScavengeSurvive/actions",
},
Builds: []compiler.Config{
{Name: "build", Version: "3.10.4"},
},
}, args{"build", true}, "gamemodes/test.amx", false},
{"custominc", []byte(`#include <a_samp>
#include <YSI\y_utils>
Expand All @@ -73,6 +70,7 @@ func TestPackage_Build(t *testing.T) {
"../build-auto-deep/dependencies/amx_assembly",
"../build-auto-deep/dependencies/YSI-Includes",
},
Args: []string{"-d3", "-;+", "-(+", "-\\+", "-Z+"},
},
},
}, args{"build", true}, "gamemodes/test.amx", false},
Expand Down

0 comments on commit 4fcf04e

Please sign in to comment.