Skip to content

Commit c78ae7a

Browse files
Include pre-uninstall script run into the unit test
1 parent de7c018 commit c78ae7a

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

Diff for: arduino/cores/packagemanager/package_manager_test.go

+28-6
Original file line numberDiff line numberDiff line change
@@ -930,29 +930,51 @@ func TestRunPostInstall(t *testing.T) {
930930
// prepare dummy post install script
931931
dir := paths.New(t.TempDir())
932932

933-
var scriptPath *paths.Path
933+
var postScriptPath *paths.Path
934+
var preScriptPath *paths.Path
934935
var err error
935936
if runtime.GOOS == "windows" {
936-
scriptPath = dir.Join("post_install.bat")
937+
postScriptPath = dir.Join("post_install.bat")
938+
preScriptPath = dir.Join("pre_uninstall.bat")
937939

938-
err = scriptPath.WriteFile([]byte(
940+
err = postScriptPath.WriteFile([]byte(
941+
`@echo off
942+
echo sent in stdout
943+
echo sent in stderr 1>&2`))
944+
require.NoError(t, err)
945+
err = preScriptPath.WriteFile([]byte(
939946
`@echo off
940947
echo sent in stdout
941948
echo sent in stderr 1>&2`))
942949
} else {
943-
scriptPath = dir.Join("post_install.sh")
944-
err = scriptPath.WriteFile([]byte(
950+
postScriptPath = dir.Join("post_install.sh")
951+
preScriptPath = dir.Join("pre_uninstall.sh")
952+
err = postScriptPath.WriteFile([]byte(
953+
`#!/bin/sh
954+
echo "sent in stdout"
955+
echo "sent in stderr" 1>&2`))
956+
require.NoError(t, err)
957+
err = preScriptPath.WriteFile([]byte(
945958
`#!/bin/sh
946959
echo "sent in stdout"
947960
echo "sent in stderr" 1>&2`))
948961
}
949962
require.NoError(t, err)
950-
err = os.Chmod(scriptPath.String(), 0777)
963+
err = os.Chmod(postScriptPath.String(), 0777)
964+
require.NoError(t, err)
965+
err = os.Chmod(preScriptPath.String(), 0777)
951966
require.NoError(t, err)
952967
stdout, stderr, err := pme.RunPreOrPostScript(dir, "post_install")
953968
require.NoError(t, err)
954969

955970
// `HasPrefix` because windows seem to add a trailing space at the end
956971
require.Equal(t, "sent in stdout", strings.Trim(string(stdout), "\n\r "))
957972
require.Equal(t, "sent in stderr", strings.Trim(string(stderr), "\n\r "))
973+
974+
stdout, stderr, err = pme.RunPreOrPostScript(dir, "pre_uninstall")
975+
require.NoError(t, err)
976+
977+
// `HasPrefix` because windows seem to add a trailing space at the end
978+
require.Equal(t, "sent in stdout", strings.Trim(string(stdout), "\n\r "))
979+
require.Equal(t, "sent in stderr", strings.Trim(string(stderr), "\n\r "))
958980
}

0 commit comments

Comments
 (0)