Skip to content

Commit d43cfd2

Browse files
committed
[#390] Ensure toolchain command execution returns failure when command is not found
- Also improve smoke tests to verify behaviour for both a failing command and a command not found
1 parent 1a69d09 commit d43cfd2

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/toolchain/command_runner.go

+6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ func (r *CommandRunner) Run(cmd *Command) (result CommandResult) {
9191
errStart := r.command.Start()
9292
if errStart != nil {
9393
report.PostError("Failed to run command: ", errStart.Error())
94+
// We currently return fail status when command cannot be launched.
95+
// This is to replicate previous implementation's behaviour where
96+
// we could not differentiate between failure to launch and failure from execution.
97+
// We could later on use a different return value in this situation,
98+
// but we need to ensure first that TCR engine can handle it correctly.
99+
result.Status = CommandStatusFail
94100
r.command = nil
95101
return result
96102
}

src/toolchain/smoke_test.go

+41-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2023 Murex
2+
Copyright (c) 2024 Murex
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
@@ -31,19 +31,57 @@ const (
3131
toolchainName = "gradle-wrapper"
3232
)
3333

34-
func Test_toolchain_returns_error_when_build_fails(t *testing.T) {
34+
func Test_toolchain_returns_error_when_build_command_is_not_found(t *testing.T) {
35+
// Command does not exist in testDataRootDir
3536
assertErrorWhenBuildFails(t, toolchainName, testDataRootDir)
3637
}
3738

39+
func Test_toolchain_returns_error_when_build_command_fails(t *testing.T) {
40+
tchn, _ := Get(toolchainName)
41+
// Add a built-in toolchain from a valid one, but with invalid build command arguments.
42+
// This allows to actually run the build command and get an execution error out of it
43+
failingName := tchn.GetName() + "-failing-build"
44+
var failingCommands []Command
45+
for _, cmd := range tchn.GetBuildCommands() {
46+
failingCommands = append(failingCommands, Command{
47+
Os: cmd.Os,
48+
Arch: cmd.Arch,
49+
Path: cmd.Path,
50+
Arguments: []string{"-invalid-argument"},
51+
})
52+
}
53+
_ = addBuiltIn(New(failingName, failingCommands, tchn.GetTestCommands(), tchn.GetTestResultDir()))
54+
assertErrorWhenBuildFails(t, failingName, testDataDirJava)
55+
}
56+
3857
func Test_toolchain_returns_ok_when_build_passes(t *testing.T) {
3958
utils.SlowTestTag(t)
4059
assertNoErrorWhenBuildPasses(t, toolchainName, testDataDirJava)
4160
}
4261

43-
func Test_toolchain_returns_error_when_tests_fail(t *testing.T) {
62+
func Test_toolchain_returns_error_when_test_command_is_not_found(t *testing.T) {
63+
// Command does not exist in testDataRootDir
4464
assertErrorWhenTestFails(t, toolchainName, testDataRootDir)
4565
}
4666

67+
func Test_toolchain_returns_error_when_test_command_fails(t *testing.T) {
68+
// Add a built-in toolchain from a valid one, but with invalid test command arguments.
69+
// This allows to actually run the test command and get an execution error out of it
70+
tchn, _ := Get(toolchainName)
71+
failingName := tchn.GetName() + "-failing-test"
72+
var failingCommands []Command
73+
for _, cmd := range tchn.GetTestCommands() {
74+
failingCommands = append(failingCommands, Command{
75+
Os: cmd.Os,
76+
Arch: cmd.Arch,
77+
Path: cmd.Path,
78+
Arguments: []string{"-invalid-argument"},
79+
})
80+
}
81+
_ = addBuiltIn(New(failingName, tchn.GetBuildCommands(), failingCommands, tchn.GetTestResultDir()))
82+
assertErrorWhenTestFails(t, failingName, testDataDirJava)
83+
}
84+
4785
func Test_toolchain_returns_ok_when_tests_pass(t *testing.T) {
4886
utils.SlowTestTag(t)
4987
assertNoErrorWhenTestPasses(t, toolchainName, testDataDirJava)

0 commit comments

Comments
 (0)